Skip to content

Commit

Permalink
minor cleanups for documentation, tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Aug 7, 2021
1 parent ecb2136 commit fb7a35c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1685,14 +1685,11 @@ fn test_sum_of_products_alloc() {
let s_tilde = Scalar::random(&mut rng);
let c = Scalar::random(&mut rng);

assert_eq!(
h0 * s,
G1Projective::sum_of_products_in_place(&[h0], &mut [s])
);
assert_eq!(h0 * s, G1Projective::sum_of_products(&[h0], &[s]));
assert_eq!(s, s_clone);
assert_eq!(
h0 * s_tilde,
G1Projective::sum_of_products(&[h0], &mut [s_tilde])
G1Projective::sum_of_products(&[h0], &[s_tilde])
);

// test schnorr proof
Expand All @@ -1702,6 +1699,6 @@ fn test_sum_of_products_alloc() {
assert_eq!(u_tilde, u * c + h0 * s_hat);
assert_eq!(
u_tilde,
G1Projective::sum_of_products(&[u, h0], &mut [c, s_hat])
G1Projective::sum_of_products(&[u, h0], &[c, s_hat])
);
}
6 changes: 3 additions & 3 deletions src/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2148,10 +2148,10 @@ fn test_sum_of_products_alloc() {
let s_tilde = Scalar::random(&mut rng);
let c = Scalar::random(&mut rng);

assert_eq!(h0 * s, G2Projective::sum_of_products(&[h0], &mut [s]));
assert_eq!(h0 * s, G2Projective::sum_of_products(&[h0], &[s]));
assert_eq!(
h0 * s_tilde,
G2Projective::sum_of_products(&[h0], &mut [s_tilde])
G2Projective::sum_of_products(&[h0], &[s_tilde])
);

// test schnorr proof
Expand All @@ -2161,6 +2161,6 @@ fn test_sum_of_products_alloc() {
assert_eq!(u_tilde, u * c + h0 * s_hat);
assert_eq!(
u_tilde,
G2Projective::sum_of_products(&[u, h0], &mut [c, s_hat])
G2Projective::sum_of_products(&[u, h0], &[c, s_hat])
);
}
17 changes: 10 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ macro_rules! impl_pippenger_sum_of_products {
() => {
/// Use pippenger multi-exponentiation method to compute
/// the sum of multiple points raise to scalars.
/// This uses a fixed window of 4 to be constant time
///
/// This uses a fixed window of 4 to be constant time.
#[cfg(feature = "alloc")]
pub fn sum_of_products(points: &[Self], scalars: &[Scalar]) -> Self {
use alloc::vec::Vec;
Expand All @@ -191,11 +192,12 @@ macro_rules! impl_pippenger_sum_of_products {

/// Use pippenger multi-exponentiation method to compute
/// the sum of multiple points raise to scalars.
/// This uses a fixed window of 4 to be constant time
/// The scalars are used as place holders for temporary computations
///
/// The scalars are used as placeholders for temporary computations.
/// This uses a fixed window of 4 to be constant time.
pub fn sum_of_products_in_place(points: &[Self], scalars: &mut [Scalar]) -> Self {
// Scalars are in montgomery form, hack them in place to be temporarily
// in canonical form, do the computation, then switch them back
// Scalars are in montgomery form, hack them in-place to be temporarily
// in canonical form, do the computation, then switch them back.
for i in 0..scalars.len() {
// Turn into canonical form by computing (a.R) / R = a
scalars[i] = Scalar::montgomery_reduce(
Expand All @@ -218,8 +220,9 @@ macro_rules! impl_pippenger_sum_of_products {
}

/// Compute pippenger multi-exponentiation.
/// Pippenger relies on scalars in canonical form
/// This uses a fixed window of 4 to be constant time
///
/// Pippenger relies on scalars in canonical form. This uses a fixed
/// window of 4 to be constant time.
fn sum_of_products_pippenger(points: &[Self], scalars: &[Scalar]) -> Self {
const WINDOW: usize = 4;
const NUM_BUCKETS: usize = 1 << WINDOW;
Expand Down

0 comments on commit fb7a35c

Please sign in to comment.