Skip to content

Commit

Permalink
feat(cheatcodes): ensure vm.difficulty and vm.prevrandao fail if …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Evalir authored May 9, 2023
1 parent f0a42cc commit 1c19c8c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion evm/src/executor/inspector/cheatcodes/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -204,10 +204,18 @@ pub fn apply<DB: DatabaseExt>(
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()
}
Expand Down

0 comments on commit 1c19c8c

Please sign in to comment.