From 4a7deff514b3e5811c0391509a8acbd12ad74b69 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 c5e16752..d989f47b 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -80,3 +80,9 @@ name = "base64" path = "fuzz_targets/base64.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); +});