diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 62c8e8359e..1257d51a10 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -17,7 +17,7 @@ hex = "0.4" indicatif = "0.17" plain_hasher = "0.2" primitive-types = { version = "0.11", features = ["rlp", "serde"] } -revm = { path = "../../crates/revm", version = "2.1", default-features = false, features = ["web3db","std","secp256k1"] } +revm = { path = "../../crates/revm", version = "2.2", default-features = false, features = ["web3db","std","secp256k1"] } rlp = { version = "0.5", default-features = false } ruint = { version = "1.6.0", features = ["rlp", "serde"] } serde = "1.0" diff --git a/bins/revme/src/statetest/runner.rs b/bins/revme/src/statetest/runner.rs index 6f9f8e0f06..17963b724e 100644 --- a/bins/revme/src/statetest/runner.rs +++ b/bins/revme/src/statetest/runner.rs @@ -156,6 +156,8 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc>) -> Result< env.block.gas_limit = unit.env.current_gas_limit; env.block.basefee = unit.env.current_base_fee.unwrap_or_default(); env.block.difficulty = unit.env.current_difficulty; + // after the Merge prevrandao replaces mix_hash field in block and replaced difficulty opcode in EVM. + env.block.prevrandao = Some(unit.env.current_difficulty.to_be_bytes().into()); //tx env env.tx.caller = diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index ba57871c57..898c43ee52 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -49,6 +49,10 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> Transact let gas_limit = self.data.env.tx.gas_limit; let exit = |reason: Return| (ExecutionResult::new_with_reason(reason), State::new()); + if GSPEC::enabled(MERGE) && self.data.env.block.prevrandao.is_none() { + return exit(Return::PrevrandaoNotSet); + } + if GSPEC::enabled(LONDON) { if let Some(priority_fee) = self.data.env.tx.gas_priority_fee { if priority_fee > self.data.env.tx.gas_price { diff --git a/crates/revm/src/instructions.rs b/crates/revm/src/instructions.rs index 296f46e57f..54f0da6740 100644 --- a/crates/revm/src/instructions.rs +++ b/crates/revm/src/instructions.rs @@ -59,6 +59,7 @@ pub enum Return { OutOfOffset, FatalExternalError, GasMaxFeeGreaterThanPriorityFee, + PrevrandaoNotSet, GasPriceLessThenBasefee, CallerGasLimitMoreThenBlock, /// EIP-3607 Reject transactions from senders with deployed code @@ -225,7 +226,7 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H opcode::COINBASE => host_env::coinbase(interp, host), opcode::TIMESTAMP => host_env::timestamp(interp, host), opcode::NUMBER => host_env::number(interp, host), - opcode::DIFFICULTY => host_env::difficulty(interp, host), + opcode::DIFFICULTY => host_env::difficulty::(interp, host), opcode::GASLIMIT => host_env::gaslimit(interp, host), opcode::SLOAD => host::sload::(interp, host), opcode::SSTORE => host::sstore::(interp, host), diff --git a/crates/revm/src/instructions/host_env.rs b/crates/revm/src/instructions/host_env.rs index b016f56dde..904b788041 100644 --- a/crates/revm/src/instructions/host_env.rs +++ b/crates/revm/src/instructions/host_env.rs @@ -27,9 +27,13 @@ pub fn number(interp: &mut Interpreter, host: &mut H) -> Return { Return::Continue } -pub fn difficulty(interp: &mut Interpreter, host: &mut H) -> Return { +pub fn difficulty(interp: &mut Interpreter, host: &mut H) -> Return { // gas!(interp, gas::BASE); - push!(interp, host.env().block.difficulty); + if SPEC::enabled(MERGE) { + push_h256!(interp, host.env().block.prevrandao.unwrap()); + } else { + push!(interp, host.env().block.difficulty); + } Return::Continue } diff --git a/crates/revm/src/models.rs b/crates/revm/src/models.rs index 7cbfa06538..4fcb12312f 100644 --- a/crates/revm/src/models.rs +++ b/crates/revm/src/models.rs @@ -195,7 +195,11 @@ pub struct BlockEnv { /// Address where we are going to send gas spend pub coinbase: H160, pub timestamp: U256, + /// Difficulty is removed and not used after Paris (aka TheMerge). Value is replaced with prevrandao. pub difficulty: U256, + /// Prevrandao is used after Paris (aka TheMerge) instead of the difficulty value. + /// NOTE: prevrandao can be found in block in place of mix_hash. + pub prevrandao: Option, /// basefee is added in EIP1559 London upgrade pub basefee: U256, pub gas_limit: U256, @@ -288,6 +292,7 @@ impl Default for BlockEnv { coinbase: H160::zero(), timestamp: U256::from(1), difficulty: U256::ZERO, + prevrandao: Some(H256::zero()), basefee: U256::ZERO, } }