-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Separate into workspaces * Remove unused name * Run cargo fix * Update readme * update makefile command for fuzzers * delete command for cuda fuzzer * Cuda fft fuzzer (#502) * add cuda fft fuzzer * add cuda fft fuzzer in honggfuzz * add power of two check --------- Co-authored-by: dafifynn <[email protected]> --------- Co-authored-by: Juanma <[email protected]> Co-authored-by: dafifynn <[email protected]> Co-authored-by: Mauro Toscano <[email protected]> Co-authored-by: daphneherlambda <[email protected]>
- Loading branch information
1 parent
6ad2e46
commit 96bb966
Showing
14 changed files
with
181 additions
and
63 deletions.
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
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 |
---|---|---|
@@ -1,58 +1,16 @@ | ||
[package] | ||
name = "fuzz" | ||
[workspace] | ||
members = ["no_gpu_fuzz", "metal_fuzz", "cuda_fuzz"] | ||
|
||
[workspace.package] | ||
edition = "2021" | ||
publish = false | ||
version = "0.1.1" | ||
edition = "2021" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
[workspace.dependencies] | ||
lambdaworks-math = { path = "../math" } | ||
lambdaworks-gpu = { path = "../gpu" } | ||
libfuzzer-sys = "0.4" | ||
lambdaworks-math = { path = "../math", features = ["metal"] } | ||
lambdaworks-gpu = { path = "../gpu", features = ["metal"] } | ||
num-traits = "0.2" | ||
ibig = "0.3.6" | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[profile.release] | ||
debug = 1 | ||
|
||
[[bin]] | ||
name = "field_fuzzer" | ||
path = "fuzz_targets/field_fuzzer.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "field_from_hex" | ||
path = "fuzz_targets/field_from_hex.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "field_from_raw" | ||
path = "fuzz_targets/field_from_raw.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "metal_fft_diff" | ||
path = "fuzz_targets/metal_fft_diff.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "polynomial_fft_diff_fuzzer" | ||
path = "fuzz_targets/polynomial_fft_diff_fuzzer.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "twiddles_generation" | ||
path = "fuzz_targets/twiddles_generation.rs" | ||
test = false | ||
doc = false |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# Fuzzing | ||
There are three types of fuzzers distributed on different workspaces depending on the features (metal/cuda) they need. So you should make sure you cded into the right folder before running any of the commands. | ||
|
||
### Running the fuzzers | ||
`cargo +nightly fuzz run <target_name>` | ||
`cargo +nightly fuzz run --fuzz-dir . <target_name>` | ||
The targets can be found in the `fuzz_targets` directory. Normally the name of the file without the extension should work, if it doesn't, look up the name for that binary target in `Cargo.toml`. | ||
|
||
### Debugging | ||
If a crash is found, an `artifacts/<target_name>` folder will be added, inside it you'll find the different reports. To get an lldb dump, run | ||
`cargo +nightly fuzz run <target_name> artifacts/crash-xxx` | ||
`cargo +nightly fuzz run --fuzz-dir . <target_name> artifacts/crash-xxx` |
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,31 @@ | ||
[package] | ||
name = "metal_fuzz" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
lambdaworks-math = { workspace = true, features = ["metal"] } | ||
lambdaworks-gpu = { workspace = true, features = ["metal"] } | ||
libfuzzer-sys = { workspace = true } | ||
|
||
[[bin]] | ||
name = "fft_diff" | ||
path = "fuzz_targets/fft_diff.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "polynomial_fft_diff" | ||
path = "fuzz_targets/polynomial_fft_diff.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "twiddles_generation_diff" | ||
path = "fuzz_targets/twiddles_generation_diff.rs" | ||
test = false | ||
doc = false | ||
|
File renamed without changes.
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
File renamed without changes.
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,33 @@ | ||
[package] | ||
name = "no_gpu_fuzz" | ||
version.workspace = true | ||
edition.workspace = true | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
lambdaworks-math = { workspace = true } | ||
lambdaworks-gpu = { workspace = true } | ||
libfuzzer-sys = { workspace = true } | ||
num-traits = "0.2" | ||
ibig = "0.3.6" | ||
|
||
[[bin]] | ||
name = "field_fuzzer" | ||
path = "fuzz_targets/field_fuzzer.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "field_from_hex" | ||
path = "fuzz_targets/field_from_hex.rs" | ||
test = false | ||
doc = false | ||
|
||
[[bin]] | ||
name = "field_from_raw" | ||
path = "fuzz_targets/field_from_raw.rs" | ||
test = false | ||
doc = false | ||
|
File renamed without changes.
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
File renamed without changes.
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,19 @@ | ||
[package] | ||
name = "fuzzer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
honggfuzz = "0.5.51" | ||
lambdaworks-math = { path = "../math", features = ["cuda"] } | ||
lambdaworks-gpu = { path = "../gpu", features = ["cuda"] } | ||
|
||
|
||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "cuda_fft_fuzzer" | ||
path = "src/cuda_fft_fuzzer.rs" |
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,13 @@ | ||
## Setup | ||
Run the following commands to get ready the setup. | ||
|
||
* `cargo install honggfuzz ` | ||
* `apt install build-essential` | ||
* `apt-get install binutils-dev` | ||
* `sudo apt-get install libunwind-dev` | ||
* `sudo apt-get install lldb` | ||
|
||
## Run the fuzzer | ||
|
||
Run the following command to run the specific fuzzer | ||
`cargo hfuzz run <name of the fuzz target> ` |
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,53 @@ | ||
#[macro_use] | ||
extern crate honggfuzz; | ||
use lambdaworks_math::{ | ||
fft::{ | ||
gpu::cuda::{ops::fft as fft_cuda, state::CudaState}, | ||
cpu::{ | ||
roots_of_unity::get_twiddles, | ||
ops::fft as fft_cpu | ||
} | ||
}, | ||
field::{ | ||
traits::RootsConfig, | ||
fields::fft_friendly::stark_252_prime_field::Stark252PrimeField, | ||
element::FieldElement | ||
}, | ||
}; | ||
|
||
fn main() { | ||
loop { | ||
fuzz!(|data: Vec<u64>| { | ||
let mut input_raw = data; | ||
let mut inputs = Vec::new(); | ||
|
||
if input_raw.len() == 0 { | ||
input_raw.push(0u64); | ||
} | ||
|
||
while !input_raw.len().is_power_of_two(){ | ||
input_raw.push(input_raw[0]); | ||
} | ||
|
||
for i in 0..input_raw.len() { | ||
let input_value = format!("{:x}", input_raw[i]); | ||
inputs.push(FieldElement::<Stark252PrimeField>::from_hex_unchecked(&input_value)) | ||
} | ||
|
||
let twiddles = get_twiddles( | ||
inputs.len().trailing_zeros() as u64, | ||
RootsConfig::BitReverse, | ||
) | ||
.unwrap(); | ||
|
||
let state = CudaState::new().unwrap(); | ||
println!("inputs {:?}", &inputs); | ||
println!("fft cpu{:?}", fft_cpu(&inputs, &twiddles)); | ||
|
||
match fft_cpu(&inputs, &twiddles) { | ||
Ok(fft_result) => assert_eq!(fft_result, fft_cuda(&inputs, &twiddles, &state).unwrap()), | ||
Err(_) => assert!(fft_cuda(&inputs, &twiddles, &state).is_err()) | ||
} | ||
}); | ||
} | ||
} |