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
17 changes: 10 additions & 7 deletions crates/block/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,13 @@ impl ConfigureEngineEvm<TaikoExecutionData> for TaikoEvmConfig {
let timestamp = payload.timestamp();
let block_number = payload.block_number();

let blob_params = self.chain_spec().blob_params_at_timestamp(timestamp);
let spec =
taiko_spec_by_timestamp_and_block_number(self.chain_spec(), timestamp, block_number);

// configure evm env based on parent block
let mut cfg_env =
CfgEnv::new().with_chain_id(self.chain_spec().chain().id()).with_spec(spec);

if let Some(blob_params) = &blob_params {
cfg_env.set_max_blobs_per_tx(blob_params.max_blobs_per_tx);
}

if self.chain_spec().is_osaka_active_at_timestamp(timestamp) {
cfg_env.tx_gas_limit_cap = Some(MAX_TX_GAS_LIMIT_OSAKA);
}
Expand Down Expand Up @@ -158,10 +153,14 @@ impl ConfigureEvm for TaikoEvmConfig {

/// Creates a new [`EvmEnv`] for the given header.
fn evm_env(&self, header: &Header) -> EvmEnvFor<Self> {
let cfg_env = CfgEnv::new()
let mut cfg_env = CfgEnv::new()
.with_chain_id(self.chain_spec().inner.chain().id())
.with_spec(taiko_revm_spec(&self.chain_spec().inner, header));

if self.chain_spec().is_osaka_active_at_timestamp(header.timestamp) {
cfg_env.tx_gas_limit_cap = Some(MAX_TX_GAS_LIMIT_OSAKA);
}

let block_env = BlockEnv {
number: U256::from(header.number()),
beneficiary: header.beneficiary(),
Expand All @@ -186,14 +185,18 @@ impl ConfigureEvm for TaikoEvmConfig {
parent: &Header,
attributes: &Self::NextBlockEnvCtx,
) -> Result<EvmEnvFor<Self>, Self::Error> {
let cfg = CfgEnv::new().with_chain_id(self.chain_spec().inner.chain().id()).with_spec(
let mut cfg = CfgEnv::new().with_chain_id(self.chain_spec().inner.chain().id()).with_spec(
taiko_spec_by_timestamp_and_block_number(
&self.chain_spec().inner,
attributes.timestamp,
parent.number + 1,
),
);

if self.chain_spec().is_osaka_active_at_timestamp(attributes.timestamp) {
cfg.tx_gas_limit_cap = Some(MAX_TX_GAS_LIMIT_OSAKA);
}

let block_env: BlockEnv = BlockEnv {
number: U256::from(parent.number + 1),
beneficiary: attributes.suggested_fee_recipient,
Expand Down
26 changes: 23 additions & 3 deletions crates/consensus/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Debug, sync::Arc};

use alloy_consensus::{
BlockHeader as AlloyBlockHeader, EMPTY_OMMER_ROOT_HASH, Transaction, TxReceipt,
proofs::calculate_receipt_root,
constants::EMPTY_WITHDRAWALS, proofs::calculate_receipt_root,
};
use alloy_eips::{Encodable2718, eip7685::Requests};
use alloy_hardforks::EthereumHardforks;
Expand All @@ -11,8 +11,8 @@ use alloy_sol_types::{SolCall, sol};
use reth_chainspec::EthChainSpec;
use reth_consensus::{Consensus, ConsensusError, FullConsensus, HeaderValidator};
use reth_consensus_common::validation::{
validate_against_parent_hash_number, validate_body_against_header, validate_header_base_fee,
validate_header_extra_data, validate_header_gas,
MAX_RLP_BLOCK_SIZE, validate_against_parent_hash_number, validate_body_against_header,
validate_header_base_fee, validate_header_extra_data, validate_header_gas,
};
use reth_evm::block::BlockExecutionResult;
use reth_primitives_traits::{
Expand Down Expand Up @@ -117,6 +117,26 @@ where
));
}

// In Taiko network, withdrawals root is always empty.
if let Some(withdrawals_root) = block.withdrawals_root() {
if withdrawals_root != EMPTY_WITHDRAWALS {
return Err(ConsensusError::BodyWithdrawalsRootDiff(
GotExpected { got: withdrawals_root, expected: EMPTY_WITHDRAWALS }.into(),
));
}
} else {
return Err(ConsensusError::WithdrawalsRootMissing);
}

if self.chain_spec.is_osaka_active_at_timestamp(block.timestamp()) &&
block.rlp_length() > MAX_RLP_BLOCK_SIZE
{
return Err(ConsensusError::BlockTooLarge {
rlp_length: block.rlp_length(),
max_rlp_length: MAX_RLP_BLOCK_SIZE,
})
}

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl TaikoSpecId {
/// Converts the [`TaikoSpecId`] into a [`SpecId`].
pub const fn into_eth_spec(self) -> SpecId {
match self {
Self::GENESIS | Self::ONTAKE | Self::PACAYA | Self::SHASTA => SpecId::PRAGUE,
Self::GENESIS | Self::ONTAKE | Self::PACAYA | Self::SHASTA => SpecId::OSAKA,
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/payload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ reth-revm = { workspace = true }
reth-provider = { workspace = true }
reth-payload-primitives = { workspace = true }
reth-basic-payload-builder = { workspace = true }
reth-consensus = { workspace = true }
reth-consensus-common = { workspace = true }
reth-engine-local = { workspace = true }
reth-ethereum = { workspace = true }
reth-ethereum-engine-primitives = { workspace = true }
Expand Down
29 changes: 29 additions & 0 deletions crates/payload/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use alloy_hardforks::EthereumHardforks;
use reth_basic_payload_builder::{
BuildArguments, BuildOutcome, MissingPayloadBehaviour, PayloadBuilder, PayloadConfig,
};
use reth_consensus::ConsensusError;
use reth_consensus_common::validation::MAX_RLP_BLOCK_SIZE;
use reth_evm::{
ConfigureEvm,
block::{BlockExecutionError, BlockValidationError},
Expand Down Expand Up @@ -152,6 +154,24 @@ where
let base_fee = attributes.base_fee_per_gas;
let mut total_fees = U256::ZERO;

// Check if Osaka hardfork is active
let chain_spec = client.chain_spec();
let is_osaka = chain_spec.is_osaka_active_at_timestamp(attributes.timestamp());

// Osaka: Pre-validate that all mandated transactions will fit within block size limit
if is_osaka {
let estimated_txs_size: usize =
attributes.transactions.iter().map(|tx| tx.inner().eip2718_encoded_length()).sum();
let estimated_total_size = estimated_txs_size + 1024; // 1KB overhead for block header

if estimated_total_size > MAX_RLP_BLOCK_SIZE {
return Err(PayloadBuilderError::other(ConsensusError::BlockTooLarge {
rlp_length: estimated_total_size,
max_rlp_length: MAX_RLP_BLOCK_SIZE,
}));
}
}

builder.apply_pre_execution_changes().map_err(|err| {
warn!(target: "payload_builder", %err, "failed to apply pre-execution changes");
PayloadBuilderError::Internal(err.into())
Expand Down Expand Up @@ -186,6 +206,15 @@ where

let sealed_block = Arc::new(block.sealed_block().clone());

// Final Osaka validation: ensure the sealed block doesn't exceed MAX_RLP_BLOCK_SIZE
// This is a safety check - the pre-execution validation should have caught this
if is_osaka && sealed_block.rlp_length() > MAX_RLP_BLOCK_SIZE {
return Err(PayloadBuilderError::other(ConsensusError::BlockTooLarge {
rlp_length: sealed_block.rlp_length(),
max_rlp_length: MAX_RLP_BLOCK_SIZE,
}));
}

let payload = TaikoBuiltPayload::new(attributes.payload_id(), sealed_block, total_fees, None);

Ok(BuildOutcome::Freeze(payload))
Expand Down
Loading