Skip to content

Commit

Permalink
chore: reduce unnecessary collected fuzz state (#7305)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 4, 2024
1 parent c24933d commit d176715
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/evm/fuzz/src/strategies/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use revm::{
interpreter::opcode::{self, spec_opcode_gas},
primitives::SpecId,
};
use std::{fmt, io::Write, str::FromStr, sync::Arc};
use std::{fmt, str::FromStr, sync::Arc};

/// A set of arbitrary 32 byte data from the VM used to generate values for the strategy.
///
Expand Down Expand Up @@ -185,19 +185,20 @@ pub fn collect_state_from_call(
} else {
return;
}
}

// Insert log topics and data
for log in logs {
log.data.topics().iter().for_each(|topic| {
state.values_mut().insert(topic.0);
});
log.data.data.chunks(32).for_each(|chunk| {
let mut buffer: [u8; 32] = [0; 32];
let _ = (&mut buffer[..])
.write(chunk)
.expect("log data chunk was larger than 32 bytes");
state.values_mut().insert(buffer);
});
// Insert log topics and data.
for log in logs {
for topic in log.topics() {
state.values_mut().insert(topic.0);
}
let chunks = log.data.data.chunks_exact(32);
let rem = chunks.remainder();
for chunk in chunks {
state.values_mut().insert(chunk.try_into().unwrap());
}
if !rem.is_empty() {
state.values_mut().insert(B256::right_padding_from(rem).0);
}
}
}
Expand Down

0 comments on commit d176715

Please sign in to comment.