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

Add fuzz tests for recursion #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions near/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
members = [
"block_finality",
"crypto/plonky2_ed25519",
"crypto/plonky2_sha512",
"block_finality",
"crypto/plonky2_sha256_u32",
"crypto/plonky2_bn128"
, "xtask"]
"crypto/plonky2_bn128",
"xtask"]

[workspace.package]
authors = [ "Zpoken" ]
Expand Down
4 changes: 4 additions & 0 deletions near/block_finality/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
31 changes: 31 additions & 0 deletions near/block_finality/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "block_finality-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
# mb change to workspace dependencies
plonky2 = { git = "https://github.com/wormhole-foundation/plonky2-near", rev = "2244a9d802aa74f15c32ca7f4139959c61126819", features = ["parallel"] }

[dependencies.block_finality]
path = ".."

[workspace]
members = ["."]

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

[[bin]]
name = "recursive_proofs"
path = "fuzz_targets/recursion/recursive_proofs.rs"
test = false
doc = false
19 changes: 19 additions & 0 deletions near/block_finality/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Install fuzz
```
rustup install nightly
```
```
cargo +nightly --version
```
```
cargo install cargo-fuzz
```
### Show fuzz targets
```
cargo fuzz list
```
### Run targets
Useful for all targets, except tests for ed25519, that should be called with flags.
```
cargo +nightly fuzz run fuzz_target_name
```
28 changes: 28 additions & 0 deletions near/block_finality/fuzz/fuzz_targets/recursion/recursive_proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_main]

use block_finality::{prove_primitives::prove_eq_array, recursion::recursive_proof};
use libfuzzer_sys::fuzz_target;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

fuzz_target!(|data: &[u8]| {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;

let (data, proof) = prove_eq_array::<F, C, D>(data, data).expect("Error generating proof.");
assert!(
data.verify(proof.clone()).is_ok(),
"Proof verification failed."
);

let (rec_data, rec_proof) = recursive_proof::<F, C, C, D>(
(&data.common, &data.verifier_only, &proof),
None,
Some(&proof.public_inputs),
)
.expect("Error generating proof.");
assert!(
rec_data.verify(rec_proof).is_ok(),
"Proof verification failed."
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![no_main]

use block_finality::{prove_primitives::prove_eq_array, recursion::recursive_proofs};
use libfuzzer_sys::fuzz_target;
use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig};

fuzz_target!(|data: &[u8]| {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;

let data_proof1 = prove_eq_array::<F, C, D>(data, data).expect("Error generating proof.");
assert!(
data_proof1.0.verify(data_proof1.1.clone()).is_ok(),
"Proof verification failed."
);

let data_proof2 = prove_eq_array::<F, C, D>(data, data).expect("Error generating proof.");
assert!(
data_proof2.0.verify(data_proof2.1.clone()).is_ok(),
"Proof verification failed."
);

let data_proofs = vec![data_proof1, data_proof2];

let (rec_data, rec_proof) =
recursive_proofs::<F, C, D>(&data_proofs, None).expect("Error generating proof.");
assert!(
rec_data.verify(rec_proof).is_ok(),
"Proof verification failed."
);
});
Loading