From 92c7a18fafaea8c5ba2241e7b9766f084ef777cd Mon Sep 17 00:00:00 2001 From: ceciliaz030 Date: Fri, 2 Feb 2024 02:53:41 +0800 Subject: [PATCH 1/8] Squashed commit of the following: commit b960c3fd5813dc86643036ed9f705fb6a28a756b Merge: 983db4b 70ab8b6 Author: ceciliaz030 Date: Fri Jan 19 03:28:32 2024 +0800 Merge remote-tracking branch 'cecilia/main' into sync-taiko-v3.5 commit 983db4be8675efea76d5f1562d6e5776748a377f Author: ceciliaz030 Date: Fri Jan 19 03:21:10 2024 +0800 non exclusive op & taiko flags commit 115d5fea1f5a3adfb355ce46d8a07c5613296e89 Author: ceciliaz030 Date: Fri Jan 19 03:11:48 2024 +0800 cleanup commit 7b0065b38797d6eead2de438f1cea7847fc32c03 Merge: c306f98 9d655c4 Author: ceciliaz030 Date: Fri Jan 19 03:06:29 2024 +0800 Merge remote-tracking branch 'cecilia/main' into sync-taiko-v3.5 commit c306f988dad4ca0e613c5f7288908f254b337ac6 Author: ceciliaz030 Date: Fri Jan 19 03:02:19 2024 +0800 handler register commit 72a085ecc08c86ee2064ccf16ccdcdc173295e57 Author: ceciliaz030 Date: Thu Jan 18 16:02:07 2024 +0800 fix specs and conditional op/taiko flags, todo: taiko handlers commit 3ec69eeffef3e8e0d54120894b66621356a866e9 Merge: a983b13 9a03c7e Author: ceciliaz030 Date: Thu Jan 18 16:01:11 2024 +0800 Merge remote-tracking branch 'cecilia/serde-no-std' into sync-taiko-v3.5 commit 9a03c7ef8b58328bd1e34c484f1f021d8c0dd1e9 Merge: cf4da2f 0629883 Author: CeciliaZ030 <45245961+CeciliaZ030@users.noreply.github.com> Date: Thu Jan 18 14:44:30 2024 +0800 Merge branch 'main' into serde-no-std commit cf4da2fa8cce0c8cd65f52c62f985dfc82a8a6e7 Author: ceciliaz030 Date: Thu Jan 18 14:35:37 2024 +0800 "preserve_order" commit 6f951139e178ffb7619707b3a98c72fe79d8a7a4 Author: ceciliaz030 Date: Thu Jan 18 14:33:28 2024 +0800 delete comment #"std" commit 15c51faf740fd548acc452ce79d20ea6bf081f48 Author: ceciliaz030 Date: Thu Jan 18 13:30:33 2024 +0800 optional serde std commit a983b13ca8131e3dd3401e7b930497b769e5a4a1 Author: ceciliaz030 Date: Thu Jan 18 13:30:33 2024 +0800 optional serde std commit 546cb515982285c12be68dca386e95b7a68fa7f2 Author: ceciliaz030 Date: Thu Jan 18 12:47:50 2024 +0800 update commit f0d680646139cb7c079595c3b09141167d84e6b5 Author: Leo Alt Date: Fri Nov 24 16:32:08 2023 +0100 use serde as no-std commit 0546172927cbf8d1084a5164acd37d53495dd3f2 Merge: c7aee3a 327dc05 Author: ceciliaz030 Date: Wed Jan 17 03:46:52 2024 +0800 Merge remote-tracking branch 'john/feat/taiko' into cecilia-taiko commit c7aee3ab42e2fec17cb6bdc654a526f03cb6e3d7 Author: ceciliaz030 Date: Wed Jan 17 03:11:35 2024 +0800 init commit 327dc05411c59db6520ba3782a4d1cdab992f479 Author: john xu Date: Mon Dec 18 06:58:08 2023 +0000 Refactor handler functions in EVM implementation commit 2e961443c60eae354a078a3c82d22af6d530035d Author: john xu Date: Sat Dec 9 07:59:10 2023 +0000 Add condition to disable gas refund for anchor transactions commit 13c2272bf4ecce03529fb6545767064d1a7a2754 Author: john xu Date: Sat Dec 9 07:21:01 2023 +0000 Remove once_cell dependency commit 6c6b061ca06460012bbf53af52d113b8d9da4ec1 Author: john xu Date: Sat Dec 9 07:13:20 2023 +0000 Add taiko module and handler commit cbbfe9c9f2f3e17d4e67e979f954cd9e67b45753 Author: Leo Alt Date: Fri Nov 24 16:32:08 2023 +0100 use serde as no-std commit 0e7d7792b85a9ea1312ce1e5e8db41acf83bcf0c Author: john xu Date: Thu Oct 19 12:28:10 2023 +0000 feat: anchor check in zeth commit daf73eea96a71565dc3627359e99eb15f0dc3e29 Author: john xu Date: Tue Oct 17 13:18:20 2023 +0000 feat: support taiko protocol taiko reimburse_caller & reward_beneficiary KATLA is before CANCUN, aka does not have 4844 --features taiko more registers update pub mod handler_register Update Cargo.toml manual pick: bluealloy/revm/pull/1073 & succinct/john/v5.0.0-patched update c-kzg 1.0.0 latest bump compiled --- .github/workflows/ci.yml | 4 +- Cargo.lock | 48 +++++-- bins/revme/Cargo.toml | 9 +- crates/interpreter/Cargo.toml | 1 + crates/interpreter/src/instructions/opcode.rs | 6 + crates/precompile/Cargo.toml | 4 + crates/precompile/src/lib.rs | 2 + crates/precompile/src/secp256k1.rs | 28 +++- crates/primitives/Cargo.toml | 1 + crates/primitives/src/env.rs | 76 +++++++--- crates/primitives/src/lib.rs | 3 + crates/primitives/src/result.rs | 35 +++-- crates/primitives/src/specification.rs | 109 +++++++++++--- crates/revm/Cargo.toml | 3 +- crates/revm/src/lib.rs | 2 + crates/revm/src/taiko.rs | 3 + crates/revm/src/taiko/handler_register.rs | 135 ++++++++++++++++++ 17 files changed, 393 insertions(+), 76 deletions(-) create mode 100644 crates/revm/src/taiko.rs create mode 100644 crates/revm/src/taiko/handler_register.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cbea7ba5c4..10737408c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: rust: ["stable", "beta", "nightly"] - flags: ["--no-default-features", "", "--all-features"] + flags: ["--no-default-features", "", "--features taiko"] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master @@ -92,7 +92,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rust-docs - - run: cargo doc --workspace --all-features --no-deps --document-private-items + - run: cargo doc --workspace --features taiko --no-deps --document-private-items env: RUSTDOCFLAGS: "--cfg docsrs -D warnings" diff --git a/Cargo.lock b/Cargo.lock index 9d369b7963..2cdcabc418 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -341,9 +341,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" @@ -384,6 +384,15 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bit-set" version = "0.5.3" @@ -561,9 +570,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", ] @@ -656,7 +665,7 @@ dependencies = [ "anes", "cast", "ciborium", - "clap 4.5.3", + "clap 4.5.4", "criterion-plot", "is-terminal", "itertools", @@ -865,6 +874,7 @@ dependencies = [ "rand_core", "sec1", "subtle", + "tap", "zeroize", ] @@ -1101,6 +1111,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec", "rand_core", "subtle", ] @@ -1599,9 +1610,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" @@ -2271,9 +2282,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "reqwest" @@ -2357,6 +2368,7 @@ dependencies = [ "ripemd", "secp256k1", "sha2", + "sp1-precompiles", "substrate-bn", ] @@ -2748,9 +2760,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "indexmap", "itoa", @@ -2859,6 +2871,20 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "sp1-precompiles" +version = "0.1.0" +source = "git+https://github.com/succinctlabs/sp1.git#bd94f18389c7f13a1919f80eb0b9aaf641941c7e" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "getrandom", + "k256", + "rand", + "serde", +] + [[package]] name = "spin" version = "0.5.2" diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 7caead93b0..30a2e37844 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -17,7 +17,6 @@ microbench = "0.5" plain_hasher = "0.2" revm = { path = "../../crates/revm", version = "7.2.0", default-features = false, features = [ "ethersdb", - "std", "serde-json", "c-kzg", ] } @@ -25,10 +24,14 @@ alloy-rlp = { version = "0.3", default-features = false, features = [ "arrayvec", "derive", ] } -serde = { version = "1.0", features = ["derive", "rc"] } -serde_json = { version = "1.0", features = ["preserve_order"] } +serde = { version = "1.0", default-features = false, features = ["derive", "rc"] } +serde_json = { version = "1.0", default-features = false, features = ["alloc"]} structopt = "0.3" thiserror = "1.0" triehash = "0.8" walkdir = "2.5" k256 = { version = "0.13.3", features = ["ecdsa"] } + +[features] +default = ["std"] +std = ["serde/std", "serde_json/std", "alloy-rlp/std", "revm/std"] \ No newline at end of file diff --git a/crates/interpreter/Cargo.toml b/crates/interpreter/Cargo.toml index 945314e874..96b88e9718 100644 --- a/crates/interpreter/Cargo.toml +++ b/crates/interpreter/Cargo.toml @@ -39,6 +39,7 @@ optimism-default-handler = [ negate-optimism-default-handler = [ "revm-primitives/negate-optimism-default-handler", ] +taiko = ["revm-primitives/taiko"] dev = [ "memory_limit", diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index 687637b4bc..4f2720aa62 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -954,6 +954,12 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] { const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::ECOTONE); TABLE } + #[cfg(feature = "taiko")] + SpecId::KATLA => { + const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::KATLA); + TABLE + } + } }; } diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index 373e6850e1..c5cf230a99 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -32,12 +32,15 @@ secp256k1 = { version = "0.28.2", default-features = false, features = [ "rand", "global-context", ], optional = true } +sp1-precompiles = { git = "https://github.com/succinctlabs/sp1.git" } + [dev-dependencies] criterion = { version = "0.5" } [features] default = ["std", "c-kzg", "secp256k1", "portable"] + std = [ "revm-primitives/std", "k256/std", @@ -50,6 +53,7 @@ std = [ asm-keccak = ["revm-primitives/asm-keccak"] optimism = ["revm-primitives/optimism"] +taiko = ["revm-primitives/taiko"] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. optimism-default-handler = [ "optimism", diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index fd34bd6358..bededaac3d 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -251,6 +251,8 @@ impl PrecompileSpecId { BEDROCK | REGOLITH | CANYON => Self::BERLIN, #[cfg(feature = "optimism")] ECOTONE => Self::CANCUN, + #[cfg(feature = "taiko")] + KATLA => Self::BERLIN, // TODO(Cecilia): what is this? } } } diff --git a/crates/precompile/src/secp256k1.rs b/crates/precompile/src/secp256k1.rs index 4ad079e1e7..387766d0a7 100644 --- a/crates/precompile/src/secp256k1.rs +++ b/crates/precompile/src/secp256k1.rs @@ -6,9 +6,27 @@ pub const ECRECOVER: PrecompileWithAddress = PrecompileWithAddress( Precompile::Standard(ec_recover_run), ); -pub use self::secp256k1::ecrecover; +#[cfg(all(target_os = "zkvm", target_vendor = "succinct"))] +#[allow(clippy::module_inception)] +mod secp256k1 { + use crate::B256; + use revm_primitives::keccak256; + + pub fn ecrecover(sig: &[u8; 65], msg: &B256) -> Result { + let recovered_key = sp1_precompiles::secp256k1::ecrecover(sig, msg)?; + + let mut hash = keccak256(&recovered_key[1..]); + + // truncate to 20 bytes + hash[..12].fill(0); + Ok(hash) + } +} -#[cfg(not(feature = "secp256k1"))] +#[cfg(all( + not(all(target_os = "zkvm", target_vendor = "succinct")), + not(feature = "secp256k1") +))] #[allow(clippy::module_inception)] mod secp256k1 { use k256::ecdsa::{Error, RecoveryId, Signature, VerifyingKey}; @@ -40,7 +58,10 @@ mod secp256k1 { } } -#[cfg(feature = "secp256k1")] +#[cfg(all( + not(all(target_os = "zkvm", target_vendor = "succinct")), + feature = "secp256k1" +))] #[allow(clippy::module_inception)] mod secp256k1 { use revm_primitives::{alloy_primitives::B512, keccak256, B256}; @@ -51,6 +72,7 @@ mod secp256k1 { // Silence the unused crate dependency warning. use k256 as _; + use sp1_precompiles as _; pub fn ecrecover(sig: &B512, recid: u8, msg: &B256) -> Result { let recid = RecoveryId::from_i32(recid as i32).expect("recovery ID is valid"); diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index b50815fec2..a716baaf88 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -67,6 +67,7 @@ asm-keccak = ["alloy-primitives/asm-keccak"] portable = ["c-kzg?/portable"] optimism = [] +taiko = [] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. optimism-default-handler = ["optimism"] negate-optimism-default-handler = [] diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index bd0e52ce52..bd29547f12 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -90,6 +90,21 @@ impl Env { /// Return initial spend gas (Gas needed to execute transaction). #[inline] pub fn validate_tx(&self) -> Result<(), InvalidTransaction> { + #[cfg(feature = "optimism")] + if self.cfg.optimism { + // Do not allow for a system transaction to be processed if Regolith is enabled. + if self.tx.optimism.is_system_transaction.unwrap_or(false) + && SPEC::enabled(SpecId::REGOLITH) + { + return Err(InvalidTransaction::DepositSystemTxPostRegolith); + } + + // Do not perform any extra validation for deposit transactions, they are pre-verified on L1. + if self.tx.optimism.source_hash.is_some() { + return Ok(()); + } + } + // BASEFEE tx check if SPEC::enabled(SpecId::LONDON) { if let Some(priority_fee) = self.tx.gas_priority_fee { @@ -227,6 +242,11 @@ impl Env { .ok_or(InvalidTransaction::OverflowPaymentInTransaction)?; } + #[cfg(feature = "taiko")] + if self.tx.taiko.is_anchor { + return Ok(()); + } + // Check if account has enough balance for gas_limit*gas_price and value transfer. // Transfer will be done inside `*_inner` functions. if balance_check > account.info.balance { @@ -430,6 +450,14 @@ pub struct BlockEnv { pub blob_excess_gas_and_price: Option, } +#[cfg(feature = "taiko")] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct TaikoFields { + pub treasury: Address, + pub is_anchor: bool, +} + impl BlockEnv { /// Takes `blob_excess_gas` saves it inside env /// and calculates `blob_fee` with [`BlobExcessGasAndPrice`]. @@ -542,6 +570,10 @@ pub struct TxEnv { #[cfg_attr(feature = "serde", serde(flatten))] #[cfg(feature = "optimism")] pub optimism: OptimismFields, + + #[cfg_attr(feature = "serde", serde(flatten))] + #[cfg(feature = "taiko")] + pub taiko: TaikoFields, } impl TxEnv { @@ -560,27 +592,6 @@ impl TxEnv { } } -impl Default for TxEnv { - fn default() -> Self { - Self { - caller: Address::ZERO, - gas_limit: u64::MAX, - gas_price: U256::ZERO, - gas_priority_fee: None, - transact_to: TransactTo::Call(Address::ZERO), // will do nothing - value: U256::ZERO, - data: Bytes::new(), - chain_id: None, - nonce: None, - access_list: Vec::new(), - blob_hashes: Vec::new(), - max_fee_per_blob_gas: None, - #[cfg(feature = "optimism")] - optimism: OptimismFields::default(), - } - } -} - /// Structure holding block blob excess gas and it calculates blob fee. /// /// Incorporated as part of the Cancun upgrade via [EIP-4844]. @@ -640,6 +651,29 @@ pub struct OptimismFields { pub enveloped_tx: Option, } +impl Default for TxEnv { + fn default() -> Self { + Self { + caller: Address::ZERO, + gas_limit: u64::MAX, + gas_price: U256::ZERO, + gas_priority_fee: None, + transact_to: TransactTo::Call(Address::ZERO), // will do nothing + value: U256::ZERO, + data: Bytes::new(), + chain_id: None, + nonce: None, + access_list: Vec::new(), + blob_hashes: Vec::new(), + max_fee_per_blob_gas: None, + #[cfg(feature = "optimism")] + optimism: OptimismFields::default(), + #[cfg(feature = "taiko")] + taiko: TaikoFields::default(), + } + } +} + /// Transaction destination. #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 50e6d35d3f..5ad33f4a6b 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -6,6 +6,9 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] +#[cfg(all(feature = "taiko", feature = "optimism"))] +compile_error!("Features 'taiko' and 'optimism' cannot be enabled at the same time."); + #[cfg(not(feature = "std"))] extern crate alloc as std; diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 5a563f7ed5..67c7ae2904 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -179,11 +179,6 @@ impl From for EVMError { } } -impl From for EVMError { - fn from(value: InvalidHeader) -> Self { - Self::Header(value) - } -} /// Transaction validation error. #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -277,6 +272,10 @@ pub enum InvalidTransaction { /// case for failed deposit transactions. #[cfg(feature = "optimism")] HaltedDepositPostRegolith, + + /// Anchor check failed + #[cfg(feature = "taiko")] + InvalidAnchorTransaction, } #[cfg(feature = "std")] @@ -329,28 +328,38 @@ impl fmt::Display for InvalidTransaction { Self::BlobGasPriceGreaterThanMax => { write!(f, "blob gas price is greater than max fee per blob gas") } - Self::EmptyBlobs => write!(f, "empty blobs"), - Self::BlobCreateTransaction => write!(f, "blob create transaction"), - Self::TooManyBlobs => write!(f, "too many blobs"), - Self::BlobVersionNotSupported => write!(f, "blob version not supported"), + InvalidTransaction::EmptyBlobs => write!(f, "Empty blobs"), + InvalidTransaction::BlobCreateTransaction => write!(f, "Blob create transaction"), + InvalidTransaction::TooManyBlobs => write!(f, "Too many blobs"), + InvalidTransaction::BlobVersionNotSupported => write!(f, "Blob version not supported"), #[cfg(feature = "optimism")] - Self::DepositSystemTxPostRegolith => { + InvalidTransaction::DepositSystemTxPostRegolith => { write!( f, - "deposit system transactions post regolith hardfork are not supported" + "Deposit system transactions post regolith hardfork are not supported" ) } #[cfg(feature = "optimism")] - Self::HaltedDepositPostRegolith => { + InvalidTransaction::HaltedDepositPostRegolith => { write!( f, - "deposit transaction halted post-regolith; error will be bubbled up to main return handler" + "Deposit transaction halted post-regolith. Error will be bubbled up to main return handler." ) } + #[cfg(feature = "taiko")] + InvalidTransaction::InvalidAnchorTransaction => { + write!(f, "Invalid Anchor transaction.") + } } } } +impl From for EVMError { + fn from(invalid: InvalidHeader) -> Self { + EVMError::Header(invalid) + } +} + /// Errors related to misconfiguration of a [`crate::env::BlockEnv`]. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 6d75e25c44..94dbb44472 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -5,7 +5,7 @@ pub use SpecId::*; /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(not(feature = "optimism"))] +#[cfg(all(not(feature = "optimism"), not(feature = "taiko")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -35,7 +35,7 @@ pub enum SpecId { /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -66,6 +66,42 @@ pub enum SpecId { LATEST = u8::MAX, } +/// Specification IDs and their activation block. +/// +/// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) +#[cfg(all(feature = "taiko", not(feature = "optimism")))] +#[repr(u8)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, enumn::N)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum SpecId { + FRONTIER = 0, + FRONTIER_THAWING = 1, + HOMESTEAD = 2, + DAO_FORK = 3, + TANGERINE = 4, + SPURIOUS_DRAGON = 5, + BYZANTIUM = 6, + CONSTANTINOPLE = 7, + PETERSBURG = 8, + ISTANBUL = 9, + MUIR_GLACIER = 10, + BERLIN = 11, + LONDON = 12, + ARROW_GLACIER = 13, + GRAY_GLACIER = 14, + MERGE = 15, + SHANGHAI = 16, + KATLA = 17, // KATLA is before CANCUN, aka does not have 4844 + CANCUN = 18, + LATEST = u8::MAX, +} + +impl Default for SpecId { + fn default() -> Self { + Self::LATEST + } +} + impl SpecId { #[inline] pub fn try_from_u8(spec_id: u8) -> Option { @@ -99,14 +135,16 @@ impl From<&str> for SpecId { "Merge" => Self::MERGE, "Shanghai" => Self::SHANGHAI, "Cancun" => Self::CANCUN, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] "Bedrock" => SpecId::BEDROCK, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] "Regolith" => SpecId::REGOLITH, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] "Canyon" => SpecId::CANYON, - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] "Ecotone" => SpecId::ECOTONE, + #[cfg(all(feature = "taiko", not(feature = "optimism")))] + "Katla" => SpecId::KATLA, _ => Self::LATEST, } } @@ -133,15 +171,17 @@ impl From for &'static str { SpecId::MERGE => "Merge", SpecId::SHANGHAI => "Shanghai", SpecId::CANCUN => "Cancun", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] SpecId::BEDROCK => "Bedrock", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] SpecId::REGOLITH => "Regolith", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] SpecId::CANYON => "Canyon", - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] SpecId::ECOTONE => "Ecotone", SpecId::LATEST => "Latest", + #[cfg(all(feature = "taiko", not(feature = "optimism")))] + SpecId::KATLA => "Katla", } } } @@ -190,15 +230,19 @@ spec!(CANCUN, CancunSpec); spec!(LATEST, LatestSpec); // Optimism Hardforks -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] spec!(BEDROCK, BedrockSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] spec!(REGOLITH, RegolithSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] spec!(CANYON, CanyonSpec); -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] spec!(ECOTONE, EcotoneSpec); +// Taiko Hardforks +#[cfg(all(feature = "taiko", not(feature = "optimism")))] +spec!(KATLA, KatlaSpec); + #[macro_export] macro_rules! spec_to_generic { ($spec_id:expr, $e:expr) => {{ @@ -258,26 +302,31 @@ macro_rules! spec_to_generic { use $crate::LatestSpec as SPEC; $e } - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] $crate::SpecId::BEDROCK => { use $crate::BedrockSpec as SPEC; $e } - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] $crate::SpecId::REGOLITH => { use $crate::RegolithSpec as SPEC; $e } - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] $crate::SpecId::CANYON => { use $crate::CanyonSpec as SPEC; $e } - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] $crate::SpecId::ECOTONE => { use $crate::EcotoneSpec as SPEC; $e } + #[cfg(all(feature = "taiko", not(feature = "optimism")))] + $crate::SpecId::KATLA => { + use $crate::KatlaSpec as SPEC; + $e + } } }}; } @@ -306,19 +355,19 @@ mod tests { spec_to_generic!(ARROW_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); spec_to_generic!(GRAY_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); spec_to_generic!(MERGE, assert_eq!(SPEC::SPEC_ID, MERGE)); - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] spec_to_generic!(BEDROCK, assert_eq!(SPEC::SPEC_ID, BEDROCK)); - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] spec_to_generic!(REGOLITH, assert_eq!(SPEC::SPEC_ID, REGOLITH)); spec_to_generic!(SHANGHAI, assert_eq!(SPEC::SPEC_ID, SHANGHAI)); - #[cfg(feature = "optimism")] + #[cfg(all(feature = "optimism", not(feature = "taiko")))] spec_to_generic!(CANYON, assert_eq!(SPEC::SPEC_ID, CANYON)); spec_to_generic!(CANCUN, assert_eq!(SPEC::SPEC_ID, CANCUN)); spec_to_generic!(LATEST, assert_eq!(SPEC::SPEC_ID, LATEST)); } } -#[cfg(feature = "optimism")] +#[cfg(all(feature = "optimism", not(feature = "taiko")))] #[cfg(test)] mod optimism_tests { use super::*; @@ -409,3 +458,19 @@ mod optimism_tests { assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::ECOTONE)); } } + +#[cfg(all(feature = "taiko", not(feature = "optimism")))] +#[cfg(test)] +mod taiko_tests { + use super::*; + + // TODO(Cecilia): update this range of bits + #[test] + fn test_katla_post_merge_hardforks() { + assert!(SpecId::enabled(SpecId::KATLA, SpecId::MERGE)); + assert!(SpecId::enabled(SpecId::KATLA, SpecId::SHANGHAI)); + assert!(!SpecId::enabled(SpecId::KATLA, SpecId::CANCUN)); + assert!(!SpecId::enabled(SpecId::KATLA, SpecId::LATEST)); + assert!(SpecId::enabled(SpecId::KATLA, SpecId::KATLA)); + } +} diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 5eca3309dd..8c1e4ebeaa 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -47,7 +47,7 @@ criterion = "0.5" indicatif = "0.17" [features] -default = ["std", "c-kzg", "secp256k1", "portable"] +default = ["std", "c-kzg", "secp256k1", "portable", "taiko"] std = [ "serde?/std", "serde_json?/std", @@ -64,6 +64,7 @@ portable = ["revm-precompile/portable", "revm-interpreter/portable"] test-utils = [] optimism = ["revm-interpreter/optimism", "revm-precompile/optimism"] +taiko = ["revm-interpreter/taiko", "revm-precompile/taiko"] # Optimism default handler enabled Optimism handler register by default in EvmBuilder. optimism-default-handler = [ "optimism", diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index cf9b275a66..58b50b969b 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -25,6 +25,8 @@ mod inspector; mod journaled_state; #[cfg(feature = "optimism")] pub mod optimism; +#[cfg(feature = "taiko")] +pub mod taiko; // Export items. diff --git a/crates/revm/src/taiko.rs b/crates/revm/src/taiko.rs new file mode 100644 index 0000000000..af549299e3 --- /dev/null +++ b/crates/revm/src/taiko.rs @@ -0,0 +1,3 @@ +//! Taiko-specific constants, types, and helpers. + +pub mod handler_register; diff --git a/crates/revm/src/taiko/handler_register.rs b/crates/revm/src/taiko/handler_register.rs new file mode 100644 index 0000000000..a806bc7e4f --- /dev/null +++ b/crates/revm/src/taiko/handler_register.rs @@ -0,0 +1,135 @@ +//! Handler related to Taiko chain + +use crate::{ + handler::{mainnet::deduct_caller_inner, register::EvmHandler}, + interpreter::Gas, + primitives::{db::Database, spec_to_generic, EVMError, Spec, SpecId, TransactTo, U256}, + Context, +}; +extern crate alloc; +use alloc::sync::Arc; +use SpecId::{CANCUN, LONDON}; + +pub fn taiko_handle_register(handler: &mut EvmHandler<'_, EXT, DB>) { + spec_to_generic!(handler.cfg.spec_id, { + handler.pre_execution.deduct_caller = Arc::new(deduct_caller::); + handler.post_execution.reimburse_caller = Arc::new(reimburse_caller::); + handler.post_execution.reward_beneficiary = Arc::new(reward_beneficiary::); + // Done with flags to avoid repetitive code + // handler.validation.tx_against_state = Arc::new(mainnet::validate_tx_against_state::); + }); +} + +#[inline] +pub fn reimburse_caller( + context: &mut Context, + gas: &Gas, +) -> Result<(), EVMError> { + if context.evm.env.tx.taiko.is_anchor { + return Ok(()); + } + let caller = context.evm.env.tx.caller; + let effective_gas_price = context.evm.env.effective_gas_price(); + + // return balance of not spend gas. + let (caller_account, _) = context + .evm + .inner + .journaled_state + .load_account(caller, &mut context.evm.inner.db)?; + + caller_account.info.balance = caller_account + .info + .balance + .saturating_add(effective_gas_price * U256::from(gas.remaining() + gas.refunded() as u64)); + + Ok(()) +} + +/// Reward beneficiary with gas fee. +#[inline] +pub fn reward_beneficiary( + context: &mut Context, + gas: &Gas, +) -> Result<(), EVMError> { + if context.evm.env.tx.taiko.is_anchor { + return Ok(()); + } + let beneficiary = context.evm.env.block.coinbase; + let effective_gas_price = context.evm.env.effective_gas_price(); + + // transfer fee to coinbase/beneficiary. + // EIP-1559 discard basefee for coinbase transfer. Basefee amount of gas is discarded. + let coinbase_gas_price = if SPEC::enabled(LONDON) { + effective_gas_price.saturating_sub(context.evm.env.block.basefee) + } else { + effective_gas_price + }; + + let (coinbase_account, _) = context + .evm + .inner + .journaled_state + .load_account(beneficiary, &mut context.evm.inner.db)?; + coinbase_account.mark_touch(); + coinbase_account.info.balance = coinbase_account + .info + .balance + .saturating_add(coinbase_gas_price * U256::from(gas.spent() - gas.refunded() as u64)); + + let treasury = context.evm.env.tx.taiko.treasury; + let basefee = context.evm.env.block.basefee; + + let (treasury_account, _) = context + .evm + .inner + .journaled_state + .load_account(treasury, &mut context.evm.inner.db)?; + treasury_account.mark_touch(); + treasury_account.info.balance = treasury_account + .info + .balance + .saturating_add(basefee * U256::from(gas.spent() - gas.refunded() as u64)); + Ok(()) +} + +/// Deduct max balance from caller +#[inline] +pub fn deduct_caller( + context: &mut Context, +) -> Result<(), EVMError> { + // load caller's account. + let (caller_account, _) = context + .evm + .inner + .journaled_state + .load_account(context.evm.inner.env.tx.caller, &mut context.evm.inner.db)?; + + let env = &context.evm.inner.env; + + // Subtract gas costs from the caller's account. + // We need to saturate the gas cost to prevent underflow in case that `disable_balance_check` is enabled. + let mut gas_cost = U256::from(env.tx.gas_limit).saturating_mul(env.effective_gas_price()); + + // EIP-4844 + if SPEC::enabled(CANCUN) { + let data_fee = env.calc_data_fee().expect("already checked"); + gas_cost = gas_cost.saturating_add(data_fee); + } + + if !context.evm.inner.env.tx.taiko.is_anchor { + // set new caller account balance. + caller_account.info.balance = caller_account.info.balance.saturating_sub(gas_cost); + } + + // bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`. + if matches!(env.tx.transact_to, TransactTo::Call(_)) { + // Nonce is already checked + caller_account.info.nonce = caller_account.info.nonce.saturating_add(1); + } + + // touch account so we know it is changed. + caller_account.mark_touch(); + + Ok(()) +} From 3b2817ce9cb27c886229494c094825b04f54dad9 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Wed, 27 Mar 2024 21:47:39 +0000 Subject: [PATCH 2/8] optimism -> taiko & keep default-handler --- crates/interpreter/Cargo.toml | 15 +- crates/interpreter/src/instruction_result.rs | 2 - crates/interpreter/src/instructions/opcode.rs | 20 -- crates/precompile/Cargo.toml | 13 +- crates/precompile/src/lib.rs | 4 - crates/primitives/Cargo.toml | 7 +- crates/primitives/src/env.rs | 54 ----- crates/primitives/src/env/handler_cfg.rs | 60 +++--- crates/primitives/src/lib.rs | 2 - crates/primitives/src/result.rs | 50 ----- crates/primitives/src/specification.rs | 192 +----------------- crates/revm/Cargo.toml | 19 +- crates/revm/src/builder.rs | 28 +-- crates/revm/src/context/evm_context.rs | 4 +- crates/revm/src/context/inner_evm_context.rs | 12 +- crates/revm/src/handler.rs | 34 ++-- crates/revm/src/lib.rs | 10 +- crates/revm/src/taiko.rs | 4 + crates/revm/src/taiko/l1block.rs | 31 +++ 19 files changed, 143 insertions(+), 418 deletions(-) create mode 100644 crates/revm/src/taiko/l1block.rs diff --git a/crates/interpreter/Cargo.toml b/crates/interpreter/Cargo.toml index 96b88e9718..2216bca5f9 100644 --- a/crates/interpreter/Cargo.toml +++ b/crates/interpreter/Cargo.toml @@ -30,16 +30,15 @@ arbitrary = ["std", "revm-primitives/arbitrary"] asm-keccak = ["revm-primitives/asm-keccak"] portable = ["revm-primitives/portable"] -optimism = ["revm-primitives/optimism"] -# Optimism default handler enabled Optimism handler register by default in EvmBuilder. -optimism-default-handler = [ - "optimism", - "revm-primitives/optimism-default-handler", +taiko = ["revm-primitives/taiko"] +# taiko default handler enabled taiko handler register by default in EvmBuilder. +taiko-default-handler = [ + "taiko", + "revm-primitives/taiko-default-handler", ] -negate-optimism-default-handler = [ - "revm-primitives/negate-optimism-default-handler", +negate-taiko-default-handler = [ + "revm-primitives/negate-taiko-default-handler", ] -taiko = ["revm-primitives/taiko"] dev = [ "memory_limit", diff --git a/crates/interpreter/src/instruction_result.rs b/crates/interpreter/src/instruction_result.rs index 13e250ee3d..c82f556bbb 100644 --- a/crates/interpreter/src/instruction_result.rs +++ b/crates/interpreter/src/instruction_result.rs @@ -87,8 +87,6 @@ impl From for InstructionResult { HaltReason::CallNotAllowedInsideStatic => Self::CallNotAllowedInsideStatic, HaltReason::OutOfFunds => Self::OutOfFunds, HaltReason::CallTooDeep => Self::CallTooDeep, - #[cfg(feature = "optimism")] - HaltReason::FailedDeposit => Self::FatalExternalError, } } } diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index 4f2720aa62..b26bcc0166 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -934,26 +934,6 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] { TABLE } )* - #[cfg(feature = "optimism")] - SpecId::BEDROCK => { - const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::BEDROCK); - TABLE - } - #[cfg(feature = "optimism")] - SpecId::REGOLITH => { - const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::REGOLITH); - TABLE - } - #[cfg(feature = "optimism")] - SpecId::CANYON => { - const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::CANYON); - TABLE - } - #[cfg(feature = "optimism")] - SpecId::ECOTONE => { - const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::ECOTONE); - TABLE - } #[cfg(feature = "taiko")] SpecId::KATLA => { const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::KATLA); diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index c5cf230a99..c8b826804d 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -52,15 +52,14 @@ std = [ ] asm-keccak = ["revm-primitives/asm-keccak"] -optimism = ["revm-primitives/optimism"] taiko = ["revm-primitives/taiko"] -# Optimism default handler enabled Optimism handler register by default in EvmBuilder. -optimism-default-handler = [ - "optimism", - "revm-primitives/optimism-default-handler", +# taiko default handler enabled taiko handler register by default in EvmBuilder. +taiko-default-handler = [ + "taiko", + "revm-primitives/taiko-default-handler", ] -negate-optimism-default-handler = [ - "revm-primitives/negate-optimism-default-handler", +negate-taiko-default-handler = [ + "revm-primitives/negate-taiko-default-handler", ] # These libraries may not work on all no_std platforms as they depend on C. diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index bededaac3d..1510688ca0 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -247,10 +247,6 @@ impl PrecompileSpecId { BERLIN | LONDON | ARROW_GLACIER | GRAY_GLACIER | MERGE | SHANGHAI => Self::BERLIN, CANCUN => Self::CANCUN, LATEST => Self::LATEST, - #[cfg(feature = "optimism")] - BEDROCK | REGOLITH | CANYON => Self::BERLIN, - #[cfg(feature = "optimism")] - ECOTONE => Self::CANCUN, #[cfg(feature = "taiko")] KATLA => Self::BERLIN, // TODO(Cecilia): what is this? } diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index a716baaf88..3dce838782 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -66,11 +66,10 @@ arbitrary = ["std", "alloy-primitives/arbitrary", "bitflags/arbitrary"] asm-keccak = ["alloy-primitives/asm-keccak"] portable = ["c-kzg?/portable"] -optimism = [] taiko = [] -# Optimism default handler enabled Optimism handler register by default in EvmBuilder. -optimism-default-handler = ["optimism"] -negate-optimism-default-handler = [] +# taiko default handler enabled taiko handler register by default in EvmBuilder. +taiko-default-handler = ["taiko"] +negate-taiko-default-handler = [] dev = [ "memory_limit", diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index bd29547f12..045152afc9 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -90,20 +90,6 @@ impl Env { /// Return initial spend gas (Gas needed to execute transaction). #[inline] pub fn validate_tx(&self) -> Result<(), InvalidTransaction> { - #[cfg(feature = "optimism")] - if self.cfg.optimism { - // Do not allow for a system transaction to be processed if Regolith is enabled. - if self.tx.optimism.is_system_transaction.unwrap_or(false) - && SPEC::enabled(SpecId::REGOLITH) - { - return Err(InvalidTransaction::DepositSystemTxPostRegolith); - } - - // Do not perform any extra validation for deposit transactions, they are pre-verified on L1. - if self.tx.optimism.source_hash.is_some() { - return Ok(()); - } - } // BASEFEE tx check if SPEC::enabled(SpecId::LONDON) { @@ -567,10 +553,6 @@ pub struct TxEnv { /// [EIP-4844]: https://eips.ethereum.org/EIPS/eip-4844 pub max_fee_per_blob_gas: Option, - #[cfg_attr(feature = "serde", serde(flatten))] - #[cfg(feature = "optimism")] - pub optimism: OptimismFields, - #[cfg_attr(feature = "serde", serde(flatten))] #[cfg(feature = "taiko")] pub taiko: TaikoFields, @@ -617,40 +599,6 @@ impl BlobExcessGasAndPrice { } } -/// Additional [TxEnv] fields for optimism. -#[cfg(feature = "optimism")] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct OptimismFields { - /// The source hash is used to make sure that deposit transactions do - /// not have identical hashes. - /// - /// L1 originated deposit transaction source hashes are computed using - /// the hash of the l1 block hash and the l1 log index. - /// L1 attributes deposit source hashes are computed with the l1 block - /// hash and the sequence number = l2 block number - l2 epoch start - /// block number. - /// - /// These two deposit transaction sources specify a domain in the outer - /// hash so there are no collisions. - pub source_hash: Option, - /// The amount to increase the balance of the `from` account as part of - /// a deposit transaction. This is unconditional and is applied to the - /// `from` account even if the deposit transaction fails since - /// the deposit is pre-paid on L1. - pub mint: Option, - /// Whether or not the transaction is a system transaction. - pub is_system_transaction: Option, - /// An enveloped EIP-2718 typed transaction. This is used - /// to compute the L1 tx cost using the L1 block info, as - /// opposed to requiring downstream apps to compute the cost - /// externally. - /// This field is optional to allow the [TxEnv] to be constructed - /// for non-optimism chains when the `optimism` feature is enabled, - /// but the [CfgEnv] `optimism` field is set to false. - pub enveloped_tx: Option, -} - impl Default for TxEnv { fn default() -> Self { Self { @@ -666,8 +614,6 @@ impl Default for TxEnv { access_list: Vec::new(), blob_hashes: Vec::new(), max_fee_per_blob_gas: None, - #[cfg(feature = "optimism")] - optimism: OptimismFields::default(), #[cfg(feature = "taiko")] taiko: TaikoFields::default(), } diff --git a/crates/primitives/src/env/handler_cfg.rs b/crates/primitives/src/env/handler_cfg.rs index b2894d697b..1ba531eabc 100644 --- a/crates/primitives/src/env/handler_cfg.rs +++ b/crates/primitives/src/env/handler_cfg.rs @@ -3,15 +3,15 @@ use core::ops::{Deref, DerefMut}; use std::boxed::Box; /// Handler configuration fields. It is used to configure the handler. -/// It contains specification id and the Optimism related field if -/// optimism feature is enabled. +/// It contains specification id and the taiko related field if +/// taiko feature is enabled. #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] pub struct HandlerCfg { /// Specification identification. pub spec_id: SpecId, - /// Optimism related field, it will append the Optimism handle register to the EVM. - #[cfg(feature = "optimism")] - pub is_optimism: bool, + /// taiko related field, it will append the taiko handle register to the EVM. + #[cfg(feature = "taiko")] + pub is_taiko: bool, } impl Default for HandlerCfg { @@ -24,34 +24,34 @@ impl HandlerCfg { /// Creates new `HandlerCfg` instance. pub fn new(spec_id: SpecId) -> Self { cfg_if::cfg_if! { - if #[cfg(all(feature = "optimism-default-handler", - not(feature = "negate-optimism-default-handler")))] { - let is_optimism = true; - } else if #[cfg(feature = "optimism")] { - let is_optimism = false; + if #[cfg(all(feature = "taiko-default-handler", + not(feature = "negate-taiko-default-handler")))] { + let is_taiko = true; + } else if #[cfg(feature = "taiko")] { + let is_taiko = false; } } Self { spec_id, - #[cfg(feature = "optimism")] - is_optimism, + #[cfg(feature = "taiko")] + is_taiko, } } - /// Creates new `HandlerCfg` instance with the optimism feature. - #[cfg(feature = "optimism")] - pub fn new_with_optimism(spec_id: SpecId, is_optimism: bool) -> Self { + /// Creates new `HandlerCfg` instance with the taiko feature. + #[cfg(feature = "taiko")] + pub fn new_with_taiko(spec_id: SpecId, is_taiko: bool) -> Self { Self { spec_id, - is_optimism, + is_taiko, } } - /// Returns `true` if the optimism feature is enabled and flag is set to `true`. - pub fn is_optimism(&self) -> bool { + /// Returns `true` if the taiko feature is enabled and flag is set to `true`. + pub fn is_taiko(&self) -> bool { cfg_if::cfg_if! { - if #[cfg(feature = "optimism")] { - self.is_optimism + if #[cfg(feature = "taiko")] { + self.is_taiko } else { false } @@ -79,15 +79,15 @@ impl CfgEnvWithHandlerCfg { /// Returns new `CfgEnvWithHandlerCfg` instance with the chain spec id. /// - /// is_optimism will be set to default value depending on `optimism-default-handler` feature. + /// is_taiko will be set to default value depending on `taiko-default-handler` feature. pub fn new_with_spec_id(cfg_env: CfgEnv, spec_id: SpecId) -> Self { Self::new(cfg_env, HandlerCfg::new(spec_id)) } - /// Enables the optimism feature. - #[cfg(feature = "optimism")] - pub fn enable_optimism(&mut self) { - self.handler_cfg.is_optimism = true; + /// Enables the taiko feature. + #[cfg(feature = "taiko")] + pub fn enable_taiko(&mut self) { + self.handler_cfg.is_taiko = true; } } @@ -122,7 +122,7 @@ impl EnvWithHandlerCfg { /// Returns new `EnvWithHandlerCfg` instance with the chain spec id. /// - /// is_optimism will be set to default value depending on `optimism-default-handler` feature. + /// is_taiko will be set to default value depending on `taiko-default-handler` feature. pub fn new_with_spec_id(env: Box, spec_id: SpecId) -> Self { Self::new(env, HandlerCfg::new(spec_id)) } @@ -137,10 +137,10 @@ impl EnvWithHandlerCfg { self.handler_cfg.spec_id } - /// Enables the optimism handle register. - #[cfg(feature = "optimism")] - pub fn enable_optimism(&mut self) { - self.handler_cfg.is_optimism = true; + /// Enables the taiko handle register. + #[cfg(feature = "taiko")] + pub fn enable_taiko(&mut self) { + self.handler_cfg.is_taiko = true; } } diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 5ad33f4a6b..8b0e1ff6f1 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -6,8 +6,6 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(all(feature = "taiko", feature = "optimism"))] -compile_error!("Features 'taiko' and 'optimism' cannot be enabled at the same time."); #[cfg(not(feature = "std"))] extern crate alloc as std; diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 67c7ae2904..730961cfed 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -240,38 +240,6 @@ pub enum InvalidTransaction { TooManyBlobs, /// Blob transaction contains a versioned hash with an incorrect version BlobVersionNotSupported, - /// System transactions are not supported post-regolith hardfork. - /// - /// Before the Regolith hardfork, there was a special field in the `Deposit` transaction - /// type that differentiated between `system` and `user` deposit transactions. This field - /// was deprecated in the Regolith hardfork, and this error is thrown if a `Deposit` transaction - /// is found with this field set to `true` after the hardfork activation. - /// - /// In addition, this error is internal, and bubbles up into a [HaltReason::FailedDeposit] error - /// in the `revm` handler for the consumer to easily handle. This is due to a state transition - /// rule on OP Stack chains where, if for any reason a deposit transaction fails, the transaction - /// must still be included in the block, the sender nonce is bumped, the `mint` value persists, and - /// special gas accounting rules are applied. Normally on L1, [EVMError::Transaction] errors - /// are cause for non-inclusion, so a special [HaltReason] variant was introduced to handle this - /// case for failed deposit transactions. - #[cfg(feature = "optimism")] - DepositSystemTxPostRegolith, - /// Deposit transaction haults bubble up to the global main return handler, wiping state and - /// only increasing the nonce + persisting the mint value. - /// - /// This is a catch-all error for any deposit transaction that is results in a [HaltReason] error - /// post-regolith hardfork. This allows for a consumer to easily handle special cases where - /// a deposit transaction fails during validation, but must still be included in the block. - /// - /// In addition, this error is internal, and bubbles up into a [HaltReason::FailedDeposit] error - /// in the `revm` handler for the consumer to easily handle. This is due to a state transition - /// rule on OP Stack chains where, if for any reason a deposit transaction fails, the transaction - /// must still be included in the block, the sender nonce is bumped, the `mint` value persists, and - /// special gas accounting rules are applied. Normally on L1, [EVMError::Transaction] errors - /// are cause for non-inclusion, so a special [HaltReason] variant was introduced to handle this - /// case for failed deposit transactions. - #[cfg(feature = "optimism")] - HaltedDepositPostRegolith, /// Anchor check failed #[cfg(feature = "taiko")] @@ -332,20 +300,6 @@ impl fmt::Display for InvalidTransaction { InvalidTransaction::BlobCreateTransaction => write!(f, "Blob create transaction"), InvalidTransaction::TooManyBlobs => write!(f, "Too many blobs"), InvalidTransaction::BlobVersionNotSupported => write!(f, "Blob version not supported"), - #[cfg(feature = "optimism")] - InvalidTransaction::DepositSystemTxPostRegolith => { - write!( - f, - "Deposit system transactions post regolith hardfork are not supported" - ) - } - #[cfg(feature = "optimism")] - InvalidTransaction::HaltedDepositPostRegolith => { - write!( - f, - "Deposit transaction halted post-regolith. Error will be bubbled up to main return handler." - ) - } #[cfg(feature = "taiko")] InvalidTransaction::InvalidAnchorTransaction => { write!(f, "Invalid Anchor transaction.") @@ -420,10 +374,6 @@ pub enum HaltReason { CallNotAllowedInsideStatic, OutOfFunds, CallTooDeep, - - /* Optimism errors */ - #[cfg(feature = "optimism")] - FailedDeposit, } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 94dbb44472..61b71c2a7d 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -5,7 +5,7 @@ pub use SpecId::*; /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(all(not(feature = "optimism"), not(feature = "taiko")))] +#[cfg(not(feature = "taiko"))] #[repr(u8)] #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -35,41 +35,7 @@ pub enum SpecId { /// Specification IDs and their activation block. /// /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -#[repr(u8)] -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, enumn::N)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum SpecId { - FRONTIER = 0, - FRONTIER_THAWING = 1, - HOMESTEAD = 2, - DAO_FORK = 3, - TANGERINE = 4, - SPURIOUS_DRAGON = 5, - BYZANTIUM = 6, - CONSTANTINOPLE = 7, - PETERSBURG = 8, - ISTANBUL = 9, - MUIR_GLACIER = 10, - BERLIN = 11, - LONDON = 12, - ARROW_GLACIER = 13, - GRAY_GLACIER = 14, - MERGE = 15, - BEDROCK = 16, - REGOLITH = 17, - SHANGHAI = 18, - CANYON = 19, - CANCUN = 20, - ECOTONE = 21, - #[default] - LATEST = u8::MAX, -} - -/// Specification IDs and their activation block. -/// -/// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) -#[cfg(all(feature = "taiko", not(feature = "optimism")))] +#[cfg(feature = "taiko")] #[repr(u8)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -135,15 +101,7 @@ impl From<&str> for SpecId { "Merge" => Self::MERGE, "Shanghai" => Self::SHANGHAI, "Cancun" => Self::CANCUN, - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - "Bedrock" => SpecId::BEDROCK, - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - "Regolith" => SpecId::REGOLITH, - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - "Canyon" => SpecId::CANYON, - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - "Ecotone" => SpecId::ECOTONE, - #[cfg(all(feature = "taiko", not(feature = "optimism")))] + #[cfg(feature = "taiko")] "Katla" => SpecId::KATLA, _ => Self::LATEST, } @@ -171,16 +129,8 @@ impl From for &'static str { SpecId::MERGE => "Merge", SpecId::SHANGHAI => "Shanghai", SpecId::CANCUN => "Cancun", - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - SpecId::BEDROCK => "Bedrock", - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - SpecId::REGOLITH => "Regolith", - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - SpecId::CANYON => "Canyon", - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - SpecId::ECOTONE => "Ecotone", SpecId::LATEST => "Latest", - #[cfg(all(feature = "taiko", not(feature = "optimism")))] + #[cfg(feature = "taiko")] SpecId::KATLA => "Katla", } } @@ -229,18 +179,9 @@ spec!(CANCUN, CancunSpec); spec!(LATEST, LatestSpec); -// Optimism Hardforks -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -spec!(BEDROCK, BedrockSpec); -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -spec!(REGOLITH, RegolithSpec); -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -spec!(CANYON, CanyonSpec); -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -spec!(ECOTONE, EcotoneSpec); // Taiko Hardforks -#[cfg(all(feature = "taiko", not(feature = "optimism")))] +#[cfg(feature = "taiko")] spec!(KATLA, KatlaSpec); #[macro_export] @@ -302,27 +243,7 @@ macro_rules! spec_to_generic { use $crate::LatestSpec as SPEC; $e } - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - $crate::SpecId::BEDROCK => { - use $crate::BedrockSpec as SPEC; - $e - } - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - $crate::SpecId::REGOLITH => { - use $crate::RegolithSpec as SPEC; - $e - } - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - $crate::SpecId::CANYON => { - use $crate::CanyonSpec as SPEC; - $e - } - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - $crate::SpecId::ECOTONE => { - use $crate::EcotoneSpec as SPEC; - $e - } - #[cfg(all(feature = "taiko", not(feature = "optimism")))] + #[cfg(feature = "taiko")] $crate::SpecId::KATLA => { use $crate::KatlaSpec as SPEC; $e @@ -355,111 +276,16 @@ mod tests { spec_to_generic!(ARROW_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); spec_to_generic!(GRAY_GLACIER, assert_eq!(SPEC::SPEC_ID, LONDON)); spec_to_generic!(MERGE, assert_eq!(SPEC::SPEC_ID, MERGE)); - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - spec_to_generic!(BEDROCK, assert_eq!(SPEC::SPEC_ID, BEDROCK)); - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - spec_to_generic!(REGOLITH, assert_eq!(SPEC::SPEC_ID, REGOLITH)); spec_to_generic!(SHANGHAI, assert_eq!(SPEC::SPEC_ID, SHANGHAI)); - #[cfg(all(feature = "optimism", not(feature = "taiko")))] - spec_to_generic!(CANYON, assert_eq!(SPEC::SPEC_ID, CANYON)); spec_to_generic!(CANCUN, assert_eq!(SPEC::SPEC_ID, CANCUN)); spec_to_generic!(LATEST, assert_eq!(SPEC::SPEC_ID, LATEST)); - } -} - -#[cfg(all(feature = "optimism", not(feature = "taiko")))] -#[cfg(test)] -mod optimism_tests { - use super::*; - - #[test] - fn test_bedrock_post_merge_hardforks() { - assert!(BedrockSpec::enabled(SpecId::MERGE)); - assert!(!BedrockSpec::enabled(SpecId::SHANGHAI)); - assert!(!BedrockSpec::enabled(SpecId::CANCUN)); - assert!(!BedrockSpec::enabled(SpecId::LATEST)); - assert!(BedrockSpec::enabled(SpecId::BEDROCK)); - assert!(!BedrockSpec::enabled(SpecId::REGOLITH)); - } + #[cfg(feature = "taiko")] + spec_to_generic!(KATLA, assert_eq!(SPEC::SPEC_ID, KATLA)); - #[test] - fn test_regolith_post_merge_hardforks() { - assert!(RegolithSpec::enabled(SpecId::MERGE)); - assert!(!RegolithSpec::enabled(SpecId::SHANGHAI)); - assert!(!RegolithSpec::enabled(SpecId::CANCUN)); - assert!(!RegolithSpec::enabled(SpecId::LATEST)); - assert!(RegolithSpec::enabled(SpecId::BEDROCK)); - assert!(RegolithSpec::enabled(SpecId::REGOLITH)); - } - - #[test] - fn test_bedrock_post_merge_hardforks_spec_id() { - assert!(SpecId::enabled(SpecId::BEDROCK, SpecId::MERGE)); - assert!(!SpecId::enabled(SpecId::BEDROCK, SpecId::SHANGHAI)); - assert!(!SpecId::enabled(SpecId::BEDROCK, SpecId::CANCUN)); - assert!(!SpecId::enabled(SpecId::BEDROCK, SpecId::LATEST)); - assert!(SpecId::enabled(SpecId::BEDROCK, SpecId::BEDROCK)); - assert!(!SpecId::enabled(SpecId::BEDROCK, SpecId::REGOLITH)); - } - - #[test] - fn test_regolith_post_merge_hardforks_spec_id() { - assert!(SpecId::enabled(SpecId::REGOLITH, SpecId::MERGE)); - assert!(!SpecId::enabled(SpecId::REGOLITH, SpecId::SHANGHAI)); - assert!(!SpecId::enabled(SpecId::REGOLITH, SpecId::CANCUN)); - assert!(!SpecId::enabled(SpecId::REGOLITH, SpecId::LATEST)); - assert!(SpecId::enabled(SpecId::REGOLITH, SpecId::BEDROCK)); - assert!(SpecId::enabled(SpecId::REGOLITH, SpecId::REGOLITH)); - } - - #[test] - fn test_canyon_post_merge_hardforks() { - assert!(CanyonSpec::enabled(SpecId::MERGE)); - assert!(CanyonSpec::enabled(SpecId::SHANGHAI)); - assert!(!CanyonSpec::enabled(SpecId::CANCUN)); - assert!(!CanyonSpec::enabled(SpecId::LATEST)); - assert!(CanyonSpec::enabled(SpecId::BEDROCK)); - assert!(CanyonSpec::enabled(SpecId::REGOLITH)); - assert!(CanyonSpec::enabled(SpecId::CANYON)); - } - - #[test] - fn test_canyon_post_merge_hardforks_spec_id() { - assert!(SpecId::enabled(SpecId::CANYON, SpecId::MERGE)); - assert!(SpecId::enabled(SpecId::CANYON, SpecId::SHANGHAI)); - assert!(!SpecId::enabled(SpecId::CANYON, SpecId::CANCUN)); - assert!(!SpecId::enabled(SpecId::CANYON, SpecId::LATEST)); - assert!(SpecId::enabled(SpecId::CANYON, SpecId::BEDROCK)); - assert!(SpecId::enabled(SpecId::CANYON, SpecId::REGOLITH)); - assert!(SpecId::enabled(SpecId::CANYON, SpecId::CANYON)); - } - - #[test] - fn test_ecotone_post_merge_hardforks() { - assert!(EcotoneSpec::enabled(SpecId::MERGE)); - assert!(EcotoneSpec::enabled(SpecId::SHANGHAI)); - assert!(EcotoneSpec::enabled(SpecId::CANCUN)); - assert!(!EcotoneSpec::enabled(SpecId::LATEST)); - assert!(EcotoneSpec::enabled(SpecId::BEDROCK)); - assert!(EcotoneSpec::enabled(SpecId::REGOLITH)); - assert!(EcotoneSpec::enabled(SpecId::CANYON)); - assert!(EcotoneSpec::enabled(SpecId::ECOTONE)); - } - - #[test] - fn test_ecotone_post_merge_hardforks_spec_id() { - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::MERGE)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::SHANGHAI)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::CANCUN)); - assert!(!SpecId::enabled(SpecId::ECOTONE, SpecId::LATEST)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::BEDROCK)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::REGOLITH)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::CANYON)); - assert!(SpecId::enabled(SpecId::ECOTONE, SpecId::ECOTONE)); } } -#[cfg(all(feature = "taiko", not(feature = "optimism")))] +#[cfg(feature = "taiko")] #[cfg(test)] mod taiko_tests { use super::*; diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 8c1e4ebeaa..0e0437cab1 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -63,17 +63,16 @@ portable = ["revm-precompile/portable", "revm-interpreter/portable"] test-utils = [] -optimism = ["revm-interpreter/optimism", "revm-precompile/optimism"] taiko = ["revm-interpreter/taiko", "revm-precompile/taiko"] -# Optimism default handler enabled Optimism handler register by default in EvmBuilder. -optimism-default-handler = [ - "optimism", - "revm-precompile/optimism-default-handler", - "revm-interpreter/optimism-default-handler", +# taiko default handler enabled taiko handler register by default in EvmBuilder. +taiko-default-handler = [ + "taiko", + "revm-precompile/taiko-default-handler", + "revm-interpreter/taiko-default-handler", ] -negate-optimism-default-handler = [ - "revm-precompile/negate-optimism-default-handler", - "revm-interpreter/negate-optimism-default-handler", +negate-taiko-default-handler = [ + "revm-precompile/negate-taiko-default-handler", + "revm-interpreter/negate-taiko-default-handler", ] ethersdb = [ @@ -81,7 +80,7 @@ ethersdb = [ "tokio", "ethers-providers", "ethers-core", -] # Negate optimism default handler +] dev = [ "memory_limit", diff --git a/crates/revm/src/builder.rs b/crates/revm/src/builder.rs index 1b8d827983..4e2d1c5d12 100644 --- a/crates/revm/src/builder.rs +++ b/crates/revm/src/builder.rs @@ -31,11 +31,11 @@ pub struct HandlerStage; impl<'a> Default for EvmBuilder<'a, SetGenericStage, (), EmptyDB> { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(all(feature = "optimism-default-handler", - not(feature = "negate-optimism-default-handler")))] { + if #[cfg(all(feature = "taiko-default-handler", + not(feature = "negate-taiko-default-handler")))] { let mut handler_cfg = HandlerCfg::new(SpecId::LATEST); - // set is_optimism to true by default. - handler_cfg.is_optimism = true; + // set is_taiko to true by default. + handler_cfg.is_taiko = true; } else { let handler_cfg = HandlerCfg::new(SpecId::LATEST); @@ -155,12 +155,12 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, SetGenericStage, EXT, DB> { } } - /// Sets the Optimism handler with latest spec. + /// Sets the taiko handler with latest spec. /// - /// If `optimism-default-handler` feature is enabled this is not needed. - #[cfg(feature = "optimism")] - pub fn optimism(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { - self.handler = Handler::optimism_with_spec(self.handler.cfg.spec_id); + /// If `taiko-default-handler` feature is enabled this is not needed. + #[cfg(feature = "taiko")] + pub fn taiko(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { + self.handler = Handler::taiko_with_spec(self.handler.cfg.spec_id); EvmBuilder { context: self.context, handler: self.handler, @@ -170,8 +170,8 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, SetGenericStage, EXT, DB> { /// Sets the mainnet handler with latest spec. /// - /// Enabled only with `optimism-default-handler` feature. - #[cfg(feature = "optimism-default-handler")] + /// Enabled only with `taiko-default-handler` feature. + #[cfg(feature = "taiko-default-handler")] pub fn mainnet(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { self.handler = Handler::mainnet_with_spec(self.handler.cfg.spec_id); EvmBuilder { @@ -209,8 +209,8 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { /// Resets the [`Handler`] and sets base mainnet handler. /// - /// Enabled only with `optimism-default-handler` feature. - #[cfg(feature = "optimism-default-handler")] + /// Enabled only with `taiko-default-handler` feature. + #[cfg(feature = "taiko-default-handler")] pub fn reset_handler_with_mainnet(mut self) -> EvmBuilder<'a, HandlerStage, EXT, DB> { self.handler = Handler::mainnet_with_spec(self.handler.cfg.spec_id); EvmBuilder { @@ -268,7 +268,7 @@ impl<'a, EXT, DB: Database> EvmBuilder<'a, HandlerStage, EXT, DB> { impl<'a, BuilderStage, EXT, DB: Database> EvmBuilder<'a, BuilderStage, EXT, DB> { /// Creates the default handler. /// - /// This is useful for adding optimism handle register. + /// This is useful for adding taiko handle register. fn handler(handler_cfg: HandlerCfg) -> Handler<'a, Evm<'a, EXT, DB>, EXT, DB> { Handler::new(handler_cfg) } diff --git a/crates/revm/src/context/evm_context.rs b/crates/revm/src/context/evm_context.rs index 5435722e7d..4c03833ea7 100644 --- a/crates/revm/src/context/evm_context.rs +++ b/crates/revm/src/context/evm_context.rs @@ -286,7 +286,7 @@ pub(crate) mod test_utils { journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::new()), db, error: Ok(()), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: None, }, precompiles: ContextPrecompiles::default(), @@ -301,7 +301,7 @@ pub(crate) mod test_utils { journaled_state: JournaledState::new(SpecId::CANCUN, HashSet::new()), db, error: Ok(()), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: None, }, precompiles: ContextPrecompiles::default(), diff --git a/crates/revm/src/context/inner_evm_context.rs b/crates/revm/src/context/inner_evm_context.rs index 98a4d5679b..400b1f181f 100644 --- a/crates/revm/src/context/inner_evm_context.rs +++ b/crates/revm/src/context/inner_evm_context.rs @@ -29,8 +29,8 @@ pub struct InnerEvmContext { /// Error that happened during execution. pub error: Result<(), EVMError>, /// Used as temporary value holder to store L1 block info. - #[cfg(feature = "optimism")] - pub l1_block_info: Option, + #[cfg(feature = "taiko")] + pub l1_block_info: Option, } impl Clone for InnerEvmContext @@ -43,7 +43,7 @@ where journaled_state: self.journaled_state.clone(), db: self.db.clone(), error: self.error.clone(), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: self.l1_block_info.clone(), } } @@ -56,7 +56,7 @@ impl InnerEvmContext { journaled_state: JournaledState::new(SpecId::LATEST, HashSet::new()), db, error: Ok(()), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: None, } } @@ -69,7 +69,7 @@ impl InnerEvmContext { journaled_state: JournaledState::new(SpecId::LATEST, HashSet::new()), db, error: Ok(()), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: None, } } @@ -84,7 +84,7 @@ impl InnerEvmContext { journaled_state: self.journaled_state, db, error: Ok(()), - #[cfg(feature = "optimism")] + #[cfg(feature = "taiko")] l1_block_info: self.l1_block_info, } } diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index 6cd2e5b244..f6a4789fdf 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -41,12 +41,12 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { /// Created new Handler with given configuration. /// /// Internaly it calls `mainnet_with_spec` with the given spec id. - /// Or `optimism_with_spec` if the optimism feature is enabled and `cfg.is_optimism` is set. + /// Or `taiko_with_spec` if the taiko feature is enabled and `cfg.is_taiko` is set. pub fn new(cfg: HandlerCfg) -> Self { cfg_if::cfg_if! { - if #[cfg(feature = "optimism")] { - if cfg.is_optimism { - Handler::optimism_with_spec(cfg.spec_id) + if #[cfg(feature = "taiko")] { + if cfg.is_taiko { + Handler::taiko_with_spec(cfg.spec_id) } else { Handler::mainnet_with_spec(cfg.spec_id) } @@ -69,26 +69,26 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { } } - /// Returns `true` if the optimism feature is enabled and flag is set to `true`. - pub fn is_optimism(&self) -> bool { - self.cfg.is_optimism() + /// Returns `true` if the taiko feature is enabled and flag is set to `true`. + pub fn is_taiko(&self) -> bool { + self.cfg.is_taiko() } - /// Handler for optimism - #[cfg(feature = "optimism")] - pub fn optimism() -> Self { + /// Handler for taiko + #[cfg(feature = "taiko")] + pub fn taiko() -> Self { let mut handler = Self::mainnet::(); - handler.cfg.is_optimism = true; + handler.cfg.is_taiko = true; handler.append_handler_register(HandleRegisters::Plain( - crate::optimism::optimism_handle_register::, + crate::taiko::taiko_handle_register::, )); handler } - /// Optimism with spec. Similar to [`Self::mainnet_with_spec`] - #[cfg(feature = "optimism")] - pub fn optimism_with_spec(spec_id: SpecId) -> Self { - spec_to_generic!(spec_id, Self::optimism::()) + /// taiko with spec. Similar to [`Self::mainnet_with_spec`] + #[cfg(feature = "taiko")] + pub fn taiko_with_spec(spec_id: SpecId) -> Self { + spec_to_generic!(spec_id, Self::taiko::()) } /// Creates handler with variable spec id, inside it will call `mainnet::` for @@ -183,7 +183,7 @@ impl<'a, EXT, DB: Database> EvmHandler<'a, EXT, DB> { } let registers = core::mem::take(&mut self.registers); - // register for optimism is added as a register, so we need to create mainnet handler here. + // register for taiko is added as a register, so we need to create mainnet handler here. let mut handler = Handler::mainnet_with_spec(spec_id); // apply all registers to default handeler and raw mainnet instruction table. for register in registers { diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 58b50b969b..275058c5f7 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -23,8 +23,8 @@ mod frame; pub mod handler; mod inspector; mod journaled_state; -#[cfg(feature = "optimism")] -pub mod optimism; +// #[cfg(feature = "optimism")] +// pub mod optimism; #[cfg(feature = "taiko")] pub mod taiko; @@ -47,9 +47,9 @@ pub use inspector::{ inspector_handle_register, inspector_instruction, inspectors, GetInspector, Inspector, }; pub use journaled_state::{JournalCheckpoint, JournalEntry, JournaledState}; -// export Optimism types, helpers, and constants -#[cfg(feature = "optimism")] -pub use optimism::{L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT}; +// // export Optimism types, helpers, and constants +// #[cfg(feature = "optimism")] +// pub use optimism::{L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT}; // Reexport libraries diff --git a/crates/revm/src/taiko.rs b/crates/revm/src/taiko.rs index af549299e3..69f1a9b7d6 100644 --- a/crates/revm/src/taiko.rs +++ b/crates/revm/src/taiko.rs @@ -1,3 +1,7 @@ //! Taiko-specific constants, types, and helpers. pub mod handler_register; +pub mod l1block; + +pub use handler_register::*; +pub use l1block::*; \ No newline at end of file diff --git a/crates/revm/src/taiko/l1block.rs b/crates/revm/src/taiko/l1block.rs new file mode 100644 index 0000000000..0b4571e214 --- /dev/null +++ b/crates/revm/src/taiko/l1block.rs @@ -0,0 +1,31 @@ +use crate::primitives::{address, db::Database, Address, SpecId, U256}; + +const L1_DUMMY_SLOT: U256 = U256::from_limbs([1u64, 0, 0, 0]); + +/// The address of the L1Block contract. +pub const L1_BLOCK_CONTRACT: Address = address!("4200000000000000000000000000000000000015"); + +/// L1 block info +#[derive(Clone, Debug, Default)] +pub struct L1BlockInfo { + /// TODO(Cecilia): Reserve for BBR + pub l1_dummy: U256, +} + +impl L1BlockInfo { + /// Try to fetch the L1 block info from the database. + pub fn try_fetch(db: &mut DB, spec_id: SpecId) -> Result { + // Ensure the L1 Block account is loaded into the cache after Ecotone. With EIP-4788, it is no longer the case + // that the L1 block account is loaded into the cache prior to the first inquiry for the L1 block info. + if spec_id.is_enabled_in(SpecId::CANCUN) { + let _ = db.basic(L1_BLOCK_CONTRACT)?; + } + + let l1_dummy = db.storage(L1_BLOCK_CONTRACT, L1_DUMMY_SLOT)?; + + Ok(L1BlockInfo { + l1_dummy, + ..Default::default() + }) + } +} \ No newline at end of file From e8d4b681c09c89c52b7b67c1f30e0d7f31586d2f Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 28 Mar 2024 00:19:20 +0000 Subject: [PATCH 3/8] fix Defualt & fmt --- crates/precompile/src/secp256k1.rs | 2 +- crates/primitives/src/env.rs | 1 - crates/primitives/src/env/handler_cfg.rs | 5 +---- crates/primitives/src/lib.rs | 1 - crates/primitives/src/result.rs | 1 - crates/primitives/src/specification.rs | 11 ++--------- crates/revm/src/taiko.rs | 2 +- crates/revm/src/taiko/l1block.rs | 2 +- 8 files changed, 6 insertions(+), 19 deletions(-) diff --git a/crates/precompile/src/secp256k1.rs b/crates/precompile/src/secp256k1.rs index 387766d0a7..4f4e9b6b72 100644 --- a/crates/precompile/src/secp256k1.rs +++ b/crates/precompile/src/secp256k1.rs @@ -20,7 +20,7 @@ mod secp256k1 { // truncate to 20 bytes hash[..12].fill(0); Ok(hash) - } + } } #[cfg(all( diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 045152afc9..81a7504e5d 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -90,7 +90,6 @@ impl Env { /// Return initial spend gas (Gas needed to execute transaction). #[inline] pub fn validate_tx(&self) -> Result<(), InvalidTransaction> { - // BASEFEE tx check if SPEC::enabled(SpecId::LONDON) { if let Some(priority_fee) = self.tx.gas_priority_fee { diff --git a/crates/primitives/src/env/handler_cfg.rs b/crates/primitives/src/env/handler_cfg.rs index 1ba531eabc..3e15b23aec 100644 --- a/crates/primitives/src/env/handler_cfg.rs +++ b/crates/primitives/src/env/handler_cfg.rs @@ -41,10 +41,7 @@ impl HandlerCfg { /// Creates new `HandlerCfg` instance with the taiko feature. #[cfg(feature = "taiko")] pub fn new_with_taiko(spec_id: SpecId, is_taiko: bool) -> Self { - Self { - spec_id, - is_taiko, - } + Self { spec_id, is_taiko } } /// Returns `true` if the taiko feature is enabled and flag is set to `true`. diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 8b0e1ff6f1..50e6d35d3f 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -6,7 +6,6 @@ #![deny(unused_must_use, rust_2018_idioms)] #![cfg_attr(not(feature = "std"), no_std)] - #[cfg(not(feature = "std"))] extern crate alloc as std; diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 730961cfed..5b13d1b7d3 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -179,7 +179,6 @@ impl From for EVMError { } } - /// Transaction validation error. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 61b71c2a7d..b31dbbcee1 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -37,7 +37,7 @@ pub enum SpecId { /// Information was obtained from the [Ethereum Execution Specifications](https://github.com/ethereum/execution-specs) #[cfg(feature = "taiko")] #[repr(u8)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, enumn::N)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, enumn::N)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum SpecId { FRONTIER = 0, @@ -59,15 +59,10 @@ pub enum SpecId { SHANGHAI = 16, KATLA = 17, // KATLA is before CANCUN, aka does not have 4844 CANCUN = 18, + #[default] LATEST = u8::MAX, } -impl Default for SpecId { - fn default() -> Self { - Self::LATEST - } -} - impl SpecId { #[inline] pub fn try_from_u8(spec_id: u8) -> Option { @@ -179,7 +174,6 @@ spec!(CANCUN, CancunSpec); spec!(LATEST, LatestSpec); - // Taiko Hardforks #[cfg(feature = "taiko")] spec!(KATLA, KatlaSpec); @@ -281,7 +275,6 @@ mod tests { spec_to_generic!(LATEST, assert_eq!(SPEC::SPEC_ID, LATEST)); #[cfg(feature = "taiko")] spec_to_generic!(KATLA, assert_eq!(SPEC::SPEC_ID, KATLA)); - } } diff --git a/crates/revm/src/taiko.rs b/crates/revm/src/taiko.rs index 69f1a9b7d6..97e0cd3a5a 100644 --- a/crates/revm/src/taiko.rs +++ b/crates/revm/src/taiko.rs @@ -4,4 +4,4 @@ pub mod handler_register; pub mod l1block; pub use handler_register::*; -pub use l1block::*; \ No newline at end of file +pub use l1block::*; diff --git a/crates/revm/src/taiko/l1block.rs b/crates/revm/src/taiko/l1block.rs index 0b4571e214..4b062070f4 100644 --- a/crates/revm/src/taiko/l1block.rs +++ b/crates/revm/src/taiko/l1block.rs @@ -28,4 +28,4 @@ impl L1BlockInfo { ..Default::default() }) } -} \ No newline at end of file +} From 1c4ffac6f6059682e8d417825dc5e6b80c56ad6d Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 28 Mar 2024 02:48:07 +0000 Subject: [PATCH 4/8] fix --- crates/interpreter/src/instructions/opcode.rs | 1 - crates/precompile/Cargo.toml | 1 - crates/primitives/src/env.rs | 54 +++++++++---------- crates/primitives/src/result.rs | 22 ++++---- crates/primitives/src/specification.rs | 1 - crates/revm/src/lib.rs | 5 -- crates/revm/src/taiko/handler_register.rs | 52 ++++-------------- 7 files changed, 47 insertions(+), 89 deletions(-) diff --git a/crates/interpreter/src/instructions/opcode.rs b/crates/interpreter/src/instructions/opcode.rs index b26bcc0166..eafec891f7 100644 --- a/crates/interpreter/src/instructions/opcode.rs +++ b/crates/interpreter/src/instructions/opcode.rs @@ -939,7 +939,6 @@ pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] { const TABLE: &[OpInfo;256] = &make_gas_table(SpecId::KATLA); TABLE } - } }; } diff --git a/crates/precompile/Cargo.toml b/crates/precompile/Cargo.toml index c8b826804d..8b8c1ea858 100644 --- a/crates/precompile/Cargo.toml +++ b/crates/precompile/Cargo.toml @@ -40,7 +40,6 @@ criterion = { version = "0.5" } [features] default = ["std", "c-kzg", "secp256k1", "portable"] - std = [ "revm-primitives/std", "k256/std", diff --git a/crates/primitives/src/env.rs b/crates/primitives/src/env.rs index 81a7504e5d..4108a42456 100644 --- a/crates/primitives/src/env.rs +++ b/crates/primitives/src/env.rs @@ -435,14 +435,6 @@ pub struct BlockEnv { pub blob_excess_gas_and_price: Option, } -#[cfg(feature = "taiko")] -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct TaikoFields { - pub treasury: Address, - pub is_anchor: bool, -} - impl BlockEnv { /// Takes `blob_excess_gas` saves it inside env /// and calculates `blob_fee` with [`BlobExcessGasAndPrice`]. @@ -573,6 +565,27 @@ impl TxEnv { } } +impl Default for TxEnv { + fn default() -> Self { + Self { + caller: Address::ZERO, + gas_limit: u64::MAX, + gas_price: U256::ZERO, + gas_priority_fee: None, + transact_to: TransactTo::Call(Address::ZERO), // will do nothing + value: U256::ZERO, + data: Bytes::new(), + chain_id: None, + nonce: None, + access_list: Vec::new(), + blob_hashes: Vec::new(), + max_fee_per_blob_gas: None, + #[cfg(feature = "taiko")] + taiko: TaikoFields::default(), + } + } +} + /// Structure holding block blob excess gas and it calculates blob fee. /// /// Incorporated as part of the Cancun upgrade via [EIP-4844]. @@ -598,25 +611,12 @@ impl BlobExcessGasAndPrice { } } -impl Default for TxEnv { - fn default() -> Self { - Self { - caller: Address::ZERO, - gas_limit: u64::MAX, - gas_price: U256::ZERO, - gas_priority_fee: None, - transact_to: TransactTo::Call(Address::ZERO), // will do nothing - value: U256::ZERO, - data: Bytes::new(), - chain_id: None, - nonce: None, - access_list: Vec::new(), - blob_hashes: Vec::new(), - max_fee_per_blob_gas: None, - #[cfg(feature = "taiko")] - taiko: TaikoFields::default(), - } - } +#[cfg(feature = "taiko")] +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct TaikoFields { + pub treasury: Address, + pub is_anchor: bool, } /// Transaction destination. diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 5b13d1b7d3..97139b4c05 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -179,6 +179,12 @@ impl From for EVMError { } } +impl From for EVMError { + fn from(invalid: InvalidHeader) -> Self { + EVMError::Header(invalid) + } +} + /// Transaction validation error. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -295,24 +301,18 @@ impl fmt::Display for InvalidTransaction { Self::BlobGasPriceGreaterThanMax => { write!(f, "blob gas price is greater than max fee per blob gas") } - InvalidTransaction::EmptyBlobs => write!(f, "Empty blobs"), - InvalidTransaction::BlobCreateTransaction => write!(f, "Blob create transaction"), - InvalidTransaction::TooManyBlobs => write!(f, "Too many blobs"), - InvalidTransaction::BlobVersionNotSupported => write!(f, "Blob version not supported"), + Self::EmptyBlobs => write!(f, "Empty blobs"), + Self::BlobCreateTransaction => write!(f, "Blob create transaction"), + Self::TooManyBlobs => write!(f, "Too many blobs"), + Self::BlobVersionNotSupported => write!(f, "Blob version not supported"), #[cfg(feature = "taiko")] - InvalidTransaction::InvalidAnchorTransaction => { + Self::InvalidAnchorTransaction => { write!(f, "Invalid Anchor transaction.") } } } } -impl From for EVMError { - fn from(invalid: InvalidHeader) -> Self { - EVMError::Header(invalid) - } -} - /// Errors related to misconfiguration of a [`crate::env::BlockEnv`]. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index b31dbbcee1..b594d1276b 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -283,7 +283,6 @@ mod tests { mod taiko_tests { use super::*; - // TODO(Cecilia): update this range of bits #[test] fn test_katla_post_merge_hardforks() { assert!(SpecId::enabled(SpecId::KATLA, SpecId::MERGE)); diff --git a/crates/revm/src/lib.rs b/crates/revm/src/lib.rs index 275058c5f7..78eb436f29 100644 --- a/crates/revm/src/lib.rs +++ b/crates/revm/src/lib.rs @@ -23,8 +23,6 @@ mod frame; pub mod handler; mod inspector; mod journaled_state; -// #[cfg(feature = "optimism")] -// pub mod optimism; #[cfg(feature = "taiko")] pub mod taiko; @@ -47,9 +45,6 @@ pub use inspector::{ inspector_handle_register, inspector_instruction, inspectors, GetInspector, Inspector, }; pub use journaled_state::{JournalCheckpoint, JournalEntry, JournaledState}; -// // export Optimism types, helpers, and constants -// #[cfg(feature = "optimism")] -// pub use optimism::{L1BlockInfo, BASE_FEE_RECIPIENT, L1_BLOCK_CONTRACT, L1_FEE_RECIPIENT}; // Reexport libraries diff --git a/crates/revm/src/taiko/handler_register.rs b/crates/revm/src/taiko/handler_register.rs index a806bc7e4f..3d8de96c52 100644 --- a/crates/revm/src/taiko/handler_register.rs +++ b/crates/revm/src/taiko/handler_register.rs @@ -1,22 +1,23 @@ //! Handler related to Taiko chain use crate::{ - handler::{mainnet::deduct_caller_inner, register::EvmHandler}, + handler::{ + mainnet::{self}, + register::EvmHandler, + }, interpreter::Gas, primitives::{db::Database, spec_to_generic, EVMError, Spec, SpecId, TransactTo, U256}, Context, }; extern crate alloc; use alloc::sync::Arc; -use SpecId::{CANCUN, LONDON}; +use SpecId::{CANCUN}; pub fn taiko_handle_register(handler: &mut EvmHandler<'_, EXT, DB>) { spec_to_generic!(handler.cfg.spec_id, { handler.pre_execution.deduct_caller = Arc::new(deduct_caller::); handler.post_execution.reimburse_caller = Arc::new(reimburse_caller::); handler.post_execution.reward_beneficiary = Arc::new(reward_beneficiary::); - // Done with flags to avoid repetitive code - // handler.validation.tx_against_state = Arc::new(mainnet::validate_tx_against_state::); }); } @@ -25,25 +26,7 @@ pub fn reimburse_caller( context: &mut Context, gas: &Gas, ) -> Result<(), EVMError> { - if context.evm.env.tx.taiko.is_anchor { - return Ok(()); - } - let caller = context.evm.env.tx.caller; - let effective_gas_price = context.evm.env.effective_gas_price(); - - // return balance of not spend gas. - let (caller_account, _) = context - .evm - .inner - .journaled_state - .load_account(caller, &mut context.evm.inner.db)?; - - caller_account.info.balance = caller_account - .info - .balance - .saturating_add(effective_gas_price * U256::from(gas.remaining() + gas.refunded() as u64)); - - Ok(()) + mainnet::reimburse_caller::(context, gas) } /// Reward beneficiary with gas fee. @@ -55,27 +38,10 @@ pub fn reward_beneficiary( if context.evm.env.tx.taiko.is_anchor { return Ok(()); } - let beneficiary = context.evm.env.block.coinbase; - let effective_gas_price = context.evm.env.effective_gas_price(); + let _beneficiary = context.evm.env.block.coinbase; + let _effective_gas_price = context.evm.env.effective_gas_price(); - // transfer fee to coinbase/beneficiary. - // EIP-1559 discard basefee for coinbase transfer. Basefee amount of gas is discarded. - let coinbase_gas_price = if SPEC::enabled(LONDON) { - effective_gas_price.saturating_sub(context.evm.env.block.basefee) - } else { - effective_gas_price - }; - - let (coinbase_account, _) = context - .evm - .inner - .journaled_state - .load_account(beneficiary, &mut context.evm.inner.db)?; - coinbase_account.mark_touch(); - coinbase_account.info.balance = coinbase_account - .info - .balance - .saturating_add(coinbase_gas_price * U256::from(gas.spent() - gas.refunded() as u64)); + mainnet::reward_beneficiary::(context, gas)?; let treasury = context.evm.env.tx.taiko.treasury; let basefee = context.evm.env.block.basefee; From 4d02ed612b5f382da91ad6dd454260a4c2213ea7 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 28 Mar 2024 02:50:49 +0000 Subject: [PATCH 5/8] cleanup comment --- crates/precompile/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 1510688ca0..90672ac874 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -248,7 +248,7 @@ impl PrecompileSpecId { CANCUN => Self::CANCUN, LATEST => Self::LATEST, #[cfg(feature = "taiko")] - KATLA => Self::BERLIN, // TODO(Cecilia): what is this? + KATLA => Self::BERLIN, } } } From b2a2042795cad533081d702f69dd9627ee86250a Mon Sep 17 00:00:00 2001 From: CeciliaZ030 <45245961+CeciliaZ030@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:11:35 -0700 Subject: [PATCH 6/8] Update result.rs Co-authored-by: Brecht Devos --- crates/primitives/src/result.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 97139b4c05..c24b70a94b 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -301,10 +301,10 @@ impl fmt::Display for InvalidTransaction { Self::BlobGasPriceGreaterThanMax => { write!(f, "blob gas price is greater than max fee per blob gas") } - Self::EmptyBlobs => write!(f, "Empty blobs"), - Self::BlobCreateTransaction => write!(f, "Blob create transaction"), - Self::TooManyBlobs => write!(f, "Too many blobs"), - Self::BlobVersionNotSupported => write!(f, "Blob version not supported"), + Self::EmptyBlobs => write!(f, "empty blobs"), + Self::BlobCreateTransaction => write!(f, "blob create transaction"), + Self::TooManyBlobs => write!(f, "too many blobs"), + Self::BlobVersionNotSupported => write!(f, "blob version not supported"), #[cfg(feature = "taiko")] Self::InvalidAnchorTransaction => { write!(f, "Invalid Anchor transaction.") From 2ce383685ca46ba5bfc83849fc07b75417d62efa Mon Sep 17 00:00:00 2001 From: CeciliaZ030 <45245961+CeciliaZ030@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:12:11 -0700 Subject: [PATCH 7/8] Update handler_register.rs Co-authored-by: Brecht Devos --- crates/revm/src/taiko/handler_register.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/revm/src/taiko/handler_register.rs b/crates/revm/src/taiko/handler_register.rs index 3d8de96c52..bcc558b9ce 100644 --- a/crates/revm/src/taiko/handler_register.rs +++ b/crates/revm/src/taiko/handler_register.rs @@ -26,6 +26,9 @@ pub fn reimburse_caller( context: &mut Context, gas: &Gas, ) -> Result<(), EVMError> { + if context.evm.env.tx.taiko.is_anchor { + return Ok(()); + } mainnet::reimburse_caller::(context, gas) } From a7a5e7812c80bc3aeaf9b6a75b37d64dab6caa02 Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 28 Mar 2024 09:06:27 +0000 Subject: [PATCH 8/8] last change --- crates/revm/src/taiko/handler_register.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/revm/src/taiko/handler_register.rs b/crates/revm/src/taiko/handler_register.rs index bcc558b9ce..3306c50a2c 100644 --- a/crates/revm/src/taiko/handler_register.rs +++ b/crates/revm/src/taiko/handler_register.rs @@ -41,8 +41,6 @@ pub fn reward_beneficiary( if context.evm.env.tx.taiko.is_anchor { return Ok(()); } - let _beneficiary = context.evm.env.block.coinbase; - let _effective_gas_price = context.evm.env.effective_gas_price(); mainnet::reward_beneficiary::(context, gas)?;