Skip to content
Merged
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
52 changes: 48 additions & 4 deletions crates/context/src/journal/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ impl<ENTRY: JournalEntryTr> JournalInner<ENTRY> {
(slot.present_value, is_cold)
}
Entry::Vacant(vac) => {
if skip_cold_load {
// is storage cold
let is_cold = !self.warm_addresses.is_storage_warm(&address, &key);

if is_cold && skip_cold_load {
return Err(JournalLoadError::ColdLoadSkipped);
}
// if storage was cleared, we don't need to ping db.
Expand All @@ -775,9 +778,6 @@ impl<ENTRY: JournalEntryTr> JournalInner<ENTRY> {
};
vac.insert(EvmStorageSlot::new(value, self.transaction_id));

// is storage cold
let is_cold = !self.warm_addresses.is_storage_warm(&address, &key);

(value, is_cold)
}
};
Expand Down Expand Up @@ -890,3 +890,47 @@ impl<ENTRY: JournalEntryTr> JournalInner<ENTRY> {
self.logs.push(log);
}
}

#[cfg(test)]
mod tests {
use super::*;
use context_interface::journaled_state::entry::JournalEntry;
use database_interface::EmptyDB;
use primitives::{address, HashSet, U256};
use state::AccountInfo;

#[test]
fn test_sload_skip_cold_load() {
let mut journal = JournalInner::<JournalEntry>::new();
let test_address = address!("1000000000000000000000000000000000000000");
let test_key = U256::from(1);

// Insert account into state
let account_info = AccountInfo {
balance: U256::from(1000),
nonce: 1,
code_hash: KECCAK_EMPTY,
code: Some(Bytecode::default()),
};
journal
.state
.insert(test_address, Account::from(account_info));

// Add storage slot to access list (make it warm)
let mut access_list = HashMap::default();
let mut storage_keys = HashSet::default();
storage_keys.insert(test_key);
access_list.insert(test_address, storage_keys);
journal.warm_addresses.set_access_list(access_list);

// Try to sload with skip_cold_load=true - should succeed because slot is in access list
let mut db = EmptyDB::new();
let result = journal.sload(&mut db, test_address, test_key, true);

// Should succeed and return as warm
assert!(result.is_ok());
let state_load = result.unwrap();
assert!(!state_load.is_cold); // Should be warm
assert_eq!(state_load.data, U256::ZERO); // Empty slot
}
}
Loading