Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed Apr 23, 2024
1 parent 9bc5015 commit 995f6db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ Cargo.lock

corpus/
artifacts/

.idea
13 changes: 13 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -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=.`
19 changes: 11 additions & 8 deletions fuzz/felt/fuzz_targets/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

0 comments on commit 995f6db

Please sign in to comment.