Skip to content

Commit

Permalink
Add comment to used state trace (#185)
Browse files Browse the repository at this point in the history
Adds comments from here #161
  • Loading branch information
dvush committed Sep 21, 2024
1 parent 20b4f93 commit 900aa72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions crates/rbuilder/src/building/evm_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub struct SlotKey {
}

#[derive(Debug, Clone, Default, PartialEq, Eq)]
/// UsedStateTrace is an execution trace of the given order
/// Limitations:
/// * `written_slot_values`, `received_amount` and `sent_amount` are not correct if transaction reverts
pub struct UsedStateTrace {
/// read slot values contains first read
pub read_slot_values: HashMap<SlotKey, B256>,
Expand Down Expand Up @@ -173,6 +176,14 @@ where
}

fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) {
// selfdestruct can be called multiple times during transaction execution
if self
.used_state_trace
.destructed_contracts
.contains(&contract)
{
return;
}
self.used_state_trace.destructed_contracts.push(contract);
if !value.is_zero() {
*self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ fn test_transfer() -> eyre::Result<()> {
.get(&sender_nonce_slot_key);
assert!(nonce_read_value.is_some());
assert!(nonce_written_value.is_some());
let nonce_read_value: U256 = nonce_read_value.unwrap().clone().into();
let nonce_written_value: U256 = nonce_written_value.unwrap().clone().into();
let nonce_read_value: U256 = (*nonce_read_value.unwrap()).into();
let nonce_written_value: U256 = (*nonce_written_value.unwrap()).into();
assert_eq!(
nonce_written_value.checked_sub(nonce_read_value),
Some(U256::from(1))
Expand Down

0 comments on commit 900aa72

Please sign in to comment.