diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 897fda2f..4335bc73 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -31,6 +31,20 @@ test = false doc = false bench = false +[[bin]] +name = "keccak_doesnt_panic" +path = "fuzz_targets/keccak/no_panics.rs" +test = false +doc = false +bench = false + +[[bin]] +name = "keccak_memory_safety" +path = "fuzz_targets/keccak/memory_safety.rs" +test = false +doc = false +bench = false + [[bin]] name = "openzeppelin_stylus_utils" path = "fuzz_targets/openzeppelin_stylus_utils.rs" diff --git a/fuzz/fuzz_targets/keccak/memory_safety.rs b/fuzz/fuzz_targets/keccak/memory_safety.rs new file mode 100644 index 00000000..0b72b8a2 --- /dev/null +++ b/fuzz/fuzz_targets/keccak/memory_safety.rs @@ -0,0 +1,24 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; +extern crate openzeppelin_crypto; + +use crate::openzeppelin_crypto::{ + hash::{BuildHasher, Hasher}, + keccak::KeccakBuilder, +}; + +fuzz_target!(|data: &[u8]| { + let mut hasher = KeccakBuilder.build_hasher(); + + // Test memory safety by updating with different slice patterns + for i in 0..data.len() { + hasher.update(&data[..i]); + let mut new_hasher = KeccakBuilder.build_hasher(); + new_hasher.update(&data[i..]); + let _ = new_hasher.finalize(); + } + + // Finalize the original hasher + let _ = hasher.finalize(); +}); diff --git a/fuzz/fuzz_targets/keccak/no_panics.rs b/fuzz/fuzz_targets/keccak/no_panics.rs new file mode 100644 index 00000000..333a6b9f --- /dev/null +++ b/fuzz/fuzz_targets/keccak/no_panics.rs @@ -0,0 +1,15 @@ +#![no_main] +#[macro_use] +extern crate libfuzzer_sys; +extern crate openzeppelin_crypto; + +use crate::openzeppelin_crypto::{ + hash::{BuildHasher, Hasher}, + keccak::KeccakBuilder, +}; + +fuzz_target!(|data: &[u8]| { + let mut hasher = KeccakBuilder.build_hasher(); + hasher.update(data); + _ = hasher.finalize(); +});