Skip to content

Commit

Permalink
[#1793] Get rid of unnecessary WitnessColumnIndexer
Browse files Browse the repository at this point in the history
  • Loading branch information
volhovm committed Mar 4, 2024
1 parent 900ce63 commit af88c18
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions msm/src/ffa/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,12 @@ fn limb_decompose(input: &Ff1) -> [Fp; LIMBS_NUM] {
ff_el.limbs
}

pub struct WitnessColumnsIndexer<T> {
pub(crate) a: [T; LIMBS_NUM],
pub(crate) b: [T; LIMBS_NUM],
pub(crate) c: [T; LIMBS_NUM],
pub(crate) d: [T; LIMBS_NUM],
}

#[allow(dead_code)]
/// Builder environment for a native group `G`.
pub struct MSMCircuitEnv<G: KimchiCurve> {
/// Aggregated witness, in raw form. For accessing [`Witness`], see the
/// `get_witness` method.
witness_raw: Vec<WitnessColumnsIndexer<G::ScalarField>>,
witness_raw: Vec<WitnessColumns<G::ScalarField>>,
}

impl MSMCircuitEnv<BN254G1Affine> {
Expand All @@ -54,17 +47,9 @@ impl MSMCircuitEnv<BN254G1Affine> {
let mut x: Vec<Vec<Fp>> = vec![vec![]; 4 * LIMBS_NUM];

for wc in &self.witness_raw {
let WitnessColumnsIndexer {
a: wc_a,
b: wc_b,
c: wc_c,
d: wc_d,
} = wc;
for i in 0..LIMBS_NUM {
x[i].push(wc_a[i]);
x[LIMBS_NUM + i].push(wc_b[i]);
x[2 * LIMBS_NUM + i].push(wc_c[i]);
x[3 * LIMBS_NUM + i].push(wc_d[i]);
let WitnessColumns { x: witness_row } = wc;
for i in 0..4 * LIMBS_NUM {
x[i].push(witness_row[i]);
}
}

Expand Down Expand Up @@ -153,12 +138,12 @@ impl MSMCircuitEnv<BN254G1Affine> {
.unwrap_or_else(|_| panic!("Length mismatch"));
let d_limbs: [Fp; LIMBS_NUM] = [Zero::zero(); LIMBS_NUM];

self.witness_raw.push(WitnessColumnsIndexer {
a: a_limbs,
b: b_limbs,
c: c_limbs,
d: d_limbs,
});
let mut witness_row = vec![];
witness_row.append(&mut a_limbs.to_vec());
witness_row.append(&mut b_limbs.to_vec());
witness_row.append(&mut c_limbs.to_vec());
witness_row.append(&mut d_limbs.to_vec());
self.witness_raw.push(WitnessColumns { x: witness_row });
}

pub fn add_test_multiplication(&mut self, a: Ff1, b: Ff1) {
Expand All @@ -175,11 +160,11 @@ impl MSMCircuitEnv<BN254G1Affine> {

let c_limbs: [Fp; LIMBS_NUM] = [Zero::zero(); LIMBS_NUM];

self.witness_raw.push(WitnessColumnsIndexer {
a: a_limbs,
b: b_limbs,
c: c_limbs,
d: d_limbs,
});
let mut witness_row = vec![];
witness_row.append(&mut a_limbs.to_vec());
witness_row.append(&mut b_limbs.to_vec());
witness_row.append(&mut c_limbs.to_vec());
witness_row.append(&mut d_limbs.to_vec());
self.witness_raw.push(WitnessColumns { x: witness_row });
}
}

0 comments on commit af88c18

Please sign in to comment.