Skip to content

Commit 33acf8a

Browse files
authored
feat(forge): improve fuzz corpus (#5246)
* insert values +/- 1 to dict * clippy
1 parent 1db257c commit 33acf8a

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

evm/src/fuzz/strategies/state.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ pub fn build_initial_state<DB: DatabaseRef>(
114114
let value = (*value).into();
115115
state.values_mut().insert(utils::u256_to_h256_be(slot).into());
116116
state.values_mut().insert(utils::u256_to_h256_be(value).into());
117+
// also add the value below and above the storage value to the dictionary.
118+
if value != U256::zero() {
119+
let below_value = value - U256::one();
120+
state.values_mut().insert(utils::u256_to_h256_be(below_value).into());
121+
}
122+
if value != U256::max_value() {
123+
let above_value = value + U256::one();
124+
state.values_mut().insert(utils::u256_to_h256_be(above_value).into());
125+
}
117126
}
118127
}
119128
}
@@ -161,6 +170,15 @@ pub fn collect_state_from_call(
161170
let value = ru256_to_u256(value.present_value());
162171
state.values_mut().insert(utils::u256_to_h256_be(slot).into());
163172
state.values_mut().insert(utils::u256_to_h256_be(value).into());
173+
// also add the value below and above the storage value to the dictionary.
174+
if value != U256::zero() {
175+
let below_value = value - U256::one();
176+
state.values_mut().insert(utils::u256_to_h256_be(below_value).into());
177+
}
178+
if value != U256::max_value() {
179+
let above_value = value + U256::one();
180+
state.values_mut().insert(utils::u256_to_h256_be(above_value).into());
181+
}
164182
}
165183
} else {
166184
return
@@ -210,7 +228,15 @@ fn collect_push_bytes(code: Bytes) -> Vec<[u8; 32]> {
210228
return bytes
211229
}
212230

213-
bytes.push(U256::from_big_endian(&code[push_start..push_end]).into());
231+
let push_value = U256::from_big_endian(&code[push_start..push_end]);
232+
bytes.push(push_value.into());
233+
// also add the value below and above the push value to the dictionary.
234+
if push_value != U256::zero() {
235+
bytes.push((push_value - U256::one()).into());
236+
}
237+
if push_value != U256::max_value() {
238+
bytes.push((push_value + U256::one()).into());
239+
}
214240

215241
i += push_size;
216242
}

0 commit comments

Comments
 (0)