From 0113bf1903c57673c66377cae7e698b9e3b35691 Mon Sep 17 00:00:00 2001 From: arvidn Date: Mon, 13 May 2024 13:17:01 +0200 Subject: [PATCH] keccak fuzzer --- fuzz/Cargo.toml | 6 ++++++ fuzz/fuzz_targets/keccak.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 fuzz/fuzz_targets/keccak.rs 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); +});