From 211bb65d75cfdfd5fcb3bfde0aeaa1af17a66e7d Mon Sep 17 00:00:00 2001 From: sirse Date: Sat, 7 Oct 2023 17:50:50 +0300 Subject: [PATCH] Moved tests to kzg-bench --- blst/src/eip_4844.rs | 2 +- blst/tests/c_bindings.rs | 39 +++ blst/tests/eip_4844.rs | 223 +-------------- kzg-bench/src/tests/c_bindings.rs | 265 ++++++++++++++++++ kzg-bench/src/tests/eip_4844.rs | 17 +- .../tests/fixtures/trusted_setup_4_old.txt | 0 .../src}/tests/fixtures/trusted_setup_old.txt | 0 kzg-bench/src/tests/mod.rs | 2 + kzg-bench/src/tests/utils.rs | 20 ++ 9 files changed, 333 insertions(+), 235 deletions(-) create mode 100644 blst/tests/c_bindings.rs create mode 100644 kzg-bench/src/tests/c_bindings.rs rename {blst => kzg-bench/src}/tests/fixtures/trusted_setup_4_old.txt (100%) rename {blst => kzg-bench/src}/tests/fixtures/trusted_setup_old.txt (100%) create mode 100644 kzg-bench/src/tests/utils.rs diff --git a/blst/src/eip_4844.rs b/blst/src/eip_4844.rs index d3b4bdfba..193997463 100644 --- a/blst/src/eip_4844.rs +++ b/blst/src/eip_4844.rs @@ -991,7 +991,7 @@ pub unsafe extern "C" fn compute_kzg_proof( #[cfg(test)] mod tests { - use kzg_bench::tests::eip_4844::get_trusted_setup_path; + use kzg_bench::tests::utils::get_trusted_setup_path; use crate::eip_4844::{kzg_settings_to_c, kzg_settings_to_rust}; diff --git a/blst/tests/c_bindings.rs b/blst/tests/c_bindings.rs new file mode 100644 index 000000000..21315db03 --- /dev/null +++ b/blst/tests/c_bindings.rs @@ -0,0 +1,39 @@ +#[cfg(test)] +mod tests { + use kzg_bench::tests::c_bindings::{ + blob_to_kzg_commitment_invalid_blob_test, load_trusted_setup_invalid_form_test, + load_trusted_setup_invalid_g1_byte_length_test, load_trusted_setup_invalid_g1_point_test, + load_trusted_setup_invalid_g2_byte_length_test, load_trusted_setup_invalid_g2_point_test, + }; + use rust_kzg_blst::eip_4844::{blob_to_kzg_commitment, load_trusted_setup}; + + #[test] + fn blob_to_kzg_commitment_invalid_blob() { + blob_to_kzg_commitment_invalid_blob_test(load_trusted_setup, blob_to_kzg_commitment); + } + + #[test] + fn load_trusted_setup_invalid_g1_byte_length() { + load_trusted_setup_invalid_g1_byte_length_test(load_trusted_setup); + } + + #[test] + fn load_trusted_setup_invalid_g1_point() { + load_trusted_setup_invalid_g1_point_test(load_trusted_setup); + } + + #[test] + fn load_trusted_setup_invalid_g2_byte_length() { + load_trusted_setup_invalid_g2_byte_length_test(load_trusted_setup); + } + + #[test] + fn load_trusted_setup_invalid_g2_point() { + load_trusted_setup_invalid_g2_point_test(load_trusted_setup); + } + + #[test] + fn load_trusted_setup_invalid_form() { + load_trusted_setup_invalid_form_test(load_trusted_setup); + } +} diff --git a/blst/tests/eip_4844.rs b/blst/tests/eip_4844.rs index 4cb4221be..9f43ec6c7 100644 --- a/blst/tests/eip_4844.rs +++ b/blst/tests/eip_4844.rs @@ -1,12 +1,5 @@ #[cfg(test)] mod tests { - use std::path::PathBuf; - use std::{fs::File, io::Read, ptr::null_mut}; - - use kzg::eip_4844::{ - load_trusted_setup_string, Blob, CKZGSettings, KZGCommitment, BYTES_PER_COMMITMENT, - BYTES_PER_FIELD_ELEMENT, BYTES_PER_G1, BYTES_PER_G2, C_KZG_RET_BADARGS, C_KZG_RET_OK, - }; use kzg::Fr; use kzg_bench::tests::eip_4844::{ blob_to_kzg_commitment_test, bytes_to_bls_field_test, @@ -14,7 +7,6 @@ mod tests { compute_and_verify_blob_kzg_proof_test, compute_and_verify_kzg_proof_fails_with_incorrect_proof_test, compute_and_verify_kzg_proof_round_trip_test, compute_kzg_proof_test, compute_powers_test, - generate_random_blob_bytes, get_trusted_setup_path, verify_kzg_proof_batch_fails_with_incorrect_proof_test, verify_kzg_proof_batch_test, }; #[cfg(not(feature = "minimal-spec"))] @@ -26,11 +18,10 @@ mod tests { }; use rust_kzg_blst::consts::SCALE2_ROOT_OF_UNITY; use rust_kzg_blst::eip_4844::{ - blob_to_kzg_commitment, blob_to_kzg_commitment_rust, blob_to_polynomial_rust, - bytes_to_blob, compute_blob_kzg_proof_rust, compute_kzg_proof_rust, compute_powers, - evaluate_polynomial_in_evaluation_form_rust, load_trusted_setup, - load_trusted_setup_filename_rust, verify_blob_kzg_proof_batch_rust, - verify_blob_kzg_proof_rust, verify_kzg_proof_rust, + blob_to_kzg_commitment_rust, blob_to_polynomial_rust, bytes_to_blob, + compute_blob_kzg_proof_rust, compute_kzg_proof_rust, compute_powers, + evaluate_polynomial_in_evaluation_form_rust, load_trusted_setup_filename_rust, + verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust, verify_kzg_proof_rust, }; use rust_kzg_blst::types::fft_settings::expand_root_of_unity; use rust_kzg_blst::types::{ @@ -258,210 +249,6 @@ mod tests { ); } - #[test] - pub fn blob_to_kzg_commitment_invalid_blob() { - let mut file = File::open(get_trusted_setup_path()).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - - let mut c_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut c_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - assert_eq!(status, C_KZG_RET_OK); - - let mut rng = rand::thread_rng(); - let mut blob_bytes = generate_random_blob_bytes(&mut rng); - - let bls_modulus: [u8; BYTES_PER_FIELD_ELEMENT] = [ - 0x73, 0xED, 0xA7, 0x53, 0x29, 0x9D, 0x7D, 0x48, 0x33, 0x39, 0xD8, 0x08, 0x09, 0xA1, - 0xD8, 0x05, 0x53, 0xBD, 0xA4, 0x02, 0xFF, 0xFE, 0x5B, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, - 0x00, 0x00, 0x00, 0x01, - ]; - // Make first field element equal to BLS_MODULUS - blob_bytes[0..BYTES_PER_FIELD_ELEMENT].copy_from_slice(&bls_modulus); - - let blob = Blob { bytes: blob_bytes }; - let mut commitment = KZGCommitment { - bytes: [0; BYTES_PER_COMMITMENT], - }; - - let output = unsafe { blob_to_kzg_commitment(&mut commitment, &blob, &c_settings) }; - - assert_eq!(output, C_KZG_RET_BADARGS) - } - - #[test] - pub fn load_trusted_setup_invalid_g1_byte_length() { - let mut file = File::open(get_trusted_setup_path()).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (mut g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - // Add one more point - let additional = [0; BYTES_PER_G1]; - g1_bytes.extend_from_slice(&additional); - - let mut loaded_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut loaded_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - - assert_eq!(status, C_KZG_RET_BADARGS) - } - - #[test] - pub fn load_trusted_setup_invalid_g2_byte_length() { - let mut file = File::open(get_trusted_setup_path()).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (g1_bytes, mut g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - // Add one more point - let additional = [0; BYTES_PER_G2]; - g2_bytes.extend_from_slice(&additional); - - let mut loaded_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut loaded_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - - assert_eq!(status, C_KZG_RET_BADARGS) - } - - #[test] - pub fn load_trusted_setup_invalid_g1_point() { - let mut file = File::open(get_trusted_setup_path()).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (mut g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - // Break first G1 point - g1_bytes[0] = 0; - - let mut loaded_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut loaded_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - - assert_eq!(status, C_KZG_RET_BADARGS) - } - - #[test] - pub fn load_trusted_setup_invalid_g2_point() { - let mut file = File::open(get_trusted_setup_path()).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (g1_bytes, mut g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - // Break first G2 point - g2_bytes[0] = 0; - - let mut loaded_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut loaded_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - - assert_eq!(status, C_KZG_RET_BADARGS) - } - - #[test] - pub fn load_trusted_setup_invalid_form() { - let trusted_setup_name = if cfg!(feature = "minimal-spec") { - "trusted_setup_4_old.txt" - } else { - "trusted_setup_old.txt" - }; - let mut file = File::open( - PathBuf::from(env!("CARGO_MANIFEST_DIR")) - .join("tests/fixtures") - .join(trusted_setup_name) - .as_os_str() - .to_str() - .unwrap(), - ) - .unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - let (g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); - - let mut loaded_settings = CKZGSettings { - g1_values: null_mut(), - g2_values: null_mut(), - max_width: 0, - roots_of_unity: null_mut(), - }; - - let status = unsafe { - load_trusted_setup( - &mut loaded_settings, - g1_bytes.as_ptr(), - g1_bytes.len() / BYTES_PER_G1, - g2_bytes.as_ptr(), - g2_bytes.len() / BYTES_PER_G2, - ) - }; - - assert_eq!(status, C_KZG_RET_BADARGS) - } - #[test] pub fn expand_root_of_unity_too_long() { let out = expand_root_of_unity(&FsFr::from_u64_arr(&SCALE2_ROOT_OF_UNITY[1]), 1); @@ -470,7 +257,7 @@ mod tests { #[test] pub fn expand_root_of_unity_too_short() { - let out = expand_root_of_unity(&FsFr::from_u64_arr(&SCALE2_ROOT_OF_UNITY[1]), 1); + let out = expand_root_of_unity(&FsFr::from_u64_arr(&SCALE2_ROOT_OF_UNITY[1]), 3); assert!(out.is_err()); } } diff --git a/kzg-bench/src/tests/c_bindings.rs b/kzg-bench/src/tests/c_bindings.rs new file mode 100644 index 000000000..6c659ef98 --- /dev/null +++ b/kzg-bench/src/tests/c_bindings.rs @@ -0,0 +1,265 @@ +use std::{fs::File, io::Read, path::PathBuf, ptr::null_mut}; + +use kzg::eip_4844::{ + load_trusted_setup_string, Blob, CKZGSettings, KZGCommitment, BYTES_PER_COMMITMENT, + BYTES_PER_FIELD_ELEMENT, BYTES_PER_G1, BYTES_PER_G2, C_KZG_RET, C_KZG_RET_BADARGS, + C_KZG_RET_OK, +}; + +use crate::tests::{ + eip_4844::generate_random_blob_bytes, + utils::{get_manifest_dir, get_trusted_setup_path}, +}; + +pub fn blob_to_kzg_commitment_invalid_blob_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, + blob_to_kzg_commitment: unsafe extern "C" fn( + out: *mut KZGCommitment, + blob: *const Blob, + s: &CKZGSettings, + ) -> C_KZG_RET, +) { + let mut file = File::open(get_trusted_setup_path()) + .map_err(|_| {}) + .unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + + let mut c_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut c_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + assert_eq!(status, C_KZG_RET_OK); + + let mut rng = rand::thread_rng(); + let mut blob_bytes = generate_random_blob_bytes(&mut rng); + + let bls_modulus: [u8; BYTES_PER_FIELD_ELEMENT] = [ + 0x73, 0xED, 0xA7, 0x53, 0x29, 0x9D, 0x7D, 0x48, 0x33, 0x39, 0xD8, 0x08, 0x09, 0xA1, 0xD8, + 0x05, 0x53, 0xBD, 0xA4, 0x02, 0xFF, 0xFE, 0x5B, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x00, 0x01, + ]; + // Make first field element equal to BLS_MODULUS + blob_bytes[0..BYTES_PER_FIELD_ELEMENT].copy_from_slice(&bls_modulus); + + let blob = Blob { bytes: blob_bytes }; + let mut commitment = KZGCommitment { + bytes: [0; BYTES_PER_COMMITMENT], + }; + + let output = unsafe { blob_to_kzg_commitment(&mut commitment, &blob, &c_settings) }; + + assert_eq!(output, C_KZG_RET_BADARGS) +} + +pub fn load_trusted_setup_invalid_g1_byte_length_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, +) { + let mut file = File::open(get_trusted_setup_path()).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (mut g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + // Add one more point + let additional = [0; BYTES_PER_G1]; + g1_bytes.extend_from_slice(&additional); + + let mut loaded_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut loaded_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + + assert_eq!(status, C_KZG_RET_BADARGS) +} + +pub fn load_trusted_setup_invalid_g1_point_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, +) { + let mut file = File::open(get_trusted_setup_path()).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (mut g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + // Break first G1 point + g1_bytes[0] = 0; + + let mut loaded_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut loaded_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + + assert_eq!(status, C_KZG_RET_BADARGS) +} + +pub fn load_trusted_setup_invalid_g2_byte_length_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, +) { + let mut file = File::open(get_trusted_setup_path()).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (g1_bytes, mut g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + // Add one more point + let additional = [0; BYTES_PER_G2]; + g2_bytes.extend_from_slice(&additional); + + let mut loaded_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut loaded_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + + assert_eq!(status, C_KZG_RET_BADARGS) +} + +pub fn load_trusted_setup_invalid_g2_point_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, +) { + let mut file = File::open(get_trusted_setup_path()).unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (g1_bytes, mut g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + // Break first G2 point + g2_bytes[0] = 0; + + let mut loaded_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut loaded_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + + assert_eq!(status, C_KZG_RET_BADARGS) +} + +pub fn load_trusted_setup_invalid_form_test( + load_trusted_setup: unsafe extern "C" fn( + *mut CKZGSettings, + *const u8, + usize, + *const u8, + usize, + ) -> C_KZG_RET, +) { + let trusted_setup_name = if cfg!(feature = "minimal-spec") { + "trusted_setup_4_old.txt" + } else { + "trusted_setup_old.txt" + }; + let mut file = File::open( + PathBuf::from(get_manifest_dir()) + .join("src/tests/fixtures") + .join(trusted_setup_name) + .as_os_str() + .to_str() + .unwrap(), + ) + .unwrap(); + let mut contents = String::new(); + file.read_to_string(&mut contents).unwrap(); + let (g1_bytes, g2_bytes) = load_trusted_setup_string(&contents).unwrap(); + + let mut loaded_settings = CKZGSettings { + g1_values: null_mut(), + g2_values: null_mut(), + max_width: 0, + roots_of_unity: null_mut(), + }; + + let status = unsafe { + load_trusted_setup( + &mut loaded_settings, + g1_bytes.as_ptr(), + g1_bytes.len() / BYTES_PER_G1, + g2_bytes.as_ptr(), + g2_bytes.len() / BYTES_PER_G2, + ) + }; + + assert_eq!(status, C_KZG_RET_BADARGS) +} diff --git a/kzg-bench/src/tests/eip_4844.rs b/kzg-bench/src/tests/eip_4844.rs index 3b147aa98..84bdb5468 100644 --- a/kzg-bench/src/tests/eip_4844.rs +++ b/kzg-bench/src/tests/eip_4844.rs @@ -4,6 +4,7 @@ use crate::test_vectors::{ blob_to_kzg_commitment, compute_blob_kzg_proof, compute_kzg_proof, verify_blob_kzg_proof, verify_blob_kzg_proof_batch, verify_kzg_proof, }; +use crate::tests::utils::{get_manifest_dir, get_trusted_setup_path}; use kzg::eip_4844::{ BYTES_PER_BLOB, BYTES_PER_COMMITMENT, BYTES_PER_FIELD_ELEMENT, BYTES_PER_PROOF, FIELD_ELEMENTS_PER_BLOB, TRUSTED_SETUP_PATH, @@ -78,22 +79,6 @@ pub fn compute_powers_test(compute_powers: &dyn Fn(&TFr, usize) -> Vec< } } -fn get_manifest_dir() -> String { - let current = current_dir().unwrap(); - let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let relative = diff_paths(manifest, current).unwrap(); - - relative.into_os_string().into_string().unwrap() -} - -pub fn get_trusted_setup_path() -> String { - PathBuf::from(get_manifest_dir()) - .join(TRUSTED_SETUP_PATH) - .into_os_string() - .into_string() - .unwrap() -} - #[allow(clippy::type_complexity)] pub fn blob_to_kzg_commitment_test< TFr: Fr + Copy, diff --git a/blst/tests/fixtures/trusted_setup_4_old.txt b/kzg-bench/src/tests/fixtures/trusted_setup_4_old.txt similarity index 100% rename from blst/tests/fixtures/trusted_setup_4_old.txt rename to kzg-bench/src/tests/fixtures/trusted_setup_4_old.txt diff --git a/blst/tests/fixtures/trusted_setup_old.txt b/kzg-bench/src/tests/fixtures/trusted_setup_old.txt similarity index 100% rename from blst/tests/fixtures/trusted_setup_old.txt rename to kzg-bench/src/tests/fixtures/trusted_setup_old.txt diff --git a/kzg-bench/src/tests/mod.rs b/kzg-bench/src/tests/mod.rs index f988b41c3..e38cc6259 100644 --- a/kzg-bench/src/tests/mod.rs +++ b/kzg-bench/src/tests/mod.rs @@ -1,4 +1,5 @@ pub mod bls12_381; +pub mod c_bindings; pub mod consts; pub mod das; pub mod eip_4844; @@ -9,4 +10,5 @@ pub mod fk20_proofs; pub mod kzg_proofs; pub mod poly; pub mod recover; +pub mod utils; pub mod zero_poly; diff --git a/kzg-bench/src/tests/utils.rs b/kzg-bench/src/tests/utils.rs new file mode 100644 index 000000000..1669de673 --- /dev/null +++ b/kzg-bench/src/tests/utils.rs @@ -0,0 +1,20 @@ +use std::{env::current_dir, path::PathBuf}; + +use kzg::eip_4844::TRUSTED_SETUP_PATH; +use pathdiff::diff_paths; + +pub fn get_manifest_dir() -> String { + let current = current_dir().unwrap(); + let manifest = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let relative = diff_paths(manifest, current).unwrap(); + + relative.into_os_string().into_string().unwrap() +} + +pub fn get_trusted_setup_path() -> String { + PathBuf::from(get_manifest_dir()) + .join(TRUSTED_SETUP_PATH) + .into_os_string() + .into_string() + .unwrap() +}