Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare for ontake upgrade #27

Merged
merged 10 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 119 additions & 61 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,16 @@ similar-asserts = "1.5.0"
test-fuzz = "5"

# raiko
raiko-core = { git = "https://github.com/taikoxyz/raiko.git", branch = "reth-wip" }
raiko-lib = { git = "https://github.com/taikoxyz/raiko.git", branch = "reth-wip" }
anyhow = "1.0"

[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko", default-features = false, features = [
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko-ontake", default-features = false, features = [
"std",
"serde",
"taiko",
]}
revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko"}
revm-interpreter = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko-ontake" }
revm-precompile = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko-ontake" }
revm-primitives = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko-ontake"}
c-kzg = { git = "https://github.com/brechtpd/c-kzg-4844", branch = "for-alpha7" }
secp256k1 = { git = "https://github.com/CeciliaZ030/rust-secp256k1", branch = "sp1-patch" }
1 change: 1 addition & 0 deletions crates/chainspec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ arbitrary = [
"alloy-chains/arbitrary"
]
network = ["reth-network-peers"]
taiko = ["reth-ethereum-forks/taiko"]
14 changes: 11 additions & 3 deletions crates/chainspec/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ pub static TAIKO_A7: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(0) },
),
(Hardfork::Shanghai, ForkCondition::Timestamp(0)),
#[cfg(feature = "taiko")]
(Hardfork::Hekla, ForkCondition::Block(0)),
]),
deposit_contract: None,
..Default::default()
Expand Down Expand Up @@ -150,6 +152,10 @@ pub static TAIKO_DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(0) },
),
(Hardfork::Shanghai, ForkCondition::Timestamp(0)),
#[cfg(feature = "taiko")]
(Hardfork::Hekla, ForkCondition::Block(0)),
#[cfg(feature = "taiko")]
(Hardfork::Ontake, ForkCondition::Block(20)), //todo
]),
deposit_contract: None,
..Default::default()
Expand All @@ -174,14 +180,16 @@ pub static TAIKO_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
(Hardfork::Byzantium, ForkCondition::Block(0)),
(Hardfork::Constantinople, ForkCondition::Block(0)),
(Hardfork::Petersburg, ForkCondition::Block(0)),
(Hardfork::Istanbul, ForkCondition::Block(1561651)),
(Hardfork::Berlin, ForkCondition::Block(4460644)),
(Hardfork::London, ForkCondition::Block(5062605)),
(Hardfork::Istanbul, ForkCondition::Block(0)),
(Hardfork::Berlin, ForkCondition::Block(0)),
(Hardfork::London, ForkCondition::Block(0)),
(
Hardfork::Paris,
ForkCondition::TTD { fork_block: None, total_difficulty: U256::from(0) },
),
(Hardfork::Shanghai, ForkCondition::Timestamp(0)),
#[cfg(feature = "taiko")]
(Hardfork::Hekla, ForkCondition::Block(0)),
]),
deposit_contract: None,
..Default::default()
Expand Down
1 change: 1 addition & 0 deletions crates/ethereum-forks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ proptest-derive.workspace = true

[features]
default = ["std", "serde"]
taiko = []
std = ["thiserror-no-std/std"]
serde = ["dep:serde"]
arbitrary = ["dep:arbitrary", "dep:proptest", "dep:proptest-derive"]
Expand Down
7 changes: 6 additions & 1 deletion crates/ethereum-forks/src/hardfork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ pub enum Hardfork {
Regolith,
/// Shanghai: <https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md>.
Shanghai,
/// Hekla: the 1st taiko mainnet version: <>
#[cfg(feature = "taiko")]
Hekla,
/// Ontake: the 1st taiko mainnet fork: <>
smtmfft marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "taiko")]
Ontake,
/// Canyon:
/// <https://github.com/ethereum-optimism/specs/blob/main/specs/protocol/superchain-upgrades.md#canyon>.
#[cfg(feature = "optimism")]
Expand All @@ -76,7 +82,6 @@ pub enum Hardfork {
#[cfg(feature = "optimism")]
Ecotone,
// ArbOS20Atlas,

// Upcoming
/// Prague: <https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/prague.md>
Prague,
Expand Down
88 changes: 69 additions & 19 deletions crates/ethereum/evm/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

use crate::{
dao_fork::{DAO_HARDFORK_BENEFICIARY, DAO_HARDKFORK_ACCOUNTS},
taiko::{check_anchor_tx, TaikoData}, EthEvmConfig,
taiko::{check_anchor_tx, check_anchor_tx_ontake, TaikoData},
EthEvmConfig,
};
use anyhow::Result;
use reth_chainspec::{ChainSpec, MAINNET};
pub use reth_consensus::Consensus;
pub use reth_ethereum_consensus::{EthBeaconConsensus, validate_block_post_execution};
pub use reth_ethereum_consensus::{validate_block_post_execution, EthBeaconConsensus};
use reth_evm::{
execute::{
BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput,
Expand All @@ -16,7 +18,8 @@ use reth_evm::{
};
use reth_execution_types::ExecutionOutcome;
use reth_primitives::{
BlockNumber, BlockWithSenders, Hardfork, Header, Receipt, Request, Withdrawals, U256,
revm::config::revm_spec, BlockNumber, BlockWithSenders, Hardfork, Head, Header, Receipt,
Request, Withdrawals, U256,
};
use reth_prune_types::PruneModes;
use reth_revm::{
Expand All @@ -26,15 +29,14 @@ use reth_revm::{
apply_beacon_root_contract_call, apply_blockhashes_update,
apply_withdrawal_requests_contract_call, post_block_balance_increments,
},
Evm, State,
JournaledState,
Evm, JournaledState, State,
};
use revm_primitives::{
db::{Database, DatabaseCommit}, Address, BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ResultAndState,
EVMError, HashSet,
db::{Database, DatabaseCommit},
Address, BlockEnv, CfgEnvWithHandlerCfg, EVMError, EnvWithHandlerCfg, HashSet, ResultAndState,
SpecId,
};
use std::sync::Arc;
use anyhow::Result;

/// Provides executors to execute regular ethereum blocks
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -176,8 +178,28 @@ where

// verify the anchor tx
if is_anchor {
check_anchor_tx(transaction, sender, &block.block, taiko_data.clone().unwrap())
let spec_id = revm_spec(
&self.chain_spec,
Head { number: block.number, ..Default::default() },
);
if spec_id.is_enabled_in(SpecId::ONTAKE) {
check_anchor_tx_ontake(
transaction,
sender,
&block.block,
taiko_data.clone().unwrap(),
)
.map_err(|e| BlockExecutionError::CanonicalRevert { inner: e.to_string() })?;
} else if spec_id.is_enabled_in(SpecId::HEKLA) {
check_anchor_tx(transaction, sender, &block.block, taiko_data.clone().unwrap())
.map_err(|e| BlockExecutionError::CanonicalRevert {
inner: e.to_string(),
})?;
} else {
return Err(BlockExecutionError::CanonicalRevert {
inner: "unknown spec id for anchor".to_string(),
});
}
}

// If the signature was not valid, the sender address will have been set to zero
Expand All @@ -188,7 +210,9 @@ where
continue;
}
// In all other cases, the tx needs to have a valid signature
return Err(BlockExecutionError::CanonicalRevert { inner: "invalid tx".to_string() });
return Err(BlockExecutionError::CanonicalRevert {
inner: "invalid tx".to_string(),
});
}

// The sum of the transaction’s gas limit, Tg, and the gas utilized in this block prior,
Expand All @@ -202,7 +226,7 @@ where
transaction_gas_limit: transaction.gas_limit(),
block_available_gas,
}
.into())
.into());
}

EvmConfig::fill_tx_env(evm.tx_mut(), transaction, *sender);
Expand All @@ -211,6 +235,7 @@ where
evm.tx_mut().taiko.is_anchor = is_anchor;
// set the treasury address
evm.tx_mut().taiko.treasury = taiko_data.clone().unwrap().l2_contract;
evm.tx_mut().taiko.basefee_ratio = taiko_data.clone().unwrap().basefee_ratio;

// Execute transaction.
let res = evm.transact().map_err(move |err| {
Expand All @@ -222,7 +247,8 @@ where
});
if res.is_err() {
// Clear the state for the next tx
evm.context.evm.journaled_state = JournaledState::new(evm.context.evm.journaled_state.spec, HashSet::new());
evm.context.evm.journaled_state =
JournaledState::new(evm.context.evm.journaled_state.spec, HashSet::new());

if optimistic {
continue;
Expand All @@ -239,11 +265,13 @@ where
println!("Invalid tx at {}: {:?}", idx, invalid_transaction);
// skip the tx
continue;
},
}
_ => {
// any other error is not allowed
return Err(BlockExecutionError::Validation(BlockValidationError::EVM { hash, error }));
},
return Err(BlockExecutionError::Validation(
BlockValidationError::EVM { hash, error },
));
}
},
_ => {
// Any other type of error is not allowed
Expand Down Expand Up @@ -289,7 +317,12 @@ where
vec![]
};

Ok(EthExecuteOutput { receipts, requests, gas_used: cumulative_gas_used, valid_transaction_indices })
Ok(EthExecuteOutput {
receipts,
requests,
gas_used: cumulative_gas_used,
valid_transaction_indices,
})
}
}

Expand All @@ -313,7 +346,12 @@ pub struct EthBlockExecutor<EvmConfig, DB> {
impl<EvmConfig, DB> EthBlockExecutor<EvmConfig, DB> {
/// Creates a new Ethereum block executor.
pub const fn new(chain_spec: Arc<ChainSpec>, evm_config: EvmConfig, state: State<DB>) -> Self {
Self { executor: EthEvmExecutor { chain_spec, evm_config }, state, optimistic: false, taiko_data: None }
Self {
executor: EthEvmExecutor { chain_spec, evm_config },
state,
optimistic: false,
taiko_data: None,
}
}

/// Optimistic execution
Expand Down Expand Up @@ -382,7 +420,12 @@ where
let env = self.evm_env_for_block(&block.header, total_difficulty);
let output = {
let evm = self.executor.evm_config.evm_with_env(&mut self.state, env);
self.executor.execute_state_transitions(block, evm, self.optimistic, self.taiko_data.clone())
self.executor.execute_state_transitions(
block,
evm,
self.optimistic,
self.taiko_data.clone(),
)
}?;

// 3. apply post execution changes
Expand Down Expand Up @@ -462,7 +505,14 @@ where
// NOTE: we need to merge keep the reverts for the bundle retention
self.state.merge_transitions(BundleRetention::Reverts);

Ok(BlockExecutionOutput { state: self.state.take_bundle(), receipts, requests, gas_used, db: self.state, valid_transaction_indices })
Ok(BlockExecutionOutput {
state: self.state.take_bundle(),
receipts,
requests,
gas_used,
db: self.state,
valid_transaction_indices,
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use reth_primitives::{
revm_primitives::{AnalysisKind, CfgEnvWithHandlerCfg, TxEnv},
Address, Head, Header, TransactionSigned, U256,
};
use reth_revm::{Database, EvmBuilder};
use reth_revm::taiko::handler_register;
use reth_revm::{Database, EvmBuilder};

pub mod execute;
pub mod taiko;
Expand Down
Loading
Loading