diff --git a/.gitignore b/.gitignore index e33ef72..024f0b4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ Cargo.lock corpus/ artifacts/ +.idea *.DS_Store 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"); });