Skip to content

Commit

Permalink
Fuzz cairo compiled programs (#1236)
Browse files Browse the repository at this point in the history
* Create fuzzer

* Remove cli

* Update fuzzer

* Change fuzzer name

* Move functions to utils; Create new fuzzer

* Remove file and update readme

* Change filename

* Fix filenames

* delete extra changes

* Move to fuzzing dir

* update and refactor cairo compiled programs fuzzer

* fmt

* add cairo_programs folder

* fix warnings

* fix formatting

* add felt arbitrary

* add felt arbitrary

* add info to readme

* add fuzzer makefile command

* fix corrections

---------

Co-authored-by: Juanma <juanma@Juanmas-MacBook-Air.local>
Co-authored-by: dafifynn <slimbieber@gmail.com>
Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
  • Loading branch information
4 people authored Jul 26, 2023
1 parent b232d69 commit c73b728
Show file tree
Hide file tree
Showing 5 changed files with 559 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,10 @@ clean:
rm -rf cairo-vm-env
rm -rf cairo-vm-pypy-env
rm -rf cairo

fuzzer-deps:
cargo +nightly install cargo-fuzz

run-cairo-compiled-fuzzer:
cd fuzzer
cargo +nightly fuzz run --fuzz-dir . cairo_compiled_programs_fuzzer
11 changes: 11 additions & 0 deletions fuzzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[package.metadata]
cargo-fuzz = true

[workspace]
members = ["."]

[dependencies]
arbitrary = { version = "1.3.0", features = ["derive"] }
honggfuzz = "0.5.55"
libfuzzer-sys = "0.4"
bincode = { version = "2.0.0-rc.3", tag = "v2.0.0-rc.3", git = "https://github.com/bincode-org/bincode.git" }
cairo-vm = { path = "../vm", features = ["arbitrary"] }
mimalloc = { version = "0.1.29", default-features = false, optional = true }
nom = "7"
thiserror = { version = "1.0.32" }
cairo-felt = { path = "../felt", features = ["arbitrary"] }
proptest = "1.2.0"

[dev-dependencies]
assert_matches = "1.5.0"
rstest = "0.17.0"


[features]
default = ["with_mimalloc"]
with_mimalloc = ["cairo-vm/with_mimalloc", "mimalloc"]
Expand All @@ -29,6 +36,10 @@ with_mimalloc = ["cairo-vm/with_mimalloc", "mimalloc"]
name = "fuzz_json"
path = "src/fuzz_json.rs"

[[bin]]
name = "cairo_compiled_programs_fuzzer"
path = "src/cairo_compiled_programs_fuzzer.rs"

[[bin]]
name = "fuzz_program"
path = "src/fuzz_program.rs"
9 changes: 9 additions & 0 deletions fuzzer/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## fuzz_json
This fuzzer creates a json file directly from bytes.
`HFUZZ_RUN_ARGS="--dict=json.dict" cargo hfuzz run fuzz_json`

## cairo_compiled_programs_fuzzer
To run this fuzzer you need to be able to run cairo-compile command from the fuzzer folder beforehand.

To run the fuzzer you need to have installed `cargo-fuzz`. If not, use the command `cargo +nightly install cargo-fuzz`

To run simply use `cargo +nightly fuzz run --fuzz-dir . cairo_compiled_programs_fuzzer`

We use nightly for this fuzzer because cargo fuzz runs with the -Z flag, which only works with +nightly.
Empty file added fuzzer/cairo_programs/.gitkeep
Empty file.
Loading

1 comment on commit c73b728

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: c73b728 Previous: b232d69 Ratio
add_u64_with_felt/1 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50
add_u64_with_felt/2 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50
add_u64_with_felt/3 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/4 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/5 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/6 4 ns/iter (± 0) 2 ns/iter (± 0) 2
add_u64_with_felt/7 4 ns/iter (± 0) 2 ns/iter (± 0) 2
add_u64_with_felt/8 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.