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(execution): verify cumulative gas used before receipts root #9224

Merged
merged 1 commit into from
Jul 1, 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
20 changes: 10 additions & 10 deletions crates/ethereum/consensus/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ pub fn validate_block_post_execution(
receipts: &[Receipt],
requests: &[Request],
) -> Result<(), ConsensusError> {
// Check if gas used matches the value set in header.
let cumulative_gas_used =
receipts.last().map(|receipt| receipt.cumulative_gas_used).unwrap_or(0);
if block.gas_used != cumulative_gas_used {
return Err(ConsensusError::BlockGasUsed {
gas: GotExpected { got: cumulative_gas_used, expected: block.gas_used },
gas_spent_by_tx: gas_spent_by_transactions(receipts),
})
}

// Before Byzantium, receipts contained state root that would mean that expensive
// operation as hashing that is required for state root got calculated in every
// transaction This was replaced with is_success flag.
Expand All @@ -27,16 +37,6 @@ pub fn validate_block_post_execution(
}
}

// Check if gas used matches the value set in header.
let cumulative_gas_used =
receipts.last().map(|receipt| receipt.cumulative_gas_used).unwrap_or(0);
if block.gas_used != cumulative_gas_used {
return Err(ConsensusError::BlockGasUsed {
gas: GotExpected { got: cumulative_gas_used, expected: block.gas_used },
gas_spent_by_tx: gas_spent_by_transactions(receipts),
})
}

// Validate that the header requests root matches the calculated requests root
if chain_spec.is_prague_active_at_timestamp(block.timestamp) {
let Some(header_requests_root) = block.header.requests_root else {
Expand Down
Loading