Skip to content
Open
Show file tree
Hide file tree
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: 7 additions & 0 deletions crates/optimism/consensus/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use alloc::sync::Arc;
use alloy_primitives::B256;
use reth_consensus::ConsensusError;
use reth_primitives_traits::GotExpected;
use reth_storage_errors::provider::ProviderError;

/// Optimism consensus error.
Expand All @@ -28,6 +29,12 @@ pub enum OpConsensusError {
/// L1 [`ConsensusError`], that also occurs on L2.
#[error(transparent)]
Eth(ConsensusError),
/// DA footprint gas missing from header
#[error("DA footprint gas missing from header")]
DAFootprintGasMissing,
/// DA footprint gas mismatch
#[error("DA footprint gas mismatch: {0:?}")]
DAFootprintGasDiff(GotExpected<u64>),
}

impl From<OpConsensusError> for ConsensusError {
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ where
block: &RecoveredBlock<N::Block>,
result: &BlockExecutionResult<N::Receipt>,
) -> Result<(), ConsensusError> {
validate_block_post_execution(block.header(), &self.chain_spec, result)
Ok(validate_block_post_execution(block.header(), &self.chain_spec, result)?)
}
}

Expand Down
9 changes: 5 additions & 4 deletions crates/optimism/consensus/src/validation/jovian.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Block verification w.r.t. consensus rules new in Jovian hardfork.

use crate::OpConsensusError;
use alloy_consensus::BlockHeader;
use reth_consensus::ConsensusError;
use reth_execution_types::BlockExecutionResult;
use reth_optimism_primitives::DepositReceipt;
use reth_primitives_traits::GotExpected;
Expand All @@ -13,12 +13,13 @@ use reth_primitives_traits::GotExpected;
pub fn validate_blob_gas_used<R: DepositReceipt>(
header: impl BlockHeader,
result: &BlockExecutionResult<R>,
) -> Result<(), ConsensusError> {
) -> Result<(), OpConsensusError> {
let computed_blob_gas_used = result.blob_gas_used;
let header_blob_gas_used = header.blob_gas_used().ok_or(ConsensusError::BlobGasUsedMissing)?;
let header_blob_gas_used =
header.blob_gas_used().ok_or(OpConsensusError::DAFootprintGasMissing)?;

if computed_blob_gas_used != header_blob_gas_used {
return Err(ConsensusError::BlobGasUsedDiff(GotExpected {
return Err(OpConsensusError::DAFootprintGasDiff(GotExpected {
got: computed_blob_gas_used,
expected: header_blob_gas_used,
}));
Expand Down
12 changes: 6 additions & 6 deletions crates/optimism/consensus/src/validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub mod jovian;
use reth_execution_types::BlockExecutionResult;
pub use reth_optimism_chainspec::decode_holocene_base_fee;

use crate::proof::calculate_receipt_root_optimism;
use crate::{proof::calculate_receipt_root_optimism, OpConsensusError};
use alloc::vec::Vec;
use alloy_consensus::{BlockHeader, TxReceipt, EMPTY_OMMER_ROOT_HASH};
use alloy_eips::Encodable2718;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub fn validate_block_post_execution<R: DepositReceipt>(
header: impl BlockHeader,
chain_spec: impl OpHardforks,
result: &BlockExecutionResult<R>,
) -> Result<(), ConsensusError> {
) -> Result<(), OpConsensusError> {
// Validate that the blob gas used is present and correctly computed if Jovian is active.
if chain_spec.is_jovian_active_at_timestamp(header.timestamp()) {
jovian::validate_blob_gas_used(&header, result)?;
Expand All @@ -116,17 +116,17 @@ pub fn validate_block_post_execution<R: DepositReceipt>(
.map(|r| Bytes::from(r.with_bloom_ref().encoded_2718()))
.collect::<Vec<_>>();
tracing::debug!(%error, ?receipts, "receipts verification failed");
return Err(error)
Err(error)?
}

// 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 header.gas_used() != cumulative_gas_used {
return Err(ConsensusError::BlockGasUsed {
return Err(OpConsensusError::Eth(ConsensusError::BlockGasUsed {
gas: GotExpected { got: cumulative_gas_used, expected: header.gas_used() },
gas_spent_by_tx: gas_spent_by_transactions(receipts),
})
}))
Comment on lines +126 to +129
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here nitpick, i think this works

Err(ConsensusError::BlockGasUsed { ..etc })?

}

Ok(())
Expand Down Expand Up @@ -558,7 +558,7 @@ mod tests {
};
assert!(matches!(
validate_block_post_execution(&header, &chainspec, &result).unwrap_err(),
ConsensusError::BlobGasUsedDiff(diff)
OpConsensusError::DAFootprintGasDiff(diff)
if diff.got == BLOB_GAS_USED && diff.expected == BLOB_GAS_USED + 1
));
}
Expand Down
Loading