Skip to content

Commit 66e4bfe

Browse files
authored
Merge pull request #1 from EYBlockchain/livesey/fully-collapse
Livesey/fully collapse
2 parents ebd6859 + ee9b8cd commit 66e4bfe

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

circuits/src/verifier/accumulator.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ impl<S: SelfEmulation> Accumulator<S> {
121121
self.rhs.collapse();
122122
}
123123

124+
/// Evaluates the variable and fixed parts of the Accumulator collapsing
125+
/// each side to a single point.
126+
pub fn fully_collapse(&self, fixed_bases: &BTreeMap<String, S::C>) -> (S::C, S::C) {
127+
(self.lhs.eval(fixed_bases), self.rhs.eval(fixed_bases))
128+
}
129+
124130
/// Accumulates several accumulators together. The resulting acc will
125131
/// satisfy the invariant iff all the accumulators individually do.
126132
pub fn accumulate(accs: &[Self]) -> Self {
@@ -293,6 +299,21 @@ impl<S: SelfEmulation> AssignedAccumulator<S> {
293299
self.rhs.collapse(layouter, curve_chip, scalar_chip)
294300
}
295301

302+
/// Evaluates the variable and fixed parts of the AssignedAccumulator
303+
/// collapsing each side to a single point.
304+
///
305+
/// This will likely be an expensive in-circuit operation.
306+
pub fn fully_collapse(
307+
&self,
308+
layouter: &mut impl Layouter<S::F>,
309+
curve_chip: &S::CurveChip,
310+
fixed_bases: &BTreeMap<String, S::C>,
311+
) -> Result<(S::AssignedPoint, S::AssignedPoint), Error> {
312+
let lhs_pt = self.lhs.eval(layouter, curve_chip, fixed_bases)?;
313+
let rhs_pt = self.rhs.eval(layouter, curve_chip, fixed_bases)?;
314+
Ok((lhs_pt, rhs_pt))
315+
}
316+
296317
/// Accumulates several accumulators together. The resulting acc will
297318
/// satisfy the invariant iff all the accumulators individually do.
298319
pub fn accumulate(

circuits/src/verifier/msm.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,34 @@ impl<S: SelfEmulation> AssignedMsm<S> {
485485
Ok(())
486486
}
487487

488+
/// Evaluates the variable and fixed base parts of the AssignedMsm
489+
/// collapsing it to a single point.
490+
///
491+
/// The fixed bases are constrained in-circuit to be fixed.
492+
pub fn eval(
493+
&self,
494+
layouter: &mut impl Layouter<S::F>,
495+
curve_chip: &S::CurveChip,
496+
fixed_bases: &BTreeMap<String, S::C>,
497+
) -> Result<S::AssignedPoint, Error> {
498+
let mut bases = self.bases.clone();
499+
let mut scalars = self.scalars.clone();
500+
501+
for (key, scalar) in self.fixed_base_scalars.iter() {
502+
let base = fixed_bases.get(key).expect("Base not provided: {key}");
503+
let fixed_base = curve_chip.assign_fixed(layouter, *base)?;
504+
bases.push(fixed_base);
505+
scalars.push(scalar.clone());
506+
}
507+
508+
let scalar_tuples = scalars
509+
.iter()
510+
.map(|s| (s.scalar.clone(), s.bound.bits() as usize))
511+
.collect::<Vec<_>>();
512+
513+
S::msm(layouter, curve_chip, &scalar_tuples, &bases)
514+
}
515+
488516
/// Scales all the scalars of the AssignedMsm by the given factor r.
489517
///
490518
/// This function mutates self.

0 commit comments

Comments
 (0)