-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fuzzing): fuzzing for felt addition
- Loading branch information
Showing
6 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,7 @@ Cargo.lock | |
# Added by cargo | ||
|
||
/target | ||
.DS_Store | ||
|
||
corpus/ | ||
artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[workspace] | ||
members = ["felt"] | ||
|
||
resolver = "2" | ||
|
||
[workspace.package] | ||
authors = [ | ||
"Lucas Levy <@LucasLvy>", | ||
] | ||
edition = "2021" | ||
repository = "https://github.com/starknet-io/types-rs" | ||
|
||
[workspace.dependencies] | ||
starknet-types-core = { path = "../crates/starknet-types-core", default-features = false, features = ["arbitrary"] } | ||
libfuzzer-sys = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "fuzzing_felt" | ||
version = "0.0.1" | ||
edition = "2021" | ||
license = "MIT" | ||
homepage = "https://github.com/starknet-io/types-rs" | ||
repository = "https://github.com/starknet-io/types-rs" | ||
categories = ["types", "math", "crypto", "fuzzing"] | ||
keywords = ["stark", "zkp", "cairo", "fuzzing"] | ||
description = "Fuzzing crate for the starknet common felt type" | ||
readme = "README.md" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
starknet-types-core.workspace = true | ||
libfuzzer-sys.workspace = true | ||
|
||
[[bin]] | ||
name = "add_fuzzer" | ||
path = "fuzz_targets/add.rs" | ||
test = false | ||
doc = false | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
use starknet_types_core::felt::Felt; | ||
|
||
fuzz_target!(|data: (Felt, Felt)| { | ||
let zero = Felt::ZERO; | ||
// Check a + 0 = a | ||
assert_eq!(data.0 + zero, data.0, "Zero addition failed"); | ||
assert_eq!(data.1 + zero, data.1, "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"); | ||
|
||
// Check a + b = a - (-b) | ||
assert_eq!(data.0 + data.1, data.0 - (-data.1), "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"); | ||
// Check a + a = 2 * a | ||
assert_eq!(data.0 + data.0, Felt::TWO * data.0, "Doubling failed"); | ||
}); |