Skip to content

Commit 36f06fe

Browse files
authored
feat: enable hardfork support (#152)
1 parent 5b9e17f commit 36f06fe

File tree

26 files changed

+250
-33
lines changed

26 files changed

+250
-33
lines changed

Cargo.lock

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ foundry-evm = { path = "crates/evm/evm" }
207207
foundry-evm-abi = { path = "crates/evm/abi" }
208208
foundry-evm-core = { path = "crates/evm/core" }
209209
foundry-evm-coverage = { path = "crates/evm/coverage" }
210+
foundry-evm-hardforks = { path = "crates/evm/hardforks" }
210211
foundry-evm-networks = { path = "crates/evm/networks" }
211212
foundry-evm-fuzz = { path = "crates/evm/fuzz" }
212213
foundry-evm-traces = { path = "crates/evm/traces" }

crates/anvil/src/config.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,13 @@ impl NodeConfig {
689689
self
690690
}
691691

692+
/// Sets the hardfork
693+
#[must_use]
694+
pub fn with_hardfork(mut self, hardfork: Option<FoundryHardfork>) -> Self {
695+
self.hardfork = hardfork;
696+
self
697+
}
698+
692699
/// Sets the init genesis (genesis.json)
693700
#[must_use]
694701
pub fn with_genesis(mut self, genesis: Option<Genesis>) -> Self {
@@ -728,13 +735,6 @@ impl NodeConfig {
728735
.unwrap_or(0)
729736
}
730737

731-
/// Sets the hardfork
732-
#[must_use]
733-
pub fn with_hardfork(mut self, hardfork: Option<FoundryHardfork>) -> Self {
734-
self.hardfork = hardfork;
735-
self
736-
}
737-
738738
/// Sets the genesis accounts
739739
#[must_use]
740740
pub fn with_genesis_accounts(mut self, accounts: Vec<PrivateKeySigner>) -> Self {

crates/cast/src/cmd/call.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use foundry_config::{
2929
};
3030
use foundry_evm::{
3131
executors::TracingExecutor,
32+
hardforks::FoundryHardfork,
3233
opts::EvmOpts,
3334
traces::{InternalTraceMode, TraceMode},
3435
};
@@ -117,6 +118,11 @@ pub struct CallArgs {
117118
#[arg(long, requires = "trace")]
118119
evm_version: Option<EvmVersion>,
119120

121+
/// The EVM hardfork to use.
122+
/// Can only be used with `--trace`.
123+
#[arg(long, requires = "trace")]
124+
pub hardfork: Option<FoundryHardfork>,
125+
120126
/// The block height to query at.
121127
///
122128
/// Can also be the tags earliest, finalized, safe, latest, or pending.
@@ -224,6 +230,7 @@ impl CallArgs {
224230
block,
225231
trace,
226232
evm_version,
233+
hardfork,
227234
debug,
228235
decode_internal,
229236
labels,
@@ -301,10 +308,12 @@ impl CallArgs {
301308
InternalTraceMode::None
302309
})
303310
.with_state_changes(shell::verbosity() > 4);
311+
304312
let mut executor = TracingExecutor::new(
305313
env,
306314
fork,
307315
evm_version,
316+
hardfork,
308317
trace_mode,
309318
networks,
310319
create2_deployer,

crates/cast/src/cmd/run.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use foundry_evm::{
2727
Env,
2828
core::env::AsEnvMut,
2929
executors::{EvmError, Executor, TracingExecutor},
30+
hardforks::FoundryHardfork,
3031
opts::EvmOpts,
3132
traces::{InternalTraceMode, TraceMode, Traces},
3233
};
@@ -85,6 +86,12 @@ pub struct RunArgs {
8586
#[arg(long)]
8687
evm_version: Option<EvmVersion>,
8788

89+
/// The EVM hardfork to use.
90+
///
91+
/// Overrides the hardfork specified in the config.
92+
#[arg(long)]
93+
hardfork: Option<FoundryHardfork>,
94+
8895
/// Sets the number of assumed available compute units per second for this provider
8996
///
9097
/// default value: 330
@@ -197,6 +204,7 @@ impl RunArgs {
197204
env.clone(),
198205
fork,
199206
evm_version,
207+
self.hardfork,
200208
trace_mode,
201209
networks,
202210
create2_deployer,

crates/chisel/src/executor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl SessionSource {
227227
})
228228
.gas_limit(self.config.evm_opts.gas_limit())
229229
.spec_id(self.config.foundry_config.evm_spec_id())
230+
.hardfork(self.config.foundry_config.hardfork())
230231
.legacy_assertions(self.config.foundry_config.legacy_assertions)
231232
.build(env, backend);
232233

crates/config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ foundry-compilers = { workspace = true, features = ["svm-solc"] }
2020
alloy-chains = { workspace = true, features = ["serde"] }
2121
alloy-primitives = { workspace = true, features = ["serde"] }
2222

23+
foundry-evm-hardforks.workspace = true
2324
foundry-evm-networks.workspace = true
2425

2526
revm.workspace = true

crates/config/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use foundry_compilers::{
3939
multi::{MultiCompilerParser, MultiCompilerRestrictions},
4040
solc::{CliSettings, SolcLanguage, SolcSettings},
4141
};
42+
use foundry_evm_hardforks::FoundryHardfork;
4243
use regex::Regex;
4344
use revm::primitives::hardfork::SpecId;
4445
use semver::Version;
@@ -235,6 +236,8 @@ pub struct Config {
235236
/// The EVM version to use when building contracts.
236237
#[serde(with = "from_str_lowercase")]
237238
pub evm_version: EvmVersion,
239+
/// The EVM hardfork to use when simulating execution.
240+
pub hardfork: Option<FoundryHardfork>,
238241
/// List of contracts to generate gas reports for.
239242
pub gas_reports: Vec<String>,
240243
/// List of contracts to ignore for gas reports.
@@ -2483,6 +2486,7 @@ impl Default for Config {
24832486
include_paths: vec![],
24842487
force: false,
24852488
evm_version: EvmVersion::Prague,
2489+
hardfork: None,
24862490
gas_reports: vec!["*".to_string()],
24872491
gas_reports_ignore: vec![],
24882492
gas_reports_include_tests: false,

crates/evm/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ foundry-cheatcodes-spec.workspace = true
1818
foundry-common.workspace = true
1919
foundry-config.workspace = true
2020
foundry-evm-abi.workspace = true
21+
foundry-evm-hardforks.workspace = true
2122
foundry-evm-networks.workspace = true
2223

2324
alloy-chains.workspace = true
2425
alloy-dyn-abi = { workspace = true, features = ["arbitrary", "eip712"] }
2526
alloy-evm.workspace = true
2627
alloy-genesis.workspace = true
2728
alloy-hardforks.workspace = true
28-
alloy-op-hardforks.workspace = true
2929
alloy-json-abi.workspace = true
3030
alloy-primitives = { workspace = true, features = [
3131
"serde",

crates/evm/core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub mod decode;
3636
pub mod either_evm;
3737
pub mod evm;
3838
pub mod fork;
39-
pub mod hardfork;
4039
pub mod ic;
4140
pub mod opts;
4241
pub mod precompiles;

0 commit comments

Comments
 (0)