From 5451a3201660109d57a116578f7b4642e4432e20 Mon Sep 17 00:00:00 2001 From: Timofey Luin Date: Wed, 3 Apr 2024 18:56:40 +0200 Subject: [PATCH] Revert "Avoid unexpected infinity when aggregating pub keys (#65)" This reverts commit 98a9362f961802cfb20b52e166880094da29815f. --- lightclient-circuits/src/sync_step_circuit.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lightclient-circuits/src/sync_step_circuit.rs b/lightclient-circuits/src/sync_step_circuit.rs index f85d4ecd..b3f0eeb0 100644 --- a/lightclient-circuits/src/sync_step_circuit.rs +++ b/lightclient-circuits/src/sync_step_circuit.rs @@ -294,7 +294,7 @@ impl StepCircuit { fp_chip: &FpChip<'_, F>, pubkey_affines: &[G1Affine], pariticipation_bits: &[bool], - assigned_affines: &mut Vec>, + assigned_pubkeys: &mut Vec>, y_signs_packed: &mut Vec>, ) -> (G1Point, AssignedValue) { let gate = fp_chip.gate(); @@ -330,22 +330,17 @@ impl StepCircuit { fp_chip.limb_bases[1], ); - assigned_affines.push(assigned_affine); + assigned_pubkeys.push(assigned_affine); participation_bits.push(participation_bit); y_signs.push(y_sign); } - let mut acc = { - let x = fp_chip.load_constant(ctx, G1Affine::identity().x); - let y = fp_chip.load_constant(ctx, G1Affine::identity().y); - G1Point::new(x, y) // identity - }; - acc = g1_chip.select(ctx, assigned_affines[0].clone(), acc, participation_bits[0]); + let rand_point = g1_chip.load_random_point::(ctx); + let mut acc = rand_point.clone(); for (bit, point) in participation_bits .iter() .copied() - .zip(assigned_affines.iter_mut()) - .skip(1) + .zip(assigned_pubkeys.iter_mut()) { let is_equal = g1_chip.is_equal(ctx, acc.clone(), point.clone()); let add = g1_chip.add_unequal(ctx, acc.clone(), point.clone(), true); @@ -353,6 +348,7 @@ impl StepCircuit { let sum = g1_chip.select(ctx, doub, add, is_equal); acc = g1_chip.select(ctx, sum, acc, bit); } + let agg_pubkey = g1_chip.sub_unequal(ctx, acc, rand_point, false); let participation_sum = gate.sum(ctx, participation_bits); *y_signs_packed = y_signs @@ -360,7 +356,7 @@ impl StepCircuit { .map(|chunk| gate.bits_to_num(ctx, chunk)) .collect_vec(); - (acc, participation_sum) + (agg_pubkey, participation_sum) } }