Skip to content

Commit

Permalink
small changes, fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anupsv committed May 21, 2024
1 parent ad9e603 commit de5186f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ rayon = "1.5"
num-traits = "0.2"
byteorder = "1.4"
ark-poly = "0.4.2"
memmap2 = "0.9.4"
crossbeam-channel = "0.5"
num_cpus = "1.16.0"


96 changes: 48 additions & 48 deletions src/arith.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,23 @@ mod tests {
use ark_ff::fields::PrimeField;
use ark_bn254::Fq;

// #[test]
// fn test_montgomery_reduce_basic() {
// // Basic test case with small values
// let (z0, z1, z2, z3) = montgomery_reduce(&1, &2, &3, &4);
// let expected = (1, 2, 3, 4); // Expected values will depend on the actual function logic
// assert_eq!((z0, z1, z2, z3), expected);
// }

// #[test]
// fn test_montgomery_reduce_large_values() {
// // Test case with large values
// let (z0, z1, z2, z3) = montgomery_reduce(&u64::MAX, &u64::MAX, &u64::MAX, &u64::MAX);
// // Calculate the expected result based on the Montgomery reduction algorithm
// // This is an example, you need to calculate the correct expected values
// let expected = (0, 0, 0, 0); // Placeholder, update with correct values
// assert_eq!((z0, z1, z2, z3), expected);
// }
#[test]
fn test_montgomery_reduce_basic() {
// Basic test case with small values
let (z0, z1, z2, z3) = montgomery_reduce(&1_u64, &2_u64, &3_u64, &4_u64);
let expected = (1015341533287961015, 614227897398722093, 10092218387357075792, 2216689030230384375); // Expected values will depend on the actual function logic
assert_eq!((z0, z1, z2, z3), expected);
}

#[test]
fn test_montgomery_reduce_large_values() {
// Test case with large values
let (z0, z1, z2, z3) = montgomery_reduce(&u64::MAX, &u64::MAX, &u64::MAX, &u64::MAX);
// Calculate the expected result based on the Montgomery reduction algorithm
// This is an example, you need to calculate the correct expected values
let expected = (5664406609643832081, 12421288465352154260, 16783890958096582019, 143333441873369583); // Placeholder, update with correct values
assert_eq!((z0, z1, z2, z3), expected);
}

#[test]
fn test_montgomery_reduce_modulus() {
Expand All @@ -172,15 +172,15 @@ mod tests {
assert_eq!((z0, z1, z2, z3), expected);
}

// #[test]
// fn test_montgomery_reduce_mixed_values() {
// // Test case with mixed values
// let (z0, z1, z2, z3) = montgomery_reduce(&1, &0, &u64::MAX, &2);
// // Calculate the expected result based on the Montgomery reduction algorithm
// // This is an example, you need to calculate the correct expected values
// let expected = (1, 0, u64::MAX, 2); // Placeholder, update with correct values
// assert_eq!((z0, z1, z2, z3), expected);
// }
#[test]
fn test_montgomery_reduce_mixed_values() {
// Test case with mixed values
let (z0, z1, z2, z3) = montgomery_reduce(&1_u64, &0_u64, &u64::MAX, &2_u64);
// Calculate the expected result based on the Montgomery reduction algorithm
// This is an example, you need to calculate the correct expected values
let expected = (3113359121765060147, 13738305701328143478, 16036157884190814464, 3242762270701651436); // Placeholder, update with correct values
assert_eq!((z0, z1, z2, z3), expected);
}

#[test]
fn test_madd2_no_overflow() {
Expand All @@ -206,13 +206,13 @@ mod tests {
assert_eq!(lo, 0);
}

// #[test]
// fn test_madd2_with_both_overflows() {
// // Case where both multiplication and addition overflow
// let (hi, lo) = madd2(u64::MAX, u64::MAX, u64::MAX, 1);
// assert_eq!(hi, u64::MAX);
// assert_eq!(lo, 0);
// }
#[test]
fn test_madd2_with_both_overflows() {
// Case where both multiplication and addition overflow
let (hi, lo) = madd2(u64::MAX, u64::MAX, u64::MAX, 1);
assert_eq!(hi, u64::MAX);
assert_eq!(lo, 1);
}

#[test]
fn test_madd2_edge_case_zero_multiplication() {
Expand All @@ -230,21 +230,21 @@ mod tests {
assert_eq!(lo, 123 * 456);
}

// #[test]
// fn test_madd2_large_numbers() {
// // Case with large numbers to test boundary conditions
// let (hi, lo) = madd2(1 << 32, 1 << 32, u64::MAX - 1, 1);
// assert_eq!(hi, 1);
// assert_eq!(lo, 0);
// }

// #[test]
// fn test_madd2_all_ones() {
// // Case where all inputs are ones (u64::MAX)
// let (hi, lo) = madd2(u64::MAX, u64::MAX, u64::MAX, u64::MAX);
// assert_eq!(hi, u64::MAX);
// assert_eq!(lo, u64::MAX - 1);
// }
#[test]
fn test_madd2_large_numbers() {
// Case with large numbers to test boundary conditions
let (hi, lo) = madd2(1 << 32, 1 << 32, u64::MAX - 1, 1);
assert_eq!(hi, 1);
assert_eq!(lo, u64::MAX);
}

#[test]
fn test_madd2_all_ones() {
// Case where all inputs are ones (u64::MAX)
let (hi, lo) = madd2(u64::MAX, u64::MAX, u64::MAX, u64::MAX);
assert_eq!(hi, u64::MAX);
assert_eq!(lo, u64::MAX);
}

#[test]
fn test_sub_64_no_borrow() {
Expand Down
2 changes: 1 addition & 1 deletion src/blob.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{errors::BlobError, helpers, polynomial::Polynomial};


/// A blob which is DA spec aligned.
/// A blob which is Eigen DA spec aligned.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Blob {
blob_data: Vec<u8>,
Expand Down
2 changes: 1 addition & 1 deletion src/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl Kzg {
}

pub fn verify_kzg_proof(&self, commitment: G1Affine, proof: G1Affine, value_fr: Fr, z_fr: Fr) -> bool {
let g2_tau = self.g2.get(1).unwrap().clone();
let g2_tau = if self.g2.len() > 28 { self.g2.get(1).unwrap().clone() } else { self.g2.get(0).unwrap().clone() };
let value_g1 = (G1Affine::generator() * value_fr).into_affine();
let commit_minus_value = (commitment - value_g1).into_affine();
let z_g2 = (G2Affine::generator() * z_fr).into_affine();
Expand Down

0 comments on commit de5186f

Please sign in to comment.