Skip to content

Commit

Permalink
fix(fuzz) - consistent gas snapshot between runs
Browse files Browse the repository at this point in the history
  • Loading branch information
grandizzy committed May 20, 2024
1 parent 1ddea96 commit cf187fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/forge/bin/cmd/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ impl SnapshotArgs {
}

pub async fn run(mut self) -> Result<()> {
// Set fuzz seed so gas snapshots are deterministic
// Set fuzz seed and disable fuzzing from state so gas snapshots are deterministic.
self.test.fuzz_seed = Some(U256::from_be_bytes(STATIC_FUZZ_SEED));
self.test.fuzz_dictionary_weight = Some(0);

let outcome = self.test.execute_tests().await?;
outcome.ensure_ok()?;
Expand Down
9 changes: 9 additions & 0 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ pub struct TestArgs {
#[arg(long)]
pub fuzz_seed: Option<U256>,

/// Set fuzz dictionary weight.
#[arg(long)]
pub fuzz_dictionary_weight: Option<u32>,

#[arg(long, env = "FOUNDRY_FUZZ_RUNS", value_name = "RUNS")]
pub fuzz_runs: Option<u64>,

Expand Down Expand Up @@ -227,6 +231,11 @@ impl TestArgs {
config.invariant.gas_report_samples = 0;
}

// Set fuzz dictionary weight if specified as arg.
if let Some(dictionary_weight) = self.fuzz_dictionary_weight {
config.fuzz.dictionary.dictionary_weight = dictionary_weight;
}

// Set up the project.
let mut project = config.project()?;

Expand Down

0 comments on commit cf187fb

Please sign in to comment.