Skip to content

Commit

Permalink
Fixed auth-list cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mrLSD committed Jan 9, 2025
1 parent e305321 commit 3d90abd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
6 changes: 3 additions & 3 deletions evm-tests/jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,9 @@ fn test_run(
let test_tx = &test.0.transaction;
for (spec, states) in &test.0.post_states {
// TODOFEE
if name != "tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing[fork_Prague-state_test-delegated_account-not_self_sponsored]" {
continue;
}
// if name != "tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_delegation_clearing[fork_Prague-state_test-delegated_account-not_self_sponsored]" {
// continue;
// }
// Run tests for specific SPEC (Hard fork)
if let Some(s) = specific_spec.as_ref() {
if s != spec {
Expand Down
10 changes: 5 additions & 5 deletions evm-tests/jsontests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ pub mod transaction {
// Other validation step inside EVM transact logic.
for auth in test_tx.authorization_list.iter() {
// 1. Verify the chain id is either 0 or the chain’s current ID.
let mut is_valid =
auth.chain_id.0 == U256::from(0) || auth.chain_id.0 == vicinity.chain_id;
if auth.chain_id.0 > U256::from(u64::MAX) {
is_valid = false;
}
let mut is_valid = if auth.chain_id.0 > U256::from(u64::MAX) {
false
} else {
auth.chain_id.0 == U256::from(0) || auth.chain_id.0 == vicinity.chain_id
};
// 3. `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s]`

// Validate the signature, as in tests it is possible to have invalid signatures values.
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/eval/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub fn extcodehash<H: Handler>(runtime: &mut Runtime, handler: &mut H) -> Contro
}

/// NOTE: For EIP-7702 should not copy from designated address
pub fn extcodecopy<H: Handler>(runtime: &mut Runtime, handler: &mut H) -> Control<H> {
pub fn extcodecopy<H: Handler>(runtime: &mut Runtime, handler: &H) -> Control<H> {
pop_h256!(runtime, address);
pop_u256!(runtime, memory_offset, code_offset, len);

Expand Down
22 changes: 15 additions & 7 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ impl Accessed {
/// Get authority from the accessed authority list (EIP-7702).
#[must_use]
pub fn get_authority_target(&self, authority: H160) -> Option<H160> {
// TODOFEE
// println!(
// "EX get_authority_target: {:?} for {authority:?}",
// self.authority
// );
self.authority.get(&authority).copied()
}

Expand Down Expand Up @@ -989,7 +994,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
// 8. Set the code of authority to be `0xef0100 || address`. This is a delegation designation.
// * As a special case, if address is 0x0000000000000000000000000000000000000000 do not write the designation.
// Clear the account’s code.
let mut delegation_clearing = false;
if authority.address.is_zero() {
delegation_clearing = true;
state.set_code(authority.authority, Vec::new());
} else {
state.set_code(authority.authority, authority.delegation_code());
Expand All @@ -998,11 +1005,13 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
state.inc_nonce(authority.authority)?;

// Add to authority access list cache
state
.metadata_mut()
.add_authority(authority.authority, authority.address);
if !delegation_clearing {
state
.metadata_mut()
.add_authority(authority.authority, authority.address);
}
}
// Warm addresses for [Step 3].
// Warm addresses for [Step 4].
self.state
.metadata_mut()
.access_addresses(warm_authority.into_iter());
Expand Down Expand Up @@ -1167,7 +1176,6 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet>
// EIP-7702 - get delegated designation address code
// Detect loop for Delegated designation
let code = self.authority_code(code_address);
println!("--> CALL: {code_address:?} | {:?}", code);
// Warm Delegated address after access
if let Some(target_address) = self.get_authority_target(code_address) {
self.warm_target((target_address, None));
Expand Down Expand Up @@ -1488,11 +1496,11 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> Handler
}
// TODOFEE
#[cfg(feature = "print-debug")]
println!("CODE_HASH");
println!("# CODE_HASH for: {address:?}");
if self.get_authority_target(address).is_some() {
// TODOFEE
#[cfg(feature = "print-debug")]
println!("AUTH CODE_HASH");
println!("# CODE_HASH: AUTH");
H256::from(EIP7702_MAGIC_HASH)
} else {
H256::from_slice(Keccak256::digest(self.code(address)).as_slice())
Expand Down
7 changes: 6 additions & 1 deletion src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ impl<'config> MemoryStackSubstate<'config> {
#[cfg(feature = "print-debug")]
println!(" [SSTORE {address:?}] {key:?}:{value:?}");
self.storages.insert((address, key), value);
let v = self.storages.get(&(address, key));
}

pub fn reset_storage<B: Backend>(&mut self, address: H160, backend: &B) {
Expand Down Expand Up @@ -501,14 +500,20 @@ impl<'config> MemoryStackSubstate<'config> {
/// Get authority target from the current state. If it's `None` just take a look
/// recursively in the parent state.
fn get_authority_target_recursive(&self, authority: H160) -> Option<H160> {
// TODOFEE
// println!("get_authority_target_recursive");
if let Some(target) = self
.metadata
.accessed()
.as_ref()
.and_then(|accessed| accessed.get_authority_target(authority))
{
// TODOFEE
// println!("target recursive result: {:?}", target);
return Some(target);
}
// TODOFEE
// println!("get_authority_target_recursive NEXT");
self.parent
.as_ref()
.and_then(|p| p.get_authority_target_recursive(authority))
Expand Down

0 comments on commit 3d90abd

Please sign in to comment.