Skip to content

Commit 818a38e

Browse files
authored
feat: address aliasing (#137)
* feat: util functions for aliasing * feat: aliasing * fix: version * chore: 0.14
1 parent a72b2a7 commit 818a38e

File tree

13 files changed

+121
-56
lines changed

13 files changed

+121
-56
lines changed

Cargo.toml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["crates/*"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.13.0"
6+
version = "0.14.0"
77
edition = "2021"
88
rust-version = "1.85"
99
authors = ["init4"]
@@ -34,21 +34,21 @@ debug = false
3434
incremental = false
3535

3636
[workspace.dependencies]
37-
signet-bundle = { version = "0.13", path = "crates/bundle" }
38-
signet-constants = { version = "0.13", path = "crates/constants" }
39-
signet-evm = { version = "0.13", path = "crates/evm" }
40-
signet-extract = { version = "0.13", path = "crates/extract" }
41-
signet-journal = { version = "0.13", path = "crates/journal" }
42-
signet-node = { version = "0.13", path = "crates/node" }
43-
signet-sim = { version = "0.13", path = "crates/sim" }
44-
signet-types = { version = "0.13", path = "crates/types" }
45-
signet-tx-cache = { version = "0.13", path = "crates/tx-cache" }
46-
signet-zenith = { version = "0.13", path = "crates/zenith" }
37+
signet-bundle = { version = "0.14", path = "crates/bundle" }
38+
signet-constants = { version = "0.14", path = "crates/constants" }
39+
signet-evm = { version = "0.14", path = "crates/evm" }
40+
signet-extract = { version = "0.14", path = "crates/extract" }
41+
signet-journal = { version = "0.14", path = "crates/journal" }
42+
signet-node = { version = "0.14", path = "crates/node" }
43+
signet-sim = { version = "0.14", path = "crates/sim" }
44+
signet-types = { version = "0.14", path = "crates/types" }
45+
signet-tx-cache = { version = "0.14", path = "crates/tx-cache" }
46+
signet-zenith = { version = "0.14", path = "crates/zenith" }
4747

48-
signet-test-utils = { version = "0.13", path = "crates/test-utils" }
48+
signet-test-utils = { version = "0.14", path = "crates/test-utils" }
4949

5050
# trevm
51-
trevm = { version = "0.29.0", features = ["full_env_cfg"] }
51+
trevm = { version = "0.31.0", features = ["full_env_cfg"] }
5252

5353
# Alloy periphery crates
5454
alloy-core = "1.4"

crates/evm/src/driver.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use alloy::{
88
TxType,
99
},
1010
eips::eip1559::{BaseFeeParams, INITIAL_BASE_FEE as EIP1559_INITIAL_BASE_FEE},
11-
primitives::{Address, Bloom, U256},
11+
primitives::{map::HashSet, Address, Bloom, U256},
1212
};
1313
use signet_extract::{Extractable, Extracts};
1414
use signet_types::{
@@ -195,6 +195,10 @@ pub struct SignetDriver<'a, 'b, C: Extractable> {
195195
/// The block extracts.
196196
pub(crate) extracts: &'a Extracts<'b, C>,
197197

198+
/// Set of addresses that generated transact events and should be aliased
199+
/// because they contain code.
200+
pub(crate) to_alias: HashSet<Address>,
201+
198202
/// Parent rollup block.
199203
parent: SealedHeader,
200204

@@ -222,6 +226,7 @@ impl<'a, 'b, C: Extractable> SignetDriver<'a, 'b, C> {
222226
/// Create a new driver.
223227
pub fn new(
224228
extracts: &'a Extracts<'b, C>,
229+
to_alias: HashSet<Address>,
225230
to_process: VecDeque<TransactionSigned>,
226231
parent: SealedHeader,
227232
constants: SignetSystemConstants,
@@ -232,6 +237,7 @@ impl<'a, 'b, C: Extractable> SignetDriver<'a, 'b, C> {
232237
+ extracts.enter_tokens.len();
233238
Self {
234239
extracts,
240+
to_alias,
235241
parent,
236242
constants,
237243
working_context: extracts.aggregate_fills(),

crates/evm/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#[macro_use]
1616
mod macros;
1717

18-
mod aliases;
19-
pub use aliases::*;
18+
mod types;
19+
pub use types::*;
2020

2121
mod driver;
2222
pub use driver::SignetDriver;
@@ -54,25 +54,23 @@ pub fn signet_evm<Db: Database + DatabaseCommit>(
5454
.with_insp(Layered::new(NoOpInspector, OrderDetector::for_rollup(constants)))
5555
.with_precompiles(signet_precompiles())
5656
.build_trevm()
57-
.expect("db set")
5857
}
5958

6059
/// Create a new EVM with the given database and inspector.
6160
pub fn signet_evm_with_inspector<Db, I>(
6261
db: Db,
63-
inner: I,
62+
outer: I,
6463
constants: SignetSystemConstants,
6564
) -> EvmNeedsCfg<Db, I>
6665
where
6766
I: Inspector<Ctx<Db>>,
6867
Db: Database + DatabaseCommit,
6968
{
70-
let inspector = SignetLayered::new(inner, OrderDetector::for_rollup(constants));
69+
let inspector = SignetLayered::new(outer, OrderDetector::for_rollup(constants));
7170

7271
TrevmBuilder::new()
7372
.with_db(db)
7473
.with_insp(inspector)
7574
.with_precompiles(signet_precompiles())
7675
.build_trevm()
77-
.expect("db set")
7876
}

crates/evm/src/sys/driver.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,12 @@ impl<'a, 'b, C: Extractable> SignetDriver<'a, 'b, C> {
397397
count = self.extracts.transacts.len()
398398
)
399399
.entered();
400-
let transacts = self.extracts.transacts.iter().map(TransactSysTx::new);
400+
let transacts: Vec<_> = self
401+
.extracts
402+
.transacts
403+
.iter()
404+
.map(|t| TransactSysTx::new(t, self.to_alias.contains(&t.event.sender)))
405+
.collect();
401406
self.apply_metered_sys_transactions(trevm, transacts)
402407
}
403408

crates/evm/src/sys/transact.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use alloy::{
66
};
77
use core::fmt;
88
use signet_extract::ExtractedEvent;
9-
use signet_types::{primitives::TransactionSigned, MagicSig};
9+
use signet_types::{primitives::TransactionSigned, MagicSig, MagicSigInfo};
1010
use signet_zenith::Transactor;
1111
use trevm::{revm::context::TxEnv, Tx};
1212

1313
/// Shim to impl [`Tx`] for [`Transactor::Transact`].
1414
#[derive(PartialEq, Eq)]
1515
pub struct TransactSysTx {
16+
/// The transact transaction.
1617
tx: TransactionSigned,
1718

1819
/// The nonce of the transaction.
@@ -23,20 +24,23 @@ pub struct TransactSysTx {
2324
magic_sig: MagicSig,
2425
}
2526

26-
impl<'a, R> From<&ExtractedEvent<'a, R, Transactor::Transact>> for TransactSysTx {
27-
fn from(transact: &ExtractedEvent<'a, R, Transactor::Transact>) -> Self {
28-
Self::new(transact)
29-
}
30-
}
31-
3227
impl TransactSysTx {
3328
/// Instantiate a new [`TransactSysTx`].
34-
pub fn new<R>(transact: &ExtractedEvent<'_, R, Transactor::Transact>) -> Self {
35-
let magic_sig = transact.magic_sig();
36-
let tx = transact.make_transaction(0);
29+
pub fn new<R>(transact: &ExtractedEvent<'_, R, Transactor::Transact>, aliased: bool) -> Self {
30+
let magic_sig = transact.magic_sig(aliased);
31+
let tx = transact.make_transaction(0, aliased);
3732
Self { tx, nonce: None, magic_sig }
3833
}
3934

35+
/// Check if the sender was aliased (i.e. the sender is a smart contract on
36+
/// the host chain).
37+
pub fn is_aliased(&self) -> bool {
38+
match self.magic_sig.ty {
39+
MagicSigInfo::Transact { aliased, .. } => aliased,
40+
_ => unreachable!(),
41+
}
42+
}
43+
4044
/// Create a [`TransactSysLog`] from the filler.
4145
fn make_sys_log(&self) -> TransactSysLog {
4246
TransactSysLog {
@@ -71,7 +75,7 @@ impl Clone for TransactSysTx {
7175
impl Tx for TransactSysTx {
7276
fn fill_tx_env(&self, tx_env: &mut TxEnv) {
7377
self.tx.as_eip1559().unwrap().fill_tx_env(tx_env);
74-
tx_env.caller = self.magic_sig.sender();
78+
tx_env.caller = self.magic_sig.rollup_sender();
7579
}
7680
}
7781

@@ -81,9 +85,11 @@ impl SysBase for TransactSysTx {
8185
}
8286

8387
fn description(&self) -> String {
88+
let is_aliased = if self.is_aliased() { " (aliased)" } else { "" };
89+
8490
format!(
85-
"Transact from {} to {} with value {} and {} bytes of input data: `0x{}{}`",
86-
self.magic_sig.sender(),
91+
"Transact from {}{is_aliased} to {} with value {} and {} bytes of input data: `0x{}{}`",
92+
self.magic_sig.rollup_sender(),
8793
self.tx.to().expect("creates not allowed"),
8894
format_ether(self.tx.value()),
8995
self.tx.input().len(),
@@ -116,7 +122,7 @@ impl SysBase for TransactSysTx {
116122
}
117123

118124
fn evm_sender(&self) -> Address {
119-
self.magic_sig.sender()
125+
self.magic_sig.rollup_sender()
120126
}
121127
}
122128

File renamed without changes.

crates/extract/src/extracted.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,22 +224,22 @@ impl<'a, R> ExtractedEvent<'a, R, Events> {
224224
impl<R> ExtractedEvent<'_, R, Transactor::Transact> {
225225
/// Create a magic signature for the transact event, containing sender
226226
/// information.
227-
pub fn magic_sig(&self) -> MagicSig {
227+
pub fn magic_sig(&self, aliased: bool) -> MagicSig {
228228
MagicSig {
229-
ty: MagicSigInfo::Transact { sender: self.event.host_sender() },
229+
ty: MagicSigInfo::Transact { sender: self.event.host_sender(), aliased },
230230
txid: self.tx_hash(),
231231
event_idx: self.log_index,
232232
}
233233
}
234234

235235
/// Create the signature for the transact event.
236-
fn signature(&self) -> alloy::primitives::Signature {
237-
self.magic_sig().into()
236+
fn signature(&self, aliased: bool) -> alloy::primitives::Signature {
237+
self.magic_sig(aliased).into()
238238
}
239239

240240
/// Make the transaction that corresponds to this transact event,
241241
/// using the provided nonce.
242-
pub fn make_transaction(&self, nonce: u64) -> TransactionSigned {
242+
pub fn make_transaction(&self, nonce: u64, aliased: bool) -> TransactionSigned {
243243
TransactionSigned::new_unhashed(
244244
Transaction::Eip1559(TxEip1559 {
245245
chain_id: self.rollup_chain_id(),
@@ -252,7 +252,7 @@ impl<R> ExtractedEvent<'_, R, Transactor::Transact> {
252252
access_list: Default::default(),
253253
input: self.data.clone(),
254254
}),
255-
self.signature(),
255+
self.signature(aliased),
256256
)
257257
}
258258
}

crates/sim/src/env/host.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ where
122122
.with_insp(inspector)
123123
.with_precompiles(signet_precompiles())
124124
.build_trevm()
125-
.expect("db set")
126125
.fill_cfg(&self.cfg)
127126
.fill_block(&self.block)
128127
}

crates/sim/src/env/sim_env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where
135135
let reason = trevm.result().output().cloned().map(hex::encode);
136136
let halted = trevm.result().is_halt();
137137
let halt_reason = if let ExecutionResult::Halt { reason, .. } = trevm.result() {
138-
Some(*reason)
138+
Some(reason.clone())
139139
} else {
140140
None
141141
};

crates/test-utils/tests/evm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl TestEnv {
4646
let header = Header { gas_limit: 30_000_000, ..Default::default() };
4747
SignetDriver::new(
4848
extracts,
49+
Default::default(),
4950
txns.into(),
5051
SealedHeader::new(header),
5152
SignetSystemConstants::test(),
@@ -345,7 +346,7 @@ fn test_a_transact() {
345346
MintNative::new(&extracts.enter_tokens[2], USDC_RECORD.decimals()).with_nonce(3);
346347
let expected_tx_3 = expected_sys_3.produce_transaction();
347348

348-
let expected_tx_4 = extracts.transacts[0].make_transaction(0);
349+
let expected_tx_4 = extracts.transacts[0].make_transaction(0, false);
349350

350351
assert_eq!(
351352
sealed_block.senders,

0 commit comments

Comments
 (0)