diff --git a/Cargo.lock b/Cargo.lock index 20f6b1563b0d..7d1cb938b5ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9853,6 +9853,7 @@ dependencies = [ "reth-rpc-types", "reth-rpc-types-compat", "taiko-reth-engine-primitives", + "tracing", ] [[package]] diff --git a/crates/chainspec/src/spec.rs b/crates/chainspec/src/spec.rs index 74d68502c74d..9f1587b18b68 100644 --- a/crates/chainspec/src/spec.rs +++ b/crates/chainspec/src/spec.rs @@ -560,6 +560,12 @@ impl ChainSpec { id >= 167000 && id <= 168000 } + /// Returns `true` if ontake fork is active at the given block number. + #[inline] + pub fn is_ontake_fork(&self, block_number: u64) -> bool { + self.is_fork_active_at_block(Hardfork::Ontake, block_number) + } + /// Returns `true` if this chain is Optimism mainnet. #[inline] pub fn is_optimism_mainnet(&self) -> bool { diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 149fbc9557b9..a5a234abfd3f 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -175,7 +175,7 @@ where transaction_gas_limit: transaction.gas_limit(), block_available_gas, } - .into()) + .into()); } EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender); @@ -542,7 +542,7 @@ mod tests { .executor(StateProviderDatabase::new(&db)) .execute( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -573,7 +573,7 @@ mod tests { // Now execute a block with the fixed header, ensure that it does not fail executor .execute_without_verification( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -639,7 +639,7 @@ mod tests { .batch_executor(StateProviderDatabase::new(&db), PruneModes::none()) .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -693,7 +693,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -738,7 +738,7 @@ mod tests { let _err = executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -765,7 +765,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -825,7 +825,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -896,7 +896,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -947,7 +947,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1005,7 +1005,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1069,7 +1069,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1124,7 +1124,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1163,7 +1163,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1205,7 +1205,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1295,7 +1295,7 @@ mod tests { let BlockExecutionOutput { receipts, requests, .. } = executor .execute( ( - &Block { + &mut Block { header, body: vec![tx], ommers: vec![], @@ -1383,7 +1383,7 @@ mod tests { // Execute the block and capture the result let exec_result = executor.execute( ( - &Block { + &mut Block { header, body: vec![tx], ommers: vec![], diff --git a/crates/taiko/evm/src/execute.rs b/crates/taiko/evm/src/execute.rs index f97c10c482a1..4a1510cb433d 100644 --- a/crates/taiko/evm/src/execute.rs +++ b/crates/taiko/evm/src/execute.rs @@ -171,7 +171,6 @@ where )?; let treasury = self.chain_spec.treasury(); - let basefee_ratio = decode_ontake_extra_data(&block.extra_data); // execute transactions let mut cumulative_gas_used = 0; @@ -234,8 +233,10 @@ where evm.tx_mut().taiko.is_anchor = is_anchor; // set the treasury address evm.tx_mut().taiko.treasury = treasury; - // set the basefee ratio - evm.tx_mut().taiko.basefee_ratio = basefee_ratio; + if self.chain_spec.is_ontake_fork(block.number) { + // set the basefee ratio + evm.tx_mut().taiko.basefee_ratio = decode_ontake_extra_data(&block.extra_data); + } // Execute transaction. let ResultAndState { result, state } = match evm.transact().map_err(move |err| { @@ -540,7 +541,7 @@ mod tests { eip4788::{BEACON_ROOTS_ADDRESS, BEACON_ROOTS_CODE, SYSTEM_ADDRESS}, eip7002::{WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, WITHDRAWAL_REQUEST_PREDEPLOY_CODE}, }; - use reth_chainspec::{ChainSpecBuilder, ForkCondition}; + use reth_chainspec::{ChainSpecBuilder, ForkCondition, MAINNET}; use reth_primitives::{ constants::{EMPTY_ROOT_HASH, ETH_TO_WEI}, keccak256, public_key_to_address, Account, Block, Transaction, TxKind, TxLegacy, B256, @@ -616,7 +617,7 @@ mod tests { .executor(StateProviderDatabase::new(&db)) .execute( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -713,7 +714,7 @@ mod tests { .batch_executor(StateProviderDatabase::new(&db), PruneModes::none()) .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -767,7 +768,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -812,7 +813,7 @@ mod tests { let _err = executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -839,7 +840,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -899,7 +900,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header: header.clone(), body: vec![], @@ -970,7 +971,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1021,7 +1022,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1079,7 +1080,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1143,7 +1144,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1198,7 +1199,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1237,7 +1238,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1279,7 +1280,7 @@ mod tests { executor .execute_and_verify_one( ( - &BlockWithSenders { + &mut BlockWithSenders { block: Block { header, body: vec![], @@ -1369,7 +1370,7 @@ mod tests { let BlockExecutionOutput { receipts, requests, .. } = executor .execute( ( - &Block { + &mut Block { header, body: vec![tx], ommers: vec![], @@ -1457,7 +1458,7 @@ mod tests { // Execute the block and capture the result let exec_result = executor.execute( ( - &Block { + &mut Block { header, body: vec![tx], ommers: vec![], diff --git a/crates/taiko/payload/builder/src/builder.rs b/crates/taiko/payload/builder/src/builder.rs index a9c74bb3a295..58e979083cfe 100644 --- a/crates/taiko/payload/builder/src/builder.rs +++ b/crates/taiko/payload/builder/src/builder.rs @@ -238,8 +238,6 @@ where alloy_rlp::Decodable::decode(&mut attributes.block_metadata.tx_list.as_ref()) .map_err(|_| PayloadBuilderError::other(TaikoPayloadBuilderError::FailedToDecodeTx))?; - let basefee_ratio = decode_ontake_extra_data(&attributes.block_metadata.extra_data); - let mut receipts = Vec::new(); for (idx, tx) in transactions.into_iter().enumerate() { let is_anchor = idx == 0; @@ -302,7 +300,10 @@ where let mut tx_env = tx_env_with_recovered(tx); tx_env.taiko.is_anchor = is_anchor; tx_env.taiko.treasury = chain_spec.treasury(); - tx_env.taiko.basefee_ratio = basefee_ratio; + if chain_spec.is_ontake_fork(block_number) { + tx_env.taiko.basefee_ratio = + decode_ontake_extra_data(&attributes.block_metadata.extra_data); + } tx_env }; let env = EnvWithHandlerCfg::new_with_cfg_env( diff --git a/crates/taiko/payload/validator/Cargo.toml b/crates/taiko/payload/validator/Cargo.toml index ffe69f8a96e8..5909a00506d2 100644 --- a/crates/taiko/payload/validator/Cargo.toml +++ b/crates/taiko/payload/validator/Cargo.toml @@ -18,3 +18,6 @@ reth-primitives = { workspace = true, features = ["taiko"] } reth-rpc-types.workspace = true reth-rpc-types-compat.workspace = true taiko-reth-engine-primitives.workspace = true + +# misc +tracing.workspace = true diff --git a/crates/taiko/payload/validator/src/lib.rs b/crates/taiko/payload/validator/src/lib.rs index f67405234336..296667a6b112 100644 --- a/crates/taiko/payload/validator/src/lib.rs +++ b/crates/taiko/payload/validator/src/lib.rs @@ -14,6 +14,7 @@ use reth_rpc_types::{engine::MaybeCancunPayloadFields, PayloadError}; use reth_rpc_types_compat::engine::payload::try_into_block; use std::sync::Arc; use taiko_reth_engine_primitives::TaikoExecutionPayload; +use tracing::debug; /// Execution payload validator.; #[derive(Clone, Debug)] @@ -111,16 +112,16 @@ impl TaikoExecutionPayloadValidator { let expected_hash = payload.block_hash(); // First parse the block - let sealed_block = if payload.payload_inner.as_v1().transactions.is_empty() && - (payload.payload_inner.withdrawals().is_none() || - payload.payload_inner.withdrawals().is_some_and(|w| w.is_empty())) + let sealed_block = if payload.payload_inner.as_v1().transactions.is_empty() + && (payload.payload_inner.withdrawals().is_none() + || payload.payload_inner.withdrawals().is_some_and(|w| w.is_empty())) { create_taiko_block(payload, cancun_fields.parent_beacon_block_root())?.seal_slow() } else { try_into_block(payload.payload_inner, cancun_fields.parent_beacon_block_root())? .seal_slow() }; - + debug!(target: "taiko_payload_validator", "Sealed block: {:?}", sealed_block); // Ensure the hash included in the payload matches the block hash if expected_hash != sealed_block.hash() { return Err(PayloadError::BlockHash { @@ -132,39 +133,39 @@ impl TaikoExecutionPayloadValidator { if self.is_cancun_active_at_timestamp(sealed_block.timestamp) { if sealed_block.header.blob_gas_used.is_none() { // cancun active but blob gas used not present - return Err(PayloadError::PostCancunBlockWithoutBlobGasUsed) + return Err(PayloadError::PostCancunBlockWithoutBlobGasUsed); } if sealed_block.header.excess_blob_gas.is_none() { // cancun active but excess blob gas not present - return Err(PayloadError::PostCancunBlockWithoutExcessBlobGas) + return Err(PayloadError::PostCancunBlockWithoutExcessBlobGas); } if cancun_fields.as_ref().is_none() { // cancun active but cancun fields not present - return Err(PayloadError::PostCancunWithoutCancunFields) + return Err(PayloadError::PostCancunWithoutCancunFields); } } else { if sealed_block.has_blob_transactions() { // cancun not active but blob transactions present - return Err(PayloadError::PreCancunBlockWithBlobTransactions) + return Err(PayloadError::PreCancunBlockWithBlobTransactions); } if sealed_block.header.blob_gas_used.is_some() { // cancun not active but blob gas used present - return Err(PayloadError::PreCancunBlockWithBlobGasUsed) + return Err(PayloadError::PreCancunBlockWithBlobGasUsed); } if sealed_block.header.excess_blob_gas.is_some() { // cancun not active but excess blob gas present - return Err(PayloadError::PreCancunBlockWithExcessBlobGas) + return Err(PayloadError::PreCancunBlockWithExcessBlobGas); } if cancun_fields.as_ref().is_some() { // cancun not active but cancun fields present - return Err(PayloadError::PreCancunWithCancunFields) + return Err(PayloadError::PreCancunWithCancunFields); } } let shanghai_active = self.is_shanghai_active_at_timestamp(sealed_block.timestamp); if !shanghai_active && sealed_block.withdrawals.is_some() { // shanghai not active but withdrawals present - return Err(PayloadError::PreShanghaiBlockWithWitdrawals) + return Err(PayloadError::PreShanghaiBlockWithWitdrawals); } // EIP-4844 checks