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
11 changes: 11 additions & 0 deletions prdoc/pr_8881.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
title: '[pallet-revive] only record diff if value changed'
doc:
- audience: Runtime Dev
description: |-
Only record storage change in diff mode if the value differ from the initial one.
Previous implementation would report a diff for example when the old value was written again.

Updated tests in https://github.com/paritytech/evm-test-suite/pull/96
crates:
- name: pallet-revive
bump: patch
11 changes: 9 additions & 2 deletions substrate/frame/revive/src/evm/tracing/prestate_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,28 @@ where
fn storage_write(&mut self, key: &Key, old_value: Option<Vec<u8>>, new_value: Option<&[u8]>) {
let key = Bytes::from(key.unhashed().to_vec());

self.trace
let old_value = self
.trace
.0
.entry(self.current_addr)
.or_default()
.storage
.entry(key.clone())
.or_insert_with(|| old_value.map(Into::into));

if self.config.diff_mode {
if !self.config.diff_mode {
return
}

if old_value.as_ref().map(|v| v.0.as_ref()) != new_value {
self.trace
.1
.entry(self.current_addr)
.or_default()
.storage
.insert(key, new_value.map(|v| v.to_vec().into()));
} else {
self.trace.1.entry(self.current_addr).or_default().storage.remove(&key);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is old_value the storage slot value before this write or before the transaction?

In the former case we should not remove it if there was a write before in this transaction that changed the value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old_value is the value that will go in the pre of the diff trace, that 's the value before the transaction.
We only set it the first time by using .or_insert_with(|| old_value.map(Into::into)); map API

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Then all good!

}
}

Expand Down