Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CeciliaZ030 committed Mar 28, 2024
1 parent e8d4b68 commit 1c4ffac
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 89 deletions.
1 change: 0 additions & 1 deletion crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
};
}
Expand Down
1 change: 0 additions & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ criterion = { version = "0.5" }

[features]
default = ["std", "c-kzg", "secp256k1", "portable"]

std = [
"revm-primitives/std",
"k256/std",
Expand Down
54 changes: 27 additions & 27 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,6 @@ pub struct BlockEnv {
pub blob_excess_gas_and_price: Option<BlobExcessGasAndPrice>,
}

#[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`].
Expand Down Expand Up @@ -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].
Expand All @@ -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.
Expand Down
22 changes: 11 additions & 11 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ impl<DBError> From<InvalidTransaction> for EVMError<DBError> {
}
}

impl<DBError> From<InvalidHeader> for EVMError<DBError> {
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))]
Expand Down Expand Up @@ -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<DBError> From<InvalidHeader> for EVMError<DBError> {
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))]
Expand Down
1 change: 0 additions & 1 deletion crates/primitives/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
5 changes: 0 additions & 5 deletions crates/revm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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

Expand Down
52 changes: 9 additions & 43 deletions crates/revm/src/taiko/handler_register.rs
Original file line number Diff line number Diff line change
@@ -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<DB: Database, EXT>(handler: &mut EvmHandler<'_, EXT, DB>) {
spec_to_generic!(handler.cfg.spec_id, {
handler.pre_execution.deduct_caller = Arc::new(deduct_caller::<SPEC, EXT, DB>);
handler.post_execution.reimburse_caller = Arc::new(reimburse_caller::<SPEC, EXT, DB>);
handler.post_execution.reward_beneficiary = Arc::new(reward_beneficiary::<SPEC, EXT, DB>);
// Done with flags to avoid repetitive code
// handler.validation.tx_against_state = Arc::new(mainnet::validate_tx_against_state::<SPEC, EXT, DB>);
});
}

Expand All @@ -25,25 +26,7 @@ pub fn reimburse_caller<SPEC: Spec, EXT, DB: Database>(
context: &mut Context<EXT, DB>,
gas: &Gas,
) -> Result<(), EVMError<DB::Error>> {
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::<SPEC, EXT, DB>(context, gas)
}

/// Reward beneficiary with gas fee.
Expand All @@ -55,27 +38,10 @@ pub fn reward_beneficiary<SPEC: Spec, EXT, DB: Database>(
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::<SPEC, EXT, DB>(context, gas)?;

let treasury = context.evm.env.tx.taiko.treasury;
let basefee = context.evm.env.block.basefee;
Expand Down

0 comments on commit 1c4ffac

Please sign in to comment.