-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from jtraglia/update-fuzzer
Add `compute_cells` fuzzing support
- Loading branch information
Showing
5 changed files
with
112 additions
and
60 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,46 @@ | ||
// Run with the following command: | ||
// cargo fuzz run fuzz_compute_cells_and_kzg_proofs | ||
|
||
#![no_main] | ||
extern crate core; | ||
|
||
use c_kzg::Blob; | ||
use c_kzg::KzgSettings; | ||
use lazy_static::lazy_static; | ||
use libfuzzer_sys::fuzz_target; | ||
use rust_eth_kzg::DASContext; | ||
use std::path::PathBuf; | ||
|
||
lazy_static! { | ||
static ref KZG_SETTINGS: KzgSettings = { | ||
let root_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
let trusted_setup_file = root_dir.join("..").join("src").join("trusted_setup.txt"); | ||
KzgSettings::load_trusted_setup_file(&trusted_setup_file, 8).unwrap() | ||
}; | ||
static ref DAS_CONTEXT: DASContext = DASContext::default(); | ||
} | ||
|
||
fuzz_target!(|blob: Blob| { | ||
let ckzg_result = KZG_SETTINGS.compute_cells(&blob); | ||
let rkzg_result = DAS_CONTEXT.compute_cells(&blob.into_inner()); | ||
|
||
match (&ckzg_result, &rkzg_result) { | ||
(Ok(ckzg_cells), Ok(rkzg_cells)) => { | ||
// Ensure the results are the same. | ||
for (ckzg_cell, rkzg_cell) in ckzg_cells.iter().zip(rkzg_cells.iter()) { | ||
assert_eq!(ckzg_cell.to_bytes().as_slice(), rkzg_cell.as_slice()) | ||
} | ||
} | ||
(Err(_), Err(_)) => { | ||
// Cannot compare errors, they are unique. | ||
} | ||
_ => { | ||
// There is a disagreement. | ||
panic!( | ||
"mismatch {:?} and {:?}", | ||
&ckzg_result.is_ok(), | ||
&rkzg_result.is_ok() | ||
); | ||
} | ||
} | ||
}); |
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