Skip to content

Commit 44f8c5d

Browse files
committed
chore: remove block height arg and add test
1 parent 3a1e296 commit 44f8c5d

File tree

11 files changed

+72
-29
lines changed

11 files changed

+72
-29
lines changed

Cargo.toml

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

55
[workspace.package]
6-
version = "0.12.4"
6+
version = "0.13.0"
77
edition = "2024"
88
rust-version = "1.88"
99
authors = ["init4"]

crates/block-processor/src/alias.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,32 @@ pub trait AliasOracle {
1212
fn should_alias(&self, address: Address) -> eyre::Result<bool>;
1313
}
1414

15+
/// Default implementation of [`AliasOracle`] for any type implementing
16+
/// [`StateProvider`]. This implementation checks if the address has bytecode
17+
/// associated with it, and if so, whether that bytecode matches the pattern
18+
/// for a 7702 delegation contract. If it is a delegation contract, it is not
19+
/// aliased; otherwise, it is aliased.
1520
impl AliasOracle for Box<dyn StateProvider> {
1621
fn should_alias(&self, address: Address) -> eyre::Result<bool> {
22+
// No account at this address.
1723
let Some(acct) = self.basic_account(&address)? else { return Ok(false) };
24+
// Get the bytecode hash for this account.
1825
let bch = match acct.bytecode_hash {
1926
Some(hash) => hash,
27+
// No bytecode hash; not a contract.
2028
None => return Ok(false),
2129
};
30+
// No code at this address.
2231
if bch == KECCAK_EMPTY {
2332
return Ok(false);
2433
}
34+
// Fetch the code associated with this bytecode hash.
2535
let code = self
2636
.bytecode_by_hash(&bch)?
2737
.ok_or_eyre("code not found. This indicates a corrupted database")?;
2838

29-
// Check for 7702 delegations.
30-
if code.len() != 23 || !code.bytecode().starts_with(&[0xef, 0x01, 0x00]) {
31-
return Ok(true);
32-
}
33-
Ok(false)
39+
// If not a 7702 delegation contract, alias it.
40+
Ok(!code.is_eip7702())
3441
}
3542
}
3643

@@ -62,6 +69,13 @@ impl AliasOracleFactory for Box<dyn StateProviderFactory> {
6269
type Oracle = Box<dyn StateProvider>;
6370

6471
fn create(&self) -> eyre::Result<Self::Oracle> {
72+
// NB: This becomes a problem if anyone ever birthday attacks a
73+
// contract/EOA pair (c.f. EIP-3607). In practice this is unlikely to
74+
// happen for the foreseeable future, and if it does we can revisit
75+
// this decision.
76+
// We considered taking the host height as an argument to this method,
77+
// but this would require all nodes to be archive nodes in order to
78+
// sync, which is less than ideal
6579
self.state_by_block_number_or_tag(alloy::eips::BlockNumberOrTag::Latest).map_err(Into::into)
6680
}
6781
}

crates/node-tests/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
HostBlockSpec, NotificationSpec, NotificationWithSidecars, RuBlockSpec,
3-
aliases::{CtxProvider, Log, TestCounterInstance, TestErc20Instance, TestLogInstance},
43
convert::ToRethPrimitive,
4+
types::{CtxProvider, Log, TestCounterInstance, TestErc20Instance, TestLogInstance},
55
utils::create_test_provider_factory_with_chain_spec,
66
};
77
use alloy::{
@@ -481,6 +481,7 @@ impl<'a> NonceChecks<'a> {
481481
}
482482

483483
/// Assert that the nonce of the address has increased.
484+
#[track_caller]
484485
pub fn assert_increase_by(&mut self, amount: u64) {
485486
let old_nonce = self.update_nonce();
486487
let expected = old_nonce + amount;
@@ -496,6 +497,7 @@ impl<'a> NonceChecks<'a> {
496497
}
497498

498499
/// Assert that the nonce of the address has increased by 1.
500+
#[track_caller]
499501
pub fn assert_incremented(&mut self) {
500502
self.assert_increase_by(1);
501503
}

crates/node-tests/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#![deny(unused_must_use, rust_2018_idioms)]
1212
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1313

14-
/// Test aliases and type definitions.
15-
pub mod aliases;
16-
1714
/// Test constants.
1815
pub mod constants;
1916

@@ -28,6 +25,9 @@ pub mod convert;
2825
pub mod rpc;
2926
pub use rpc::rpc_test;
3027

28+
/// Test aliases and type definitions.
29+
pub mod types;
30+
3131
/// Utility functions and test harnesses.
3232
pub mod utils;
3333
pub use utils::run_test;

crates/node-tests/src/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{aliases::TestCounterInstance, context::SignetTestContext, utils::run_test};
1+
use crate::{context::SignetTestContext, types::TestCounterInstance, utils::run_test};
22

33
/// A test helper that sets up a Signet test context, deploys the Counter
44
/// contract, and then runs the provided async function `f` with the context and
File renamed without changes.

crates/node-tests/tests/host_events.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ use serial_test::serial;
1414
use signet_db::{DbSignetEvent, SignetEvents};
1515
use signet_node_tests::{
1616
HostBlockSpec, SignetTestContext,
17-
aliases::{Counter, TestCounterInstance},
1817
constants::{DEFAULT_REWARD_ADDRESS, TEST_CONSTANTS},
1918
run_test,
19+
types::{Counter, TestCounterInstance},
2020
utils::{adjust_usd_decimals, adjust_usd_decimals_u256},
2121
};
2222
use signet_test_utils::{chain::USDC_RECORD, contracts::counter::COUNTER_BYTECODE};
23-
use signet_types::constants::{HostPermitted, RollupPermitted};
23+
use signet_types::{
24+
constants::{HostPermitted, RollupPermitted},
25+
unalias_address,
26+
};
2427
use signet_zenith::{MINTER_ADDRESS, Passage, Transactor, mintCall};
2528

2629
alloy::sol! {
@@ -207,31 +210,44 @@ async fn test_transact() {
207210
run_test(|ctx| async move {
208211
// set up user
209212
let user = ctx.addresses[0];
213+
214+
// Getting a little cute here. We ensure that the ALIASED version is
215+
// one of the standard test addresses, so we don't have to set up any
216+
// extra accounts.
217+
let aliased = ctx.addresses[1];
218+
let host_contract = unalias_address(aliased);
219+
220+
// Indicate to the block processor that this address should be aliased
221+
ctx.set_should_alias(host_contract, true);
222+
210223
let mut user_nonce = ctx.track_nonce(user, Some("user"));
211224
let mut user_bal = ctx.track_balance(user, Some("user"));
212225

226+
let mut aliased_nonce = ctx.track_nonce(aliased, Some("aliased"));
227+
let mut aliased_bal = ctx.track_balance(aliased, Some("aliased"));
228+
213229
// Deploy a contract to interact with
214-
let deployer = ctx.addresses[1];
230+
let deployer = ctx.addresses[2];
215231

216232
// Assert that the counter is zero
217233
let contract = ctx.deploy_counter(deployer).await;
218234
let contract_addr = *contract.address();
219235
assert_eq!(contract.count().call().await.unwrap(), U256::ZERO);
220236

221237
// Transact that calls the context and increments it.
222-
let block = HostBlockSpec::new(ctx.constants()).simple_transact(
223-
user,
224-
contract_addr,
225-
Counter::incrementCall::SELECTOR,
226-
0,
227-
);
238+
let block = HostBlockSpec::new(ctx.constants())
239+
.simple_transact(user, contract_addr, Counter::incrementCall::SELECTOR, 0)
240+
.simple_transact(host_contract, contract_addr, Counter::incrementCall::SELECTOR, 0);
228241

229242
ctx.process_block(block).await.unwrap();
230243

231244
user_nonce.assert_incremented();
232245
user_bal.assert_decrease();
233246

234-
assert_eq!(contract.count().call().await.unwrap(), U256::from(1));
247+
aliased_nonce.assert_incremented();
248+
aliased_bal.assert_decrease();
249+
250+
assert_eq!(contract.count().call().await.unwrap(), U256::from(2));
235251

236252
// check the RPC response
237253
let block = ctx
@@ -258,6 +274,20 @@ async fn test_transact() {
258274
assert_eq!(transact_tx.to().unwrap(), contract_addr);
259275
assert_eq!(transact_tx.value(), U256::ZERO);
260276
assert_eq!(transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
277+
278+
let aliased_transact_tx = &txns[1];
279+
assert_eq!(aliased_transact_tx.from(), aliased);
280+
assert_eq!(aliased_transact_tx.to().unwrap(), contract_addr);
281+
assert_eq!(aliased_transact_tx.value(), U256::ZERO);
282+
assert_eq!(aliased_transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
283+
284+
let aliased_tx_hash = aliased_transact_tx.tx_hash();
285+
let aliased_transact_tx =
286+
ctx.alloy_provider.get_transaction_by_hash(aliased_tx_hash).await.unwrap().unwrap();
287+
assert_eq!(aliased_transact_tx.from(), aliased);
288+
assert_eq!(aliased_transact_tx.to().unwrap(), contract_addr);
289+
assert_eq!(aliased_transact_tx.value(), U256::ZERO);
290+
assert_eq!(aliased_transact_tx.input(), &Bytes::from(Counter::incrementCall::SELECTOR));
261291
})
262292
.await;
263293
}

crates/node-tests/tests/orders.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use alloy::{
88
};
99
use serial_test::serial;
1010
use signet_node_tests::{
11-
HostBlockSpec, RuBlockSpec, SignetTestContext,
12-
aliases::{Erc20, TestErc20Instance},
13-
run_test,
11+
HostBlockSpec, RuBlockSpec, SignetTestContext, run_test,
12+
types::{Erc20, TestErc20Instance},
1413
};
1514
use signet_types::constants::HostPermitted;
1615
use signet_zenith::RollupOrders;

crates/node-tests/tests/rpc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use reth::providers::{BlockNumReader, BlockReader, TransactionsProvider};
1717
use serial_test::serial;
1818
use signet_node_tests::{
1919
SignetTestContext,
20-
aliases::{Counter, TestCounterInstance},
2120
constants::TEST_CONSTANTS,
2221
rpc_test,
22+
types::{Counter, TestCounterInstance},
2323
};
2424
use signet_test_utils::contracts::counter::{COUNTER_BYTECODE, COUNTER_DEPLOY_CODE};
2525
use tokio::try_join;

crates/node-tests/tests/rpc_debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use reth::{
44
rpc::types::trace::geth::{CallConfig, GethDebugTracingOptions},
55
};
66
use serial_test::serial;
7-
use signet_node_tests::{aliases::Counter::incrementCall, rpc::rpc_test};
7+
use signet_node_tests::{rpc::rpc_test, types::Counter::incrementCall};
88
use signet_test_utils::specs::{HostBlockSpec, RuBlockSpec};
99

1010
#[serial]

0 commit comments

Comments
 (0)