From 7122250f2463986a513d6a0df7eb783d41900d4a Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Mon, 8 May 2023 19:24:52 -0400 Subject: [PATCH 1/2] chore(cheatcodes): ensure difficulty/prevrandao fail if not using the correct EVM version. --- evm/src/executor/inspector/cheatcodes/env.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/evm/src/executor/inspector/cheatcodes/env.rs b/evm/src/executor/inspector/cheatcodes/env.rs index 90a6809ae1ac..4c5bcd05ea1e 100644 --- a/evm/src/executor/inspector/cheatcodes/env.rs +++ b/evm/src/executor/inspector/cheatcodes/env.rs @@ -14,7 +14,7 @@ use ethers::{ }; use foundry_config::Config; use revm::{ - primitives::{Bytecode, B256}, + primitives::{Bytecode, SpecId, B256}, Database, EVMData, }; use std::collections::BTreeMap; @@ -204,10 +204,18 @@ pub fn apply( Bytes::new() } HEVMCalls::Difficulty(inner) => { + ensure!( + data.env.cfg.spec_id < SpecId::MERGE, + "Difficulty is not supported after the merge. Please use vm.prevrandao instead." + ); data.env.block.difficulty = inner.0.into(); Bytes::new() } HEVMCalls::Prevrandao(inner) => { + ensure!( + data.env.cfg.spec_id >= SpecId::MERGE, + "Prevrandao is not supported before the merge. Please use vm.difficulty instead." + ); data.env.block.prevrandao = Some(B256::from(inner.0)); Bytes::new() } From 4ffa6d212fa7bad40172733cfcae84290656fef8 Mon Sep 17 00:00:00 2001 From: Enrique Ortiz Date: Tue, 9 May 2023 13:29:25 -0400 Subject: [PATCH 2/2] chore: touch up revert error --- evm/src/executor/inspector/cheatcodes/env.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evm/src/executor/inspector/cheatcodes/env.rs b/evm/src/executor/inspector/cheatcodes/env.rs index 4c5bcd05ea1e..d83bf56ac80a 100644 --- a/evm/src/executor/inspector/cheatcodes/env.rs +++ b/evm/src/executor/inspector/cheatcodes/env.rs @@ -206,7 +206,7 @@ pub fn apply( HEVMCalls::Difficulty(inner) => { ensure!( data.env.cfg.spec_id < SpecId::MERGE, - "Difficulty is not supported after the merge. Please use vm.prevrandao instead." + "Difficulty is not supported after the Paris hard fork. Please use vm.prevrandao instead. For more information, please see https://eips.ethereum.org/EIPS/eip-4399" ); data.env.block.difficulty = inner.0.into(); Bytes::new() @@ -214,7 +214,7 @@ pub fn apply( HEVMCalls::Prevrandao(inner) => { ensure!( data.env.cfg.spec_id >= SpecId::MERGE, - "Prevrandao is not supported before the merge. Please use vm.difficulty instead." + "Prevrandao is not supported before the Paris hard fork. Please use vm.difficulty instead. For more information, please see https://eips.ethereum.org/EIPS/eip-4399" ); data.env.block.prevrandao = Some(B256::from(inner.0)); Bytes::new()