Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fuzzers #564

Merged
merged 7 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
toolchain: stable
targets: wasm32-unknown-unknown

- name: Set up cargo cache
uses: Swatinem/rust-cache@v2

- name: Run cargo check
run: cargo check

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Cargo
# will have compiled files and executables
/target/
**/target/**

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Expand All @@ -21,3 +21,5 @@ proving_system/stark/src/cairo_run/program.trace
**/.DS_Store

ensure-no_std/target
# Files from fuzzers are inside a corpus folder
**/corpus/**
18 changes: 7 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.PHONY: test clippy docker-shell nix-shell benchmarks benchmark docs build-cuda build-metal clippy-metal test-metal coverage clean

FUZZ_DIR = fuzz/no_gpu_fuzz

ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

CAIRO0_PROGRAMS_DIR=provers/cairo/cairo_programs/cairo0
Expand Down Expand Up @@ -76,22 +78,16 @@ build-cuda:
docs:
cd docs && mdbook serve --open

STARK_DESERIALIZE_FUZZER = deserialize_stark_proof
run-fuzzer:
cargo +nightly fuzz run --fuzz-dir $(FUZZ_DIR) $(FUZZER)

proof-deserializer-fuzzer:
cd fuzz/deserialize_stark_proof
cargo +nightly fuzz run --fuzz-dir . $(STARK_DESERIALIZE_FUZZER)
cargo +nightly fuzz run --fuzz-dir $(FUZZ_DIR) deserialize_stark_proof

FUZZER = field_from_hex
run-no-gpu-fuzzer:
cd fuzz/no_gpu_fuzz
cargo +nightly fuzz run --fuzz-dir . $(FUZZER)

METALFUZZER = fft_diff
run-metal-fuzzer:
cd fuzz/metal_fuzz
cargo +nightly fuzz run --fuzz-dir . $(METALFUZZER)
cargo +nightly fuzz run --fuzz-dir $(FUZZ_DIR) fft_diff

CUDAFUZZER = cuda_fft_fuzzer
run-cuda-fuzzer:
cd fuzz/cuda_fuzz
cargo hfuzz run $(CUDAFUZZER)
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ If you use ```Lambdaworks``` libraries in your research projects, please cite th

## Fuzzers

Fuzzers are divided between the ones that use only the CPU, the ones that use Metal, and the ones that use CUDA.

CPU Fuzzers can be run with the command ```bash make run-fuzzer FUZZER=fuzzer_name```

For example:

```bash
make run-fuzzer FUZZER=field_from_hex
```

The list of fuzzers can be found in `fuzz/no_gpu_fuzz`

Fuzzers for FTT in Metal and Cuda can be run with `make run-metal-fuzzer` and `make run-cuda-fuzzer`


Run a specific fuzzer from the ones contained in **fuzz/fuzz_targets/** folder with`cargo`, for example to run the one for the target `field_from_hex`:

```bash
Expand Down
2 changes: 2 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = ["no_gpu_fuzz", "metal_fuzz", "cuda_fuzz"]
resolver = "2"

[workspace.package]
edition = "2021"
Expand All @@ -9,6 +10,7 @@ version = "0.1.1"
[workspace.dependencies]
lambdaworks-math = { path = "../math" }
lambdaworks-gpu = { path = "../gpu" }
stark-platinum-prover = { path = "../provers/stark" }
libfuzzer-sys = "0.4"

[profile.release]
Expand Down
24 changes: 0 additions & 24 deletions fuzz/deserialize_stark_proof/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions fuzz/deserialize_stark_proof/fuzz_targets/deserialize.rs

This file was deleted.

9 changes: 9 additions & 0 deletions fuzz/no_gpu_fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ cargo-fuzz = true
lambdaworks-math = { workspace = true }
lambdaworks-gpu = { workspace = true }
libfuzzer-sys = { workspace = true }
stark-platinum-prover = { workspace = true }

num-traits = "0.2"
ibig = "0.3.6"

Expand All @@ -31,3 +33,10 @@ path = "fuzz_targets/field_from_raw.rs"
test = false
doc = false

[[bin]]
name = "deserialize_stark_proof"
path = "fuzz_targets/deserialize_stark_proof.rs"
test = false
doc = false


12 changes: 12 additions & 0 deletions fuzz/no_gpu_fuzz/fuzz_targets/deserialize_stark_proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use stark_platinum_prover::proof::stark::StarkProof;
use lambdaworks_math::field::fields::fft_friendly::stark_252_prime_field::Stark252PrimeField;
use lambdaworks_math::traits::Deserializable;


fuzz_target!(|data: Vec<u8>| {

let _proof = StarkProof::<Stark252PrimeField>::deserialize(&data);

});
19 changes: 0 additions & 19 deletions fuzzer/Cargo.toml

This file was deleted.

13 changes: 0 additions & 13 deletions fuzzer/README.md

This file was deleted.

53 changes: 0 additions & 53 deletions fuzzer/src/cuda_fft_fuzzer.rs

This file was deleted.