Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Commit

Permalink
Aggregator Fix (#348)
Browse files Browse the repository at this point in the history
Co-authored-by: lazovicff <[email protected]>
  • Loading branch information
ozgurarmanc and lazovicff authored Sep 5, 2023
1 parent c826552 commit 9048c3c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
6 changes: 5 additions & 1 deletion eigentrust-zk/src/ecc/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ where
) -> AssignedEcPoint<C, N, NUM_LIMBS, NUM_BITS, P> {
Self { x, y }
}

/// Checks if given point is at the infinity or not
pub fn is_infinity(&self) -> bool {
self.x.integer == Integer::zero() && self.y.integer == Integer::zero()
}
}

/// Chipset structure for the EccAdd.
Expand Down Expand Up @@ -1468,7 +1473,6 @@ mod test {
);

let ecc_table_select = EccTableSelectConfig::new(main);

let ecc_mul = EccMulConfig::new(
ecc_ladder.clone(),
ecc_add.clone(),
Expand Down
11 changes: 10 additions & 1 deletion eigentrust-zk/src/ecc/generic/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ where
Self { x, y, _ec: PhantomData }
}

/// Create a new object with x = 0 and y = 0
pub fn zero() -> Self {
Self::new(Integer::zero(), Integer::zero())
}

/// Checks if given point is at the infinity or not
pub fn is_infinity(&self) -> bool {
self == &EcPoint::zero()
}

/// Selection function for the table
fn select(bit: bool, table: [Self; 2]) -> Self {
if bit {
Expand Down Expand Up @@ -165,7 +175,6 @@ where
/// Scalar multiplication for given point with using ladder
pub fn mul_scalar(&self, scalar: Integer<C::ScalarExt, N, NUM_LIMBS, NUM_BITS, P>) -> Self {
let (aux_init, aux_fin) = Self::aux(1);

let exp = self.clone();
// Converts given input to its bit by Scalar Field's bit size
let mut bits = Vec::new();
Expand Down
15 changes: 11 additions & 4 deletions eigentrust-zk/src/ecc/same_curve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
use crate::{
gadgets::{
bits2num::Bits2NumChip,
main::{IsEqualChipset, SelectChipset},
main::{AndChipset, SelectChipset},
},
integer::{
native::Integer, AssignedInteger, IntegerAddChip, IntegerAssigner, IntegerDivChip,
Expand Down Expand Up @@ -123,6 +123,11 @@ where
) -> AssignedEcPoint<C, NUM_LIMBS, NUM_BITS, P> {
Self { x, y }
}

/// Checks if given point is at the infinity or not
pub fn is_infinity(&self) -> bool {
self.x.integer == Integer::zero() && self.y.integer == Integer::zero()
}
}

/// Chipset structure for the EccAdd.
Expand Down Expand Up @@ -424,6 +429,7 @@ where
}
}

#[derive(Debug)]
struct EccEqualChipset<C: CurveAffine, const NUM_LIMBS: usize, const NUM_BITS: usize, P>
where
P: RnsParams<C::Base, C::Scalar, NUM_LIMBS, NUM_BITS>,
Expand Down Expand Up @@ -467,10 +473,12 @@ where
self, common: &CommonConfig, config: &Self::Config, mut layouter: impl Layouter<C::Scalar>,
) -> Result<Self::Output, Error> {
let x_eq = IntegerEqualChipset::new(self.p.x, self.q.x);
let is_x_eq = x_eq.synthesize(common, &config.int_eq, layouter.namespace(|| "x_eq"))?;
let y_eq = IntegerEqualChipset::new(self.p.y, self.q.y);

let is_x_eq = x_eq.synthesize(common, &config.int_eq, layouter.namespace(|| "x_eq"))?;
let is_y_eq = y_eq.synthesize(common, &config.int_eq, layouter.namespace(|| "y_eq"))?;
let point_eq = IsEqualChipset::new(is_x_eq, is_y_eq);

let point_eq = AndChipset::new(is_x_eq, is_y_eq);
let is_point_eq =
point_eq.synthesize(common, &config.main, layouter.namespace(|| "point_eq"))?;

Expand Down Expand Up @@ -1285,7 +1293,6 @@ mod test {
);

let ecc_table_select = EccTableSelectConfig::new(main);

let ecc_mul = EccMulConfig::new(
ecc_ladder.clone(),
ecc_add.clone(),
Expand Down
9 changes: 7 additions & 2 deletions eigentrust-zk/src/ecc/same_curve/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ where
Self { x, y, _ec: PhantomData }
}

/// Create a new object with x = 0 and y = 1
/// Create a new object with x = 0 and y = 0
pub fn zero() -> Self {
Self::new(Integer::zero(), Integer::one())
Self::new(Integer::zero(), Integer::zero())
}

/// Checks if given point is at the infinity or not
pub fn is_infinity(&self) -> bool {
self == &EcPoint::zero()
}

/// Create a new object with x = 1 and y = 1
Expand Down
2 changes: 1 addition & 1 deletion eigentrust-zk/src/ecdsa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ mod test {
integer_add_selector, integer_sub_selector, integer_mul_selector,
integer_div_selector,
);
let ecc_table_select = EccTableSelectConfig::new(main.clone());
let ecc_table_select = EccTableSelectConfig::new(main);
let ecc_mul_scalar = EccMulConfig::new(
ecc_ladder.clone(),
ecc_add.clone(),
Expand Down
9 changes: 4 additions & 5 deletions eigentrust-zk/src/verifier/aggregator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,16 +432,15 @@ mod test {
) -> Result<(), Error> {
let aggregator_chipset =
AggregatorChipset::new(self.svk, self.snarks.clone(), self.as_proof.clone());
let _accumulator_limbs = aggregator_chipset.synthesize(
let accumulator_limbs = aggregator_chipset.synthesize(
&config.common,
&config.aggregator,
layouter.namespace(|| "aggregator chipset"),
)?;

// TODO: Uncomment when the bug is fixed
// for (row, inst) in accumulator_limbs.enumerate() {
// layouter.constrain_instance(inst.cell(), config.common.instance, row)?;
// }
for (row, inst) in accumulator_limbs.iter().enumerate() {
layouter.constrain_instance(inst.cell(), config.common.instance, row)?;
}
Ok(())
}
}
Expand Down
1 change: 1 addition & 0 deletions eigentrust-zk/src/verifier/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ where
let point = pairs
.iter()
.cloned()
.filter(|(_, base)| !base.inner.is_infinity())
.map(|(scalar, base)| {
let config = base.loader.clone();
let aux = base.loader.aux.clone();
Expand Down
1 change: 1 addition & 0 deletions eigentrust-zk/src/verifier/loader/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ where
let point = pairs
.iter()
.cloned()
.filter(|(_, base)| !base.inner.is_infinity())
.map(|(scalar, base)| {
let new = scalar.clone();
base.inner.mul_scalar(new.inner)
Expand Down

0 comments on commit 9048c3c

Please sign in to comment.