Skip to content

Commit

Permalink
basic taiko support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brechtpd committed May 31, 2024
1 parent 7509ce5 commit fbd1411
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 12 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ reth-node-events = { path = "crates/node/events" }
reth-testing-utils = { path = "testing/testing-utils" }

# revm
revm = { version = "8.0.0", features = ["std", "secp256k1", "taiko"], default-features = false }
revm-primitives = { version = "3.1.1", features = ["std", "taiko"], default-features = false }
revm = { version = "8.0.0", features = ["std", "secp256k1"], default-features = false }
revm-primitives = { version = "3.1.1", features = ["std"], default-features = false }
revm-inspectors = { git = "https://github.com/paradigmxyz/evm-inspectors", rev = "848d568" }

# eth
Expand Down Expand Up @@ -414,10 +414,10 @@ alloy-rpc-types-trace = { git = "https://github.com/brechtpd/alloy", branch = "1
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v35_taiko_v2", default-features = false, features = [
"std",
"serde",
#"taiko",
"taiko",
]}
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v35_taiko_v2", default-features = false, features = [
#"std",
#"serde",
#"taiko",
"std",
"serde",
"taiko",
]}
9 changes: 9 additions & 0 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ where
where
DB: Database<Error = ProviderError>,
{
let is_taiko = self.chain_spec.is_taiko();

// apply pre execution changes
apply_beacon_root_contract_call(
&self.chain_spec,
Expand All @@ -156,6 +158,7 @@ where
// execute transactions
let mut cumulative_gas_used = 0;
let mut receipts = Vec::with_capacity(block.body.len());
let mut tx_number = 0;
for (sender, transaction) in block.transactions_with_sender() {
// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
// must be no greater than the block’s gasLimit.
Expand All @@ -172,6 +175,12 @@ where
}

EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender, ());
if is_taiko && tx_number == 0 {
evm.tx_mut().taiko.is_anchor = true;
// set the treasury address
//tx_env.taiko.treasury = chain_spec.l2_contract.unwrap_or_default();
}
tx_number += 1;

// Execute transaction.
let res = evm.transact().map_err(move |err| {
Expand Down
1 change: 1 addition & 0 deletions crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
cfg_env.perf_analyse_created_bytecodes = AnalysisKind::Analyse;

cfg_env.handler_cfg.spec_id = spec_id;
cfg_env.handler_cfg.is_taiko = chain_spec.is_taiko();
}
}

Expand Down
11 changes: 8 additions & 3 deletions crates/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
/// This does not automatically configure the EVM with [ConfigureEvmEnv] methods. It is up to
/// the caller to call an appropriate method to fill the transaction and block environment
/// before executing any transactions using the provided EVM.
fn evm<'a, DB: Database + 'a>(&self, db: DB) -> Evm<'a, (), DB> {
EvmBuilder::default().with_db(db).build()
fn evm<'a, DB: Database + 'a>(&self, db: DB, is_taiko: bool) -> Evm<'a, (), DB> {
let builder = EvmBuilder::default().with_db(db);
if is_taiko {
builder.append_handler_register(revm::taiko::handler_register::taiko_handle_register).build()
} else {
builder.build()
}
}

/// Returns a new EVM with the given database configured with the given environment settings,
Expand All @@ -34,7 +39,7 @@ pub trait ConfigureEvm: ConfigureEvmEnv {
db: DB,
env: EnvWithHandlerCfg,
) -> Evm<'a, (), DB> {
let mut evm = self.evm(db);
let mut evm = self.evm(db, env.handler_cfg.is_taiko);
evm.modify_spec_id(env.spec_id());
evm.context.evm.env = env.env;
evm
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use info::ChainInfo;
pub use spec::{
AllGenesisFormats, BaseFeeParams, BaseFeeParamsKind, ChainSpec, ChainSpecBuilder,
DisplayHardforks, ForkBaseFeeParams, ForkCondition, ForkTimestamps, DEV, GOERLI, HOLESKY,
MAINNET, SEPOLIA,
MAINNET, SEPOLIA, TAIKO_A7,
};
#[cfg(feature = "optimism")]
pub use spec::{BASE_MAINNET, BASE_SEPOLIA, OP_MAINNET, OP_SEPOLIA};
Expand Down
68 changes: 68 additions & 0 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
fmt::{Display, Formatter},
sync::Arc,
};
use alloy_chains::ChainKind::Id;

pub use alloy_eips::eip1559::BaseFeeParams;

Expand Down Expand Up @@ -78,6 +79,66 @@ pub static MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

/// The Taiko A7 spec
pub static TAIKO_A7: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: 167009.into(),
genesis: serde_json::from_str(include_str!("../../res/genesis/mainnet.json"))
.expect("Can't deserialize Mainnet genesis json"),
genesis_hash: Some(b256!(
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
)),
// <https://etherscan.io/block/15537394>
paris_block_and_final_difficulty: Some((
15537394,
U256::from(58_750_003_716_598_352_816_469u128),
)),
fork_timestamps: ForkTimestamps::default().shanghai(0),
hardforks: BTreeMap::from([
(Hardfork::Shanghai, ForkCondition::Block(0)),
]),
// https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0
deposit_contract: Some(DepositContract::new(
address!("00000000219ab540356cbb839cbe05303d7705fa"),
11052984,
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 3500,
}
.into()
});

/// The Taiko A7 spec
pub static TAIKO_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
chain: 167000.into(),
genesis: serde_json::from_str(include_str!("../../res/genesis/mainnet.json"))
.expect("Can't deserialize Mainnet genesis json"),
genesis_hash: Some(b256!(
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
)),
// <https://etherscan.io/block/15537394>
paris_block_and_final_difficulty: Some((
15537394,
U256::from(58_750_003_716_598_352_816_469u128),
)),
fork_timestamps: ForkTimestamps::default().shanghai(1681338455).cancun(1710338135),
hardforks: BTreeMap::from([
(Hardfork::Shanghai, ForkCondition::Block(0)),
]),
// https://etherscan.io/tx/0xe75fb554e433e03763a1560646ee22dcb74e5274b34c5ad644e7c0f619a7e1d0
deposit_contract: Some(DepositContract::new(
address!("00000000219ab540356cbb839cbe05303d7705fa"),
11052984,
b256!("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5"),
)),
base_fee_params: BaseFeeParamsKind::Constant(BaseFeeParams::ethereum()),
prune_delete_limit: 3500,
}
.into()
});

/// The Goerli spec
pub static GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ChainSpec {
Expand Down Expand Up @@ -583,6 +644,13 @@ impl ChainSpec {
self.chain.is_optimism()
}

/// Returns `true` if this chain contains Taiko configuration.
#[inline]
pub fn is_taiko(&self) -> bool {
let id = self.chain.id();
id >= 167000 && id <= 168000
}

/// Returns `true` if this chain is Optimism mainnet.
#[inline]
pub fn is_optimism_mainnet(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub use block::{
pub use chain::{
AllGenesisFormats, BaseFeeParams, BaseFeeParamsKind, Chain, ChainInfo, ChainSpec,
ChainSpecBuilder, DisplayHardforks, ForkBaseFeeParams, ForkCondition, ForkTimestamps,
NamedChain, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA,
NamedChain, DEV, GOERLI, HOLESKY, MAINNET, SEPOLIA, TAIKO_A7,
};
#[cfg(feature = "zstd-codec")]
pub use compression::*;
Expand Down
4 changes: 4 additions & 0 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ optimism = [
"reth-consensus-common/optimism",
"reth-interfaces/optimism",
]
taiko = [
"revm/taiko",
"reth-primitives/taiko",
]
js-tracer = ["revm-inspectors/js-tracer"]
4 changes: 4 additions & 0 deletions crates/revm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ impl ConfigureEvmEnv for TestEvmConfig {
{
cfg_env.handler_cfg.is_optimism = chain_spec.is_optimism();
}
#[cfg(feature = "taiko")]
{
cfg_env.handler_cfg.is_taiko = chain_spec.is_taiko();
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub(crate) fn create_txn_env(
max_fee_per_blob_gas,
#[cfg(feature = "optimism")]
optimism: OptimismFields { enveloped_tx: Some(Bytes::new()), ..Default::default() },
taiko: revm_primitives::TaikoFields { treasury: Address::default(), is_anchor: false },
taiko: revm_primitives::TaikoFields { treasury: address!(0x1670090000000000000000000000000000010001), is_anchor: false },
};

Ok(env)
Expand Down

0 comments on commit fbd1411

Please sign in to comment.