Skip to content

Commit 8f99f72

Browse files
authored
fix(revm): remove storage reset that clears is_cold flag (#1518)
* fix(revm): remove storage reset that clears is_cold flag * docs
1 parent 5a4ef14 commit 8f99f72

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

crates/revm/src/context/evm_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ mod tests {
358358
result.interpreter_result().result,
359359
InstructionResult::OutOfFunds
360360
);
361-
let checkpointed = vec![vec![JournalEntry::AccountLoaded { address: contract }]];
361+
let checkpointed = vec![vec![JournalEntry::AccountWarmed { address: contract }]];
362362
assert_eq!(evm_context.journaled_state.journal, checkpointed);
363363
assert_eq!(evm_context.journaled_state.depth, 0);
364364
}

crates/revm/src/journaled_state.rs

+36-32
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,6 @@ impl JournaledState {
270270
last_journal.push(JournalEntry::AccountCreated { address });
271271
account.info.code = None;
272272

273-
// Set all storages to default value. They need to be present to act as accessed slots in access list.
274-
// it shouldn't be possible for them to have different values then zero as code is not existing for this account,
275-
// but because tests can change that assumption we are doing it.
276-
let empty = EvmStorageSlot::default();
277-
account
278-
.storage
279-
.iter_mut()
280-
.for_each(|(_, slot)| *slot = empty.clone());
281-
282273
// touch account. This is important as for pre SpuriousDragon account could be
283274
// saved even empty.
284275
Self::touch_account(last_journal, &address, account);
@@ -321,7 +312,7 @@ impl JournaledState {
321312
) {
322313
for entry in journal_entries.into_iter().rev() {
323314
match entry {
324-
JournalEntry::AccountLoaded { address } => {
315+
JournalEntry::AccountWarmed { address } => {
325316
state.get_mut(&address).unwrap().mark_cold();
326317
}
327318
JournalEntry::AccountTouched { address } => {
@@ -367,19 +358,33 @@ impl JournaledState {
367358
JournalEntry::AccountCreated { address } => {
368359
let account = &mut state.get_mut(&address).unwrap();
369360
account.unmark_created();
361+
account
362+
.storage
363+
.values_mut()
364+
.for_each(|slot| slot.mark_cold());
370365
account.info.nonce = 0;
371366
}
372-
JournalEntry::StorageChange {
367+
JournalEntry::StorageWarmed { address, key } => {
368+
state
369+
.get_mut(&address)
370+
.unwrap()
371+
.storage
372+
.get_mut(&key)
373+
.unwrap()
374+
.mark_cold();
375+
}
376+
JournalEntry::StorageChanged {
373377
address,
374378
key,
375379
had_value,
376380
} => {
377-
let storage = &mut state.get_mut(&address).unwrap().storage;
378-
if let Some(had_value) = had_value {
379-
storage.get_mut(&key).unwrap().present_value = had_value;
380-
} else {
381-
storage.get_mut(&key).unwrap().mark_cold();
382-
}
381+
state
382+
.get_mut(&address)
383+
.unwrap()
384+
.storage
385+
.get_mut(&key)
386+
.unwrap()
387+
.present_value = had_value;
383388
}
384389
JournalEntry::TransientStorageChange {
385390
address,
@@ -581,7 +586,7 @@ impl JournaledState {
581586
self.journal
582587
.last_mut()
583588
.unwrap()
584-
.push(JournalEntry::AccountLoaded { address });
589+
.push(JournalEntry::AccountWarmed { address });
585590
}
586591

587592
Ok((value, is_cold))
@@ -674,11 +679,7 @@ impl JournaledState {
674679
self.journal
675680
.last_mut()
676681
.unwrap()
677-
.push(JournalEntry::StorageChange {
678-
address,
679-
key,
680-
had_value: None,
681-
});
682+
.push(JournalEntry::StorageWarmed { address, key });
682683
}
683684

684685
Ok((value, is_cold))
@@ -718,10 +719,10 @@ impl JournaledState {
718719
self.journal
719720
.last_mut()
720721
.unwrap()
721-
.push(JournalEntry::StorageChange {
722+
.push(JournalEntry::StorageChanged {
722723
address,
723724
key,
724-
had_value: Some(present),
725+
had_value: present,
725726
});
726727
// insert value into present state.
727728
slot.present_value = new;
@@ -800,7 +801,7 @@ pub enum JournalEntry {
800801
/// Used to mark account that is warm inside EVM in regards to EIP-2929 AccessList.
801802
/// Action: We will add Account to state.
802803
/// Revert: we will remove account from state.
803-
AccountLoaded { address: Address },
804+
AccountWarmed { address: Address },
804805
/// Mark account to be destroyed and journal balance to be reverted
805806
/// Action: Mark account and transfer the balance
806807
/// Revert: Unmark the account and transfer balance back
@@ -833,15 +834,18 @@ pub enum JournalEntry {
833834
/// Actions: Mark account as created
834835
/// Revert: Unmart account as created and reset nonce to zero.
835836
AccountCreated { address: Address },
836-
/// It is used to track both storage change and warm load of storage slot. For warm load in regard
837-
/// to EIP-2929 AccessList had_value will be None
838-
/// Action: Storage change or warm load
839-
/// Revert: Revert to previous value or remove slot from storage
840-
StorageChange {
837+
/// Entry used to track storage changes
838+
/// Action: Storage change
839+
/// Revert: Revert to previous value
840+
StorageChanged {
841841
address: Address,
842842
key: U256,
843-
had_value: Option<U256>, //if none, storage slot was cold loaded from db and needs to be removed
843+
had_value: U256,
844844
},
845+
/// Entry used to track storage warming introduced by EIP-2929.
846+
/// Action: Storage warmed
847+
/// Revert: Revert to cold state
848+
StorageWarmed { address: Address, key: U256 },
845849
/// It is used to track an EIP-1153 transient storage change.
846850
/// Action: Transient storage changed.
847851
/// Revert: Revert to previous value.

0 commit comments

Comments
 (0)