Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 5 additions & 2 deletions evm/src/fuzz/invariant/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,11 @@ impl<'a> InvariantExecutor<'a> {
}

// Stores fuzz state for use with [fuzz_calldata_from_state].
let fuzz_state: EvmFuzzState =
build_initial_state(self.executor.backend().mem_db(), self.config.include_storage);
let fuzz_state: EvmFuzzState = build_initial_state(
self.executor.backend().mem_db(),
self.config.include_storage,
self.config.include_push_bytes,
);

// During execution, any newly created contract is added here and used through the rest of
// the fuzz run.
Expand Down
12 changes: 10 additions & 2 deletions evm/src/fuzz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ impl<'a> FuzzedExecutor<'a> {

// Stores fuzz state for use with [fuzz_calldata_from_state]
let state: EvmFuzzState = if let Some(fork_db) = self.executor.backend().active_fork_db() {
build_initial_state(fork_db, self.config.include_storage)
build_initial_state(
fork_db,
self.config.include_storage,
self.config.include_push_bytes,
)
} else {
build_initial_state(self.executor.backend().mem_db(), self.config.include_storage)
build_initial_state(
self.executor.backend().mem_db(),
self.config.include_storage,
self.config.include_push_bytes,
)
};

let strat = proptest::strategy::Union::new_weighted(vec![
Expand Down
2 changes: 1 addition & 1 deletion evm/src/fuzz/strategies/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mod tests {
let func = HumanReadableParser::parse_function(f).unwrap();

let db = CacheDB::new(EmptyDB());
let state = build_initial_state(&db, true);
let state = build_initial_state(&db, true, true);

let strat = proptest::strategy::Union::new_weighted(vec![
(60, fuzz_calldata(func.clone())),
Expand Down
11 changes: 7 additions & 4 deletions evm/src/fuzz/strategies/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ This is a bug, please open an issue: https://github.com/foundry-rs/foundry/issue
pub fn build_initial_state<DB: DatabaseRef>(
db: &CacheDB<DB>,
include_storage: bool,
include_push_bytes: bool,
) -> EvmFuzzState {
let mut state = FuzzDictionary::default();

Expand All @@ -91,10 +92,12 @@ pub fn build_initial_state<DB: DatabaseRef>(
state.insert(H256::from(*address).into());

// Insert push bytes
if let Some(code) = &account.info.code {
if state.cache.insert(*address) {
for push_byte in collect_push_bytes(code.bytes().clone()) {
state.insert(push_byte);
if include_push_bytes {
if let Some(code) = &account.info.code {
if state.cache.insert(*address) {
for push_byte in collect_push_bytes(code.bytes().clone()) {
state.insert(push_byte);
}
}
}
}
Expand Down