Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests-evm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
repository: paritytech/evm-test-suite
ref: 372e9b48d375a63297d6e553a70a89c4e9dfa14e
ref: 4dc2658b3c944d65e4624fad87e7532c9253448e
path: evm-test-suite

- uses: denoland/setup-deno@v2
Expand Down
9 changes: 9 additions & 0 deletions prdoc/pr_10303.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: pallet-revive fix prestate diff tracing
doc:
- audience: Runtime Dev
description: 'Fix prestate diff-tracing, add missing storage diff for created contracts

'
crates:
- name: pallet-revive
bump: patch
49 changes: 23 additions & 26 deletions substrate/frame/revive/src/evm/tracing/prestate_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ where
}
}

/// Get the appropriate trace entry (pre or post) based on whether
/// the address was created.
/// Returns early if the address is created and diff_mode is false.
macro_rules! get_entry {
($self:expr, $addr:expr) => {
if $self.created_addrs.contains(&$addr) {
if !$self.config.diff_mode {
return
}
$self.trace.1.entry($addr)
} else {
$self.trace.0.entry($addr)
}
};
}

impl<T: Config> PrestateTracer<T>
where
T::Nonce: Into<u32>,
Expand Down Expand Up @@ -174,13 +190,9 @@ where
}

/// Record a read
fn read_account_prestate(&mut self, addr: H160) {
if self.created_addrs.contains(&addr) {
return
}

fn read_account(&mut self, addr: H160) {
let include_code = !self.config.disable_code;
self.trace.0.entry(addr).or_insert_with_key(|addr| {
get_entry!(self, addr).or_insert_with_key(|addr| {
Self::prestate_info(
addr,
Pallet::<T>::evm_balance(addr),
Expand Down Expand Up @@ -228,8 +240,8 @@ where
if self.create_code.take().is_some() {
self.created_addrs.insert(to);
}
self.read_account_prestate(from);
self.read_account_prestate(to);
self.read_account(from);
self.read_account(to);
}

fn exit_child_span_with_error(&mut self, _error: crate::DispatchError, _gas_used: Weight) {
Expand All @@ -253,15 +265,9 @@ where

fn storage_write(&mut self, key: &Key, old_value: Option<Vec<u8>>, new_value: Option<&[u8]>) {
let current_addr = self.current_addr();
if self.created_addrs.contains(&current_addr) {
return
}
let key = Bytes::from(key.unhashed().to_vec());

let old_value = self
.trace
.0
.entry(current_addr)
let old_value = get_entry!(self, current_addr)
.or_default()
.storage
.entry(key.clone())
Expand All @@ -285,26 +291,17 @@ where

fn storage_read(&mut self, key: &Key, value: Option<&[u8]>) {
let current_addr = self.current_addr();
if self.created_addrs.contains(&current_addr) {
return
}

self.trace
.0
.entry(current_addr)
get_entry!(self, current_addr)
.or_default()
.storage
.entry(key.unhashed().to_vec().into())
.or_insert_with(|| value.map(|v| v.to_vec().into()));
}

fn balance_read(&mut self, addr: &H160, value: U256) {
if self.created_addrs.contains(&addr) {
return
}

let include_code = !self.config.disable_code;
self.trace.0.entry(*addr).or_insert_with_key(|addr| {
get_entry!(self, *addr).or_insert_with_key(|addr| {
Self::prestate_info(addr, value, include_code.then(|| Self::bytecode(addr)).flatten())
});
}
Expand Down
11 changes: 9 additions & 2 deletions substrate/frame/revive/src/tests/sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,19 @@ fn prestate_diff_mode_tracing_works() {
"{{CONTRACT_ADDR}}": {
"balance": "0x0",
"nonce": 2,
"code": "{{CONTRACT_CODE}}"
"code": "{{CONTRACT_CODE}}",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "{{CHILD_ADDR_PADDED}}",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000007"
}
},
"{{CHILD_ADDR}}": {
"balance": "0x0",
"nonce": 1,
"code": "{{CHILD_CODE}}"
"code": "{{CHILD_CODE}}",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x000000000000000000000000000000000000000000000000000000000000000a"
}
}
}
}"#,
Expand Down