From 1c4ffac6f6059682e8d417825dc5e6b80c56ad6d Mon Sep 17 00:00:00 2001 From: CeciliaZ030 Date: Thu, 28 Mar 2024 02:48:07 +0000 Subject: [PATCH] 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;