Skip to content

Commit

Permalink
feat: anchor check in zeth
Browse files Browse the repository at this point in the history
  • Loading branch information
johntaiko committed Oct 19, 2023
1 parent daf73ee commit 0e7d779
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 75 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/primitives/Cargo.toml
Expand Up @@ -47,7 +47,7 @@ serde = [
arbitrary = ["std", "alloy-primitives/arbitrary", "bitflags/arbitrary"]

optimism = []
taiko = ["dep:once_cell"]
taiko = []

dev = [
"memory_limit",
Expand Down
17 changes: 0 additions & 17 deletions crates/primitives/src/env.rs
Expand Up @@ -3,8 +3,6 @@ use crate::{
InvalidTransaction, Spec, SpecId, B256, GAS_PER_BLOB, KECCAK_EMPTY, MAX_BLOB_NUMBER_PER_BLOCK,
MAX_INITCODE_SIZE, U256, VERSIONED_HASH_VERSION_KZG,
};
#[cfg(feature = "taiko")]
use crate::{EVMError, TaikoEnv, TxType};
use core::cmp::{min, Ordering};

#[derive(Clone, Debug, Default, PartialEq, Eq)]
Expand All @@ -13,20 +11,10 @@ pub struct Env {
pub cfg: CfgEnv,
pub block: BlockEnv,
pub tx: TxEnv,
#[cfg(feature = "taiko")]
/// Configuration of the taiko
pub taiko: TaikoEnv,
}

#[cfg(feature = "taiko")]
impl Env {
pub fn pre_check<DB>(&self) -> Result<(), EVMError<DB>> {
if !crate::anchor::validate(self) {
return Err(InvalidTransaction::InvalidAnchorTransaction.into());
}
Ok(())
}

pub fn is_anchor(&self) -> bool {
self.tx.index == 0
}
Expand Down Expand Up @@ -151,9 +139,6 @@ pub struct TxEnv {
/// The index of the transaction in the block.
#[cfg(feature = "taiko")]
pub index: usize,
/// The type of the transaction.
#[cfg(feature = "taiko")]
pub tx_type: TxType,

/// Caller aka Author aka transaction signer.
pub caller: Address,
Expand Down Expand Up @@ -456,8 +441,6 @@ impl Default for TxEnv {
Self {
#[cfg(feature = "taiko")]
index: 0,
#[cfg(feature = "taiko")]
tx_type: TxType::Legacy,

caller: Address::ZERO,
gas_limit: u64::MAX,
Expand Down
4 changes: 0 additions & 4 deletions crates/primitives/src/lib.rs
Expand Up @@ -14,8 +14,6 @@ pub mod precompile;
pub mod result;
pub mod specification;
pub mod state;
#[cfg(feature = "taiko")]
pub mod taiko;
pub mod utilities;

pub use alloy_primitives::{
Expand All @@ -34,6 +32,4 @@ pub use precompile::*;
pub use result::*;
pub use specification::*;
pub use state::*;
#[cfg(feature = "taiko")]
pub use taiko::*;
pub use utilities::*;
5 changes: 0 additions & 5 deletions crates/primitives/src/taiko.rs

This file was deleted.

27 changes: 0 additions & 27 deletions crates/primitives/src/taiko/anchor.rs

This file was deleted.

15 changes: 0 additions & 15 deletions crates/primitives/src/taiko/env.rs

This file was deleted.

3 changes: 2 additions & 1 deletion crates/revm/Cargo.toml
Expand Up @@ -28,6 +28,7 @@ tokio = { version = "1.32", features = [
ethers-providers = { version = "2.0", optional = true }
ethers-core = { version = "2.0", optional = true }
futures = { version = "0.3.27", optional = true }
once_cell = { version = "1.18", default-features = false, optional = true }

[dev-dependencies]
ethers-contract = { version = "2.0.10", default-features = false }
Expand All @@ -41,7 +42,7 @@ serde = ["dep:serde", "dep:serde_json", "revm-interpreter/serde"]
arbitrary = ["revm-interpreter/arbitrary"]

optimism = ["revm-interpreter/optimism", "revm-precompile/optimism"]
taiko = ["revm-interpreter/taiko", "revm-precompile/taiko"]
taiko = ["revm-interpreter/taiko", "revm-precompile/taiko", "dep:once_cell"]

ethersdb = ["std", "tokio", "futures", "ethers-providers", "ethers-core"]

Expand Down
3 changes: 0 additions & 3 deletions crates/revm/src/evm_impl.rs
Expand Up @@ -158,9 +158,6 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact<DB::Error>
fn preverify_transaction(&mut self) -> Result<(), EVMError<DB::Error>> {
let env = self.env();

#[cfg(feature = "taiko")]
env.pre_check()?;

// Important: validate block before tx.
env.validate_block_env::<GSPEC>()?;
env.validate_tx::<GSPEC>()?;
Expand Down
11 changes: 9 additions & 2 deletions crates/revm/src/handler/taiko.rs
@@ -1,11 +1,18 @@
//! Mainnet related handlers.
use core::str::FromStr;
use revm_interpreter::primitives::EVMError;

use crate::{
interpreter::{return_ok, return_revert, Gas, InstructionResult},
primitives::{db::Database, Env, Spec, SpecId::LONDON, U256},
primitives::{db::Database, Address, Env, Spec, SpecId::LONDON, U256},
EVMData,
};
use once_cell::sync::Lazy;

static TREASURY: Lazy<Address> = Lazy::new(|| {
Address::from_str("0xdf09A0afD09a63fb04ab3573922437e1e637dE8b")
.expect("invalid treasury account")
});

/// Handle output of the transaction
pub fn handle_call_return<SPEC: Spec>(
Expand Down Expand Up @@ -93,7 +100,7 @@ pub fn reward_beneficiary<SPEC: Spec, DB: Database>(
.balance
.saturating_add(coinbase_gas_price * U256::from(gas.spend() - gas_refund));

let treasury = *crate::primitives::anchor::TREASURY;
let treasury = *TREASURY;
let basefee = data.env.block.basefee;

let (treasury_account, _) = data
Expand Down

0 comments on commit 0e7d779

Please sign in to comment.