-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
361 additions
and
124 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
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,35 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use kzg::eip_4844::{bytes_to_blob, compute_cells_and_kzg_proofs_rust}; | ||
use kzg_bench::tests::eip_7594::test_vectors_compute_cells_and_kzg_proofs; | ||
use rust_kzg_blst::{ | ||
eip_4844::load_trusted_setup, | ||
types::{ | ||
fft_settings::FsFFTSettings, | ||
fp::FsFp, | ||
fr::FsFr, | ||
g1::{FsG1, FsG1Affine}, | ||
g2::FsG2, | ||
kzg_settings::FsKZGSettings, | ||
poly::FsPoly, | ||
}, | ||
}; | ||
|
||
#[test] | ||
pub fn bytes_to_bls_field_test_() { | ||
test_vectors_compute_cells_and_kzg_proofs::< | ||
FsFr, | ||
FsG1, | ||
FsG2, | ||
FsPoly, | ||
FsFFTSettings, | ||
FsKZGSettings, | ||
FsFp, | ||
FsG1Affine, | ||
>( | ||
&load_trusted_setup, | ||
&compute_cells_and_kzg_proofs_rust, | ||
&bytes_to_blob, | ||
); | ||
} | ||
} |
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
28 changes: 15 additions & 13 deletions
28
kzg-bench/src/test_vectors/compute_cells_and_kzg_proofs.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
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,7 +1,9 @@ | ||
pub mod blob_to_kzg_commitment; | ||
pub mod compute_blob_kzg_proof; | ||
pub mod compute_cells_and_kzg_proofs; | ||
pub mod compute_kzg_proof; | ||
pub mod recover_cells_and_kzg_proofs; | ||
pub mod verify_blob_kzg_proof; | ||
pub mod verify_blob_kzg_proof_batch; | ||
pub mod verify_cell_kzg_proof_batch; | ||
pub mod verify_kzg_proof; | ||
pub mod compute_cells_and_kzg_proofs; |
49 changes: 49 additions & 0 deletions
49
kzg-bench/src/test_vectors/recover_cells_and_kzg_proofs.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,49 @@ | ||
#![allow(dead_code)] | ||
|
||
use crate::Bytes48; | ||
use crate::{Cell, Error}; | ||
use alloc::string::String; | ||
use alloc::vec::Vec; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Input { | ||
cell_indices: Vec<u64>, | ||
cells: Vec<String>, | ||
} | ||
|
||
impl Input { | ||
pub fn get_cell_indices(&self) -> Result<Vec<u64>, Error> { | ||
Ok(self.cell_indices.clone()) | ||
} | ||
|
||
pub fn get_cells(&self) -> Result<Vec<Cell>, Error> { | ||
self.cells | ||
.iter() | ||
.map(|s| Cell::from_hex(s)) | ||
.collect::<Result<Vec<Cell>, Error>>() | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct Test { | ||
pub input: Input, | ||
output: Option<(Vec<String>, Vec<String>)>, | ||
} | ||
|
||
impl Test { | ||
pub fn get_output(&self) -> Option<(Vec<Cell>, Vec<Bytes48>)> { | ||
self.output.clone().map(|(cells, proofs)| { | ||
( | ||
cells | ||
.iter() | ||
.map(|s| Cell::from_hex(s).unwrap()) | ||
.collect::<Vec<Cell>>(), | ||
proofs | ||
.iter() | ||
.map(|s| Bytes48::from_hex(s).unwrap()) | ||
.collect::<Vec<Bytes48>>(), | ||
) | ||
}) | ||
} | ||
} |
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 @@ | ||
#![allow(dead_code)] | ||
|
||
use crate::{Bytes48, Cell, Error}; | ||
use alloc::string::String; | ||
use alloc::vec::Vec; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct Input { | ||
commitments: Vec<String>, | ||
cell_indices: Vec<u64>, | ||
cells: Vec<String>, | ||
proofs: Vec<String>, | ||
} | ||
|
||
impl Input { | ||
pub fn get_commitments(&self) -> Result<Vec<Bytes48>, Error> { | ||
self.commitments | ||
.iter() | ||
.map(|s| Bytes48::from_hex(s)) | ||
.collect::<Result<Vec<Bytes48>, Error>>() | ||
} | ||
|
||
pub fn get_cell_indices(&self) -> Result<Vec<u64>, Error> { | ||
Ok(self.cell_indices.clone()) | ||
} | ||
|
||
pub fn get_cells(&self) -> Result<Vec<Cell>, Error> { | ||
self.cells | ||
.iter() | ||
.map(|s| Cell::from_hex(s)) | ||
.collect::<Result<Vec<Cell>, Error>>() | ||
} | ||
|
||
pub fn get_proofs(&self) -> Result<Vec<Bytes48>, Error> { | ||
self.proofs | ||
.iter() | ||
.map(|s| Bytes48::from_hex(s)) | ||
.collect::<Result<Vec<Bytes48>, Error>>() | ||
} | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct Test { | ||
pub input: Input, | ||
output: Option<bool>, | ||
} | ||
|
||
impl Test { | ||
pub fn get_output(&self) -> Option<bool> { | ||
self.output | ||
} | ||
} |
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,72 @@ | ||
use super::utils::{get_manifest_dir, get_trusted_setup_path}; | ||
use crate::test_vectors::compute_cells_and_kzg_proofs; | ||
use kzg::{FFTSettings, Fr, G1Affine, G1Fp, G1GetFp, G1Mul, KZGSettings, Poly, G1, G2}; | ||
use std::path::PathBuf; | ||
|
||
const COMPUTE_CELLS_AND_KZG_PROOFS_TEST_VECTORS: &str = | ||
"src/test_vectors/compute_cells_and_kzg_proofs/*/*/*"; | ||
const RECOVER_CELLS_AND_KZG_PROOFS_TEST_VECTORS: &str = | ||
"src/test_vectors/recover_cells_and_kzg_proofs/*/*/*"; | ||
const VERIFY_CELL_KZG_PROOF_BATCH_TEST_VECTORS: &str = | ||
"src/test_vectors/verify_cell_kzg_proof_batch/*/*/*"; | ||
|
||
pub fn test_vectors_compute_cells_and_kzg_proofs< | ||
TFr: Fr, | ||
TG1: G1 + G1Mul<TFr> + G1GetFp<TG1Fp>, | ||
TG2: G2, | ||
TPoly: Poly<TFr>, | ||
TFFTSettings: FFTSettings<TFr>, | ||
TKZGSettings: KZGSettings<TFr, TG1, TG2, TFFTSettings, TPoly, TG1Fp, TG1Affine>, | ||
TG1Fp: G1Fp, | ||
TG1Affine: G1Affine<TG1, TG1Fp>, | ||
>( | ||
load_trusted_setup: &dyn Fn(&str) -> Result<TKZGSettings, String>, | ||
compute_cells_and_kzg_proofs: &dyn Fn( | ||
&[TFr], | ||
&TKZGSettings, | ||
) -> Result<(Vec<TFr>, Vec<TG1>), String>, | ||
bytes_to_blob: &dyn Fn(&[u8]) -> Result<Vec<TFr>, String>, | ||
) { | ||
let settings = load_trusted_setup(get_trusted_setup_path().as_str()).unwrap(); | ||
let test_files: Vec<PathBuf> = glob::glob(&format!( | ||
"{}/{}", | ||
get_manifest_dir(), | ||
COMPUTE_CELLS_AND_KZG_PROOFS_TEST_VECTORS | ||
)) | ||
.unwrap() | ||
.collect::<Vec<Result<_>>>() | ||
.unwrap(); | ||
assert!(!test_files.is_empty()); | ||
|
||
for test_file in test_files { | ||
let yaml_data = fs::read_to_string(test_file).unwrap(); | ||
let test: compute_cells_and_kzg_proofs::Test = serde_yaml::from_str(&yaml_data).unwrap(); | ||
|
||
let blob = match bytes_to_blob(&test.input.get_blob_bytes()) { | ||
Ok(blob) => blob, | ||
Err(_) => { | ||
assert!(test.get_output().is_none()); | ||
continue; | ||
} | ||
}; | ||
|
||
match compute_cells_and_kzg_proofs(&blob, &settings) { | ||
Err(_) => assert!(test.get_output().is_none()), | ||
Ok((recv_cells, recv_proofs)) => { | ||
let (exp_cells, exp_proofs) = test.get_output().unwrap(); | ||
|
||
let recv_cells = recv_cells | ||
.into_iter() | ||
.map(|it| it.to_bytes().to_vec()) | ||
.collect::<Vec<Vec<u8>>>(); | ||
let recv_proofs = recv_proofs | ||
.into_iter() | ||
.map(|it| it.to_bytes().to_vec()) | ||
.collect::<Vec<Vec<u8>>>(); | ||
|
||
assert_eq!(recv_cells, exp_cells, "Cells do not match"); | ||
assert_eq!(recv_proofs, exp_proofs, "Proofs do not match"); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.