Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pevm): Post-processing lazy evaluation: assert that the evaluated nonce matches the transaction's #355

Merged
merged 3 commits into from
Sep 16, 2024
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
7 changes: 5 additions & 2 deletions src/pevm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl Pevm {
None
};

// TODO: Assert that the evaluated nonce matches the tx's.
for (tx_idx, memory_entry) in write_history.iter() {
let tx = unsafe { txs.get_unchecked(*tx_idx) };
match memory_entry {
MemoryEntry::Data(_, MemoryValue::Basic(info)) => {
// We fall back to sequential execution when reading a self-destructed account,
Expand All @@ -272,7 +272,6 @@ impl Pevm {
// TODO: Guard against overflows & underflows
// Ideally we would share these calculations with revm
// (using their utility functions).
let tx = unsafe { txs.get_unchecked(*tx_idx) };
let mut max_fee = U256::from(tx.gas_limit) * tx.gas_price + tx.value;
if let Some(blob_fee) = tx.max_fee_per_blob_gas {
max_fee +=
Expand All @@ -291,6 +290,10 @@ impl Pevm {
// TODO: Better error handling
_ => unreachable!(),
}
// Assert that evaluated nonce is correct when address is caller.
debug_assert!(
tx.caller != address || tx.nonce.map_or(true, |n| n + 1 == nonce)
);

// SAFETY: The multi-version data structure should not leak an index over block size.
let tx_result = unsafe { fully_evaluated_results.get_unchecked_mut(*tx_idx) };
Expand Down