From 1c19c8c6ace4687e6f7586fb9f4e35f7077024a7 Mon Sep 17 00:00:00 2001 From: evalir Date: Tue, 9 May 2023 13:53:33 -0400 Subject: [PATCH] feat(cheatcodes): ensure `vm.difficulty` and `vm.prevrandao` fail if not using the correct EVM Version (#4904) * chore(cheatcodes): ensure difficulty/prevrandao fail if not using the correct EVM version. * chore: touch up revert error --- 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..d83bf56ac80a 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 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() } HEVMCalls::Prevrandao(inner) => { + ensure!( + data.env.cfg.spec_id >= SpecId::MERGE, + "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() }