Skip to content

Commit

Permalink
reuse input bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Jan 6, 2024
1 parent bc64c3e commit 069e973
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ async fn fuzz_task(pb: ProgressBar, num_hashes: u64, max_input_bytes: usize) ->
// Init thread RNG
let mut rng = rand::thread_rng();

// Re-use the same memory for the tiny-keccak hash outputs.
// Re-use the same memory for the input slice and tiny-keccak hash outputs.
let mut hash_tiny: [u8; 32] = [0u8; 32];
let mut bytes = vec![0u8; max_input_bytes];

for i in 0..num_hashes {
let mut bytes = vec![0u8; rng.gen_range(0..max_input_bytes)];
rng.fill(bytes.as_mut_slice());
let in_slice = bytes[0..rng.gen_range(0..max_input_bytes)].as_mut();
rng.fill(in_slice);

hash_input_tiny(bytes.as_slice(), hash_tiny.as_mut());
let hash_evm = hash_input_evm(&mut evm, bytes.as_slice())?;
hash_input_tiny(in_slice, hash_tiny.as_mut());
let hash_evm = hash_input_evm(&mut evm, in_slice)?;

if hash_tiny != hash_evm {
bail!(
Expand Down

0 comments on commit 069e973

Please sign in to comment.