From 995f6dbae7c843170ac446c43583263e32a7e882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kami=C5=84ski=20=40=20StarkWare?= Date: Tue, 23 Apr 2024 14:59:05 +0200 Subject: [PATCH] add readme --- .gitignore | 2 ++ fuzz/README.md | 13 +++++++++++++ fuzz/felt/fuzz_targets/add.rs | 19 +++++++++++-------- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 fuzz/README.md diff --git a/.gitignore b/.gitignore index 55e6876..01d3bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ Cargo.lock corpus/ artifacts/ + +.idea \ No newline at end of file diff --git a/fuzz/README.md b/fuzz/README.md new file mode 100644 index 0000000..635a3d1 --- /dev/null +++ b/fuzz/README.md @@ -0,0 +1,13 @@ +# Fuzzing + +This directory contains the fuzzing infrastructure for the `types-rs` project. + +## Setup +``` +cargo install cargo-fuzz +``` + +## Running the fuzzers +* cd into one of the directories, e.g., `cd felt` +* list the available fuzz targets, e.g., `cargo fuzz list --fuzz-dir=.` +* run the fuzzer, e.g., `cargo +nightly fuzz run add_fuzzer --fuzz-dir=.` \ No newline at end of file diff --git a/fuzz/felt/fuzz_targets/add.rs b/fuzz/felt/fuzz_targets/add.rs index 25bd84b..88391a6 100644 --- a/fuzz/felt/fuzz_targets/add.rs +++ b/fuzz/felt/fuzz_targets/add.rs @@ -4,19 +4,22 @@ use starknet_types_core::felt::Felt; fuzz_target!(|data: (Felt, Felt)| { let zero = Felt::ZERO; + let (a, b) = data; // Check a + 0 = a - assert_eq!(data.0 + zero, data.0, "Zero addition failed"); - assert_eq!(data.1 + zero, data.1, "Zero addition failed"); + assert_eq!(a + zero, a, "Zero addition failed"); + assert_eq!(b + zero, b, "Zero addition failed"); // Check a + (-a) = 0 - assert_eq!(data.0 + (-data.0), zero, "Unary addition failed"); - assert_eq!(data.1 + (-data.1), zero, "Unary addition failed"); + assert_eq!(a + (-a), zero, "Unary addition failed"); + assert_eq!(b + (-b), zero, "Unary addition failed"); // Check a + b = a - (-b) - assert_eq!(data.0 + data.1, data.0 - (-data.1), "addition failed"); + assert_eq!(a + b, a - (-b), "addition failed"); + // Check a + a = a - (-a) - assert_eq!(data.0 + data.0, data.0 - (-data.0), "addition failed"); - assert_eq!(data.1 + data.1, data.1 - (-data.1), "addition failed"); + assert_eq!(a + a, a - (-a), "addition failed"); + assert_eq!(b + b, b - (-b), "addition failed"); + // Check a + a = 2 * a - assert_eq!(data.0 + data.0, Felt::TWO * data.0, "Doubling failed"); + assert_eq!(a + a, Felt::TWO * a, "Doubling failed"); });