Skip to content

Commit

Permalink
apply suggestions & remove leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
kilic committed Nov 29, 2023
1 parent 402e7a5 commit 3dd8887
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Cargo.lock
.vscode
**/*.html
.DS_Store
**/*.py

# script generated source code
src/bn256/fr/table.rs
Expand Down
3 changes: 1 addition & 2 deletions src/ff_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub trait Legendre {
// The legendre symbol returns 0 for 0
// and 1 for quadratic residues,
// we consider 0 a square hence quadratic residue.
unimplemented!()
// self.legendre().ct_ne(&-1)
self.legendre().ct_ne(&-1)
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::multicore;

fn get_booth_index(window_index: usize, window_size: usize, el: &[u8]) -> i32 {
// Booth encoding:
// * step by `window`e size
// * step by `window` size
// * slice by size of `window + 1``
// * each window overlap by 1 bit
// * append a zero bit to the least significant end
Expand All @@ -27,7 +27,7 @@ fn get_booth_index(window_index: usize, window_size: usize, el: &[u8]) -> i32 {
}
let mut tmp = u32::from_le_bytes(v);

// pad with one 0 if windowing least significant window
// pad with one 0 if slicing the least significant window
if window_index == 0 {
tmp <<= 1;
}
Expand All @@ -46,7 +46,7 @@ fn get_booth_index(window_index: usize, window_size: usize, el: &[u8]) -> i32 {
if sign {
tmp as i32
} else {
((!tmp.saturating_sub(1) & ((1 << window_size) - 1)) as i32).neg()
((!(tmp - 1) & ((1 << window_size) - 1)) as i32).neg()
}
}

Expand Down Expand Up @@ -363,17 +363,16 @@ mod test {
}
}

#[test]
fn test_msm_cross() {
let min_k = 10;
let max_k = 22;

fn run_msm_cross<C: CurveAffine>(min_k: usize, max_k: usize) {
let points = (0..1 << max_k)
.map(|_| G1Affine::random(OsRng))
.map(|_| C::Curve::random(OsRng))
.collect::<Vec<_>>();
let mut affine_points = vec![C::identity(); 1 << max_k];
C::Curve::batch_normalize(&points[..], &mut affine_points[..]);
let points = affine_points;

let scalars = (0..1 << max_k)
.map(|_| Fr::random(OsRng))
.map(|_| C::Scalar::random(OsRng))
.collect::<Vec<_>>();

for k in min_k..=max_k {
Expand All @@ -391,4 +390,10 @@ mod test {
assert_eq!(e0, e1);
}
}

#[test]
fn test_msm_cross() {
run_msm_cross::<G1Affine>(10, 18);
// run_msm_cross::<G1Affine>(19, 23);
}
}

0 comments on commit 3dd8887

Please sign in to comment.