diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 5eca6b99..eb42c5cf 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -74,3 +74,9 @@ name = "allocator" path = "fuzz_targets/allocator.rs" test = false doc = false + +[[bin]] +name = "keccak" +path = "fuzz_targets/keccak.rs" +test = false +doc = false diff --git a/fuzz/fuzz_targets/keccak.rs b/fuzz/fuzz_targets/keccak.rs new file mode 100644 index 00000000..9094bba7 --- /dev/null +++ b/fuzz/fuzz_targets/keccak.rs @@ -0,0 +1,16 @@ +#![no_main] +use clvmr::keccak256_ops::op_keccak256; +use clvmr::{reduction::Reduction, Allocator, NodePtr}; +use libfuzzer_sys::fuzz_target; + +fuzz_target!(|data: &[u8]| { + let mut a = Allocator::new(); + let blob = a.new_atom(data).expect("failed to create atom"); + let args = a + .new_pair(blob, NodePtr::NIL) + .expect("failed to create pair"); + let Reduction(cost, node) = op_keccak256(&mut a, args, 11000000000).expect("keccak256 failed"); + assert!(cost >= 210); + assert!(node.is_atom()); + assert_eq!(a.atom_len(node), 32); +});