Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lonerapier committed Aug 19, 2023
1 parent c39463f commit 24d437d
Show file tree
Hide file tree
Showing 5 changed files with 823 additions and 25 deletions.
4 changes: 3 additions & 1 deletion barustenberg/src/ecc/scalar_multiplication/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
pub(crate) mod process_buckets;
pub(crate) mod runtime_states;
pub(crate) mod scalar_multiplication;
pub(crate) mod tests;
pub(crate) mod wnaf;

#[cfg(test)]
mod tests;

use ark_ff::Field;

#[inline]
Expand Down
6 changes: 3 additions & 3 deletions barustenberg/src/ecc/scalar_multiplication/runtime_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(crate) const fn get_num_rounds(num_points: usize) -> usize {
}

#[derive(Clone, Default, Debug)]
pub(crate) struct PippengerRuntimeState<F: Field, G: AffineRepr<BaseField = F>> {
pub(crate) struct PippengerRuntimeState<F: Field, G: AffineRepr> {
// TODO: maybe arc should be used here for threads. think later.
pub point_schedule: Vec<u64>,
pub point_pairs_1: Vec<G>,
Expand All @@ -84,7 +84,7 @@ pub(crate) struct PippengerRuntimeState<F: Field, G: AffineRepr<BaseField = F>>
}

#[derive(Default, Clone, Debug)]
pub(crate) struct AffinePippengerRuntimeState<F: Field, G: AffineRepr<BaseField = F>> {
pub(crate) struct AffinePippengerRuntimeState<F: Field, G: AffineRepr> {
pub points: Vec<G>,
pub point_pairs_1: Vec<G>,
pub point_pairs_2: Vec<G>,
Expand All @@ -97,7 +97,7 @@ pub(crate) struct AffinePippengerRuntimeState<F: Field, G: AffineRepr<BaseField
pub num_buckets: usize,
}

impl<F: Field, G: AffineRepr<BaseField = F>> PippengerRuntimeState<F, G> {
impl<F: Field, G: AffineRepr> PippengerRuntimeState<F, G> {
pub(crate) fn new(num_initial_points: usize) -> Self {
const MAX_NUM_ROUNDS: u32 = 256;
let num_points = num_initial_points * 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn generate_pippenger_point_table<F: Field, G: AffineRepr<BaseField =
}
}

fn compute_wnaf_states<F: Field>(
pub fn compute_wnaf_states<F: Field>(
point_schedule: &mut Vec<u64>,
skew_table: &mut Vec<bool>,
round_counts: &mut Vec<u64>,
Expand All @@ -57,7 +57,7 @@ fn compute_wnaf_states<F: Field>(
todo!("implement");
}

fn organise_buckets(point_schedule: &mut Vec<u64>, num_points: usize) {
pub fn organise_buckets(point_schedule: &mut Vec<u64>, num_points: usize) {
let num_rounds: usize = get_num_rounds(num_points);

for i in 0..num_rounds {
Expand All @@ -74,7 +74,7 @@ fn organise_buckets(point_schedule: &mut Vec<u64>, num_points: usize) {
// 1.) the output of arkworks implementation returns a (sign, field) instead of just the field element
// 2.) glv decomposition exists as a trait we would need to implement for each curve and requires the same amount of thought and code as just doing this
// In the future i do think these implementations should live as a trait. But not a trait defined by arkworks #fuck_arkworks
fn split_into_endomorphism_scalars<F: Field>(scalar: F) -> Vec<F> {
pub fn split_into_endomorphism_scalars<F: Field>(scalar: F) -> Vec<F> {
todo!();
}

Expand All @@ -100,7 +100,7 @@ fn conditionally_negate_affine<G: AffineRepr>(src: &G, dest: &G, predicate: u64)
}

//Note u32 chosen to be in line with c++ implementation
fn construct_addition_chains<F: Field, G: AffineRepr<BaseField = F>>(
pub fn construct_addition_chains<F: Field, G: AffineRepr<BaseField = F>>(
state: &mut AffinePippengerRuntimeState<F, G>,
empty_bucket_counts: bool,
) -> usize {
Expand Down Expand Up @@ -427,7 +427,7 @@ fn add_affine_point_with_edge_cases<F: Field, G: AffineRepr<BaseField = F>>(
*
* We can re-arrange the Pippenger algorithm to get this property, but it's...complicated
**/
fn add_affine_points<F: Field, G: AffineRepr<BaseField = F>>(
pub fn add_affine_points<F: Field, G: AffineRepr<BaseField = F>>(
points: &mut [G],
num_points: usize,
scratch_space: &mut [F],
Expand Down Expand Up @@ -501,7 +501,7 @@ fn evaluate_addition_chains<F: Field, G: AffineRepr<BaseField = F>>(
}
}

fn reduce_buckets<F: Field, G: AffineRepr<BaseField = F>>(
pub fn reduce_buckets<F: Field, G: AffineRepr<BaseField = F>>(
state: &mut AffinePippengerRuntimeState<F, G>,
first_round: bool,
handle_edge_cases: bool,
Expand Down
Loading

0 comments on commit 24d437d

Please sign in to comment.