Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions crates/evm/evm/src/executors/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const COVERAGE_MAP_SIZE: usize = 65536;

/// Possible mutation strategies to apply on a call sequence.
#[derive(Debug, Clone)]
enum MutationType {
pub(crate) enum MutationType {
/// Splice original call sequence.
Splice,
/// Repeat selected call several times.
Expand All @@ -47,19 +47,19 @@ enum MutationType {

/// Holds Corpus information.
#[derive(Serialize)]
struct CorpusEntry {
pub(crate) struct CorpusEntry {
// Unique corpus identifier.
uuid: Uuid,
pub(crate) uuid: Uuid,
// Total mutations of corpus as primary source.
total_mutations: usize,
pub(crate) total_mutations: usize,
// New coverage found as a result of mutating this corpus.
new_finds_produced: usize,
pub(crate) new_finds_produced: usize,
// Corpus call sequence.
#[serde(skip_serializing)]
tx_seq: Vec<BasicTxDetails>,
pub(crate) tx_seq: Vec<BasicTxDetails>,
// Whether this corpus is favored, i.e. producing new finds more often than
// `FAVORABILITY_THRESHOLD`.
is_favored: bool,
pub(crate) is_favored: bool,
}

impl CorpusEntry {
Expand Down Expand Up @@ -92,7 +92,7 @@ pub(crate) struct CorpusMetrics {
// Number of features (new hitcount bin of previously hit edge) seen during the invariant run.
cumulative_features_seen: usize,
// Number of corpus entries.
corpus_count: usize,
pub(crate) corpus_count: usize,
// Number of corpus entries that are favored.
favored_items: usize,
}
Expand Down
22 changes: 10 additions & 12 deletions crates/evm/evm/src/executors/fuzz/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::executors::{
DURATION_BETWEEN_METRICS_REPORT, Executor, FailFast, FuzzTestTimer, RawCallResult,
shared_corpus::{CorpusWorker, SharedCorpus},
};
use alloy_dyn_abi::JsonAbiExt;
use alloy_json_abi::Function;
Expand Down Expand Up @@ -27,7 +28,6 @@ use serde_json::json;
use std::time::{Instant, SystemTime, UNIX_EPOCH};

mod types;
use crate::executors::corpus::CorpusManager;
pub use types::{CaseOutcome, CounterExampleOutcome, FuzzOutcome};

/// Contains data collected during fuzz test runs.
Expand Down Expand Up @@ -118,13 +118,10 @@ impl FuzzedExecutor {
// We want to collect at least one trace which will be displayed to user.
let max_traces_to_collect = std::cmp::max(1, self.config.gas_report_samples) as usize;

let mut corpus_manager = CorpusManager::new(
self.config.corpus.clone(),
strategy.boxed(),
&self.executor,
Some(func),
None,
)?;
let shared_corpus =
SharedCorpus::new(self.config.corpus.clone(), &self.executor, Some(func), None)?;

let mut corpus_manager = shared_corpus.new_worker(strategy.boxed());

// Start timer for this fuzz test.
let timer = FuzzTestTimer::new(self.config.timeout);
Expand All @@ -144,11 +141,12 @@ impl FuzzedExecutor {
failure.calldata
} else {
// If running with progress, then increment current run.
let metrics_read = shared_corpus.metrics.read();
if let Some(progress) = progress {
progress.inc(1);
// Display metrics in progress bar.
if self.config.corpus.collect_edge_coverage() {
progress.set_message(format!("{}", &corpus_manager.metrics));
progress.set_message(format!("{}", &metrics_read));
}
} else if self.config.corpus.collect_edge_coverage()
&& last_metrics_report.elapsed() > DURATION_BETWEEN_METRICS_REPORT
Expand All @@ -159,7 +157,7 @@ impl FuzzedExecutor {
.duration_since(UNIX_EPOCH)?
.as_secs(),
"test": func.name,
"metrics": &corpus_manager.metrics,
"metrics": &*metrics_read,
});
let _ = sh_println!("{}", serde_json::to_string(&metrics)?);
last_metrics_report = Instant::now();
Expand Down Expand Up @@ -257,7 +255,7 @@ impl FuzzedExecutor {
gas_report_traces: traces.into_iter().map(|a| a.arena).collect(),
line_coverage: test_data.coverage,
deprecated_cheatcodes: test_data.deprecated_cheatcodes,
failed_corpus_replays: corpus_manager.failed_replays(),
failed_corpus_replays: shared_corpus.failed_replays(),
};

match test_data.failure {
Expand Down Expand Up @@ -298,7 +296,7 @@ impl FuzzedExecutor {
&mut self,
address: Address,
calldata: Bytes,
coverage_metrics: &mut CorpusManager,
coverage_metrics: &mut CorpusWorker,
) -> Result<FuzzOutcome, TestCaseError> {
let mut call = self
.executor
Expand Down
1 change: 1 addition & 0 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub mod invariant;
pub use invariant::InvariantExecutor;

mod corpus;
mod shared_corpus;
mod trace;

pub use trace::TracingExecutor;
Expand Down
Loading
Loading