@@ -8,15 +8,14 @@ use ark_ff::PrimeField;
8
8
use ark_poly:: { univariate:: DensePolynomial , EvaluationDomain , GeneralEvaluationDomain } ;
9
9
use ark_r1cs_std:: {
10
10
alloc:: AllocVar ,
11
- boolean:: Boolean ,
12
11
eq:: EqGadget ,
13
12
fields:: { fp:: FpVar , FieldVar } ,
14
13
groups:: { CurveVar , GroupOpsBounds } ,
15
14
poly:: polynomial:: univariate:: dense:: DensePolynomialVar ,
16
15
R1CSVar , ToBitsGadget , ToConstraintFieldGadget ,
17
16
} ;
18
17
use ark_relations:: r1cs:: { ConstraintSynthesizer , ConstraintSystemRef , SynthesisError } ;
19
- use ark_std:: { fmt:: Debug , marker:: PhantomData , One , Zero } ;
18
+ use ark_std:: { fmt:: Debug , marker:: PhantomData , Zero } ;
20
19
21
20
use super :: {
22
21
folding:: lagrange_polys,
@@ -29,7 +28,7 @@ use crate::{
29
28
CycleFoldChallengeGadget , CycleFoldCommittedInstance , CycleFoldCommittedInstanceVar ,
30
29
CycleFoldConfig , NIFSFullGadget ,
31
30
} ,
32
- nonnative:: { affine:: NonNativeAffineVar , uint :: NonNativeUintVar } ,
31
+ nonnative:: affine:: NonNativeAffineVar ,
33
32
CF1 , CF2 ,
34
33
} ,
35
34
frontend:: FCircuit ,
@@ -165,7 +164,7 @@ impl AugmentationGadget {
165
164
Ok ( ( U , L_X_evals ) )
166
165
}
167
166
168
- pub fn prepare_and_fold_cyclefold <
167
+ pub fn fold_cyclefold <
169
168
C1 : CurveGroup < BaseField = C2 :: ScalarField , ScalarField = C2 :: BaseField > ,
170
169
C2 : CurveGroup ,
171
170
GC2 : CurveVar < C2 , CF2 < C2 > > + ToConstraintFieldGadget < CF2 < C2 > > ,
@@ -174,32 +173,19 @@ impl AugmentationGadget {
174
173
transcript : & mut PoseidonSpongeVar < CF1 < C1 > > ,
175
174
pp_hash : FpVar < CF1 < C1 > > ,
176
175
mut cf_U : CycleFoldCommittedInstanceVar < C2 , GC2 > ,
177
- cf_u_cmWs : Vec < GC2 > ,
178
- cf_u_xs : Vec < Vec < NonNativeUintVar < CF1 < C1 > > > > ,
176
+ cf_us : Vec < CycleFoldCommittedInstanceVar < C2 , GC2 > > ,
179
177
cf_cmTs : Vec < GC2 > ,
180
178
) -> Result < CycleFoldCommittedInstanceVar < C2 , GC2 > , SynthesisError >
181
179
where
182
180
C2 :: BaseField : PrimeField + Absorb ,
183
181
for < ' a > & ' a GC2 : GroupOpsBounds < ' a , C2 , GC2 > ,
184
182
{
185
- assert_eq ! ( cf_u_cmWs. len( ) , cf_u_xs. len( ) ) ;
186
- assert_eq ! ( cf_u_xs. len( ) , cf_cmTs. len( ) ) ;
183
+ assert_eq ! ( cf_us. len( ) , cf_cmTs. len( ) ) ;
187
184
188
185
// Fold the incoming CycleFold instances into the running CycleFold
189
186
// instance in a iterative way, since `NIFSFullGadget` only supports
190
187
// folding one incoming instance at a time.
191
- for ( ( cmW, x) , cmT) in cf_u_cmWs. into_iter ( ) . zip ( cf_u_xs) . zip ( cf_cmTs) {
192
- // Prepare the incoming CycleFold instance `cf_u` for the current
193
- // iteration.
194
- // For each CycleFold instance `cf_u`, we have `cf_u.cmE = 0`, and
195
- // `cf_u.u = 1`.
196
- let cf_u = CycleFoldCommittedInstanceVar {
197
- cmE : GC2 :: zero ( ) ,
198
- u : NonNativeUintVar :: new_constant ( ConstraintSystemRef :: None , C1 :: BaseField :: one ( ) ) ?,
199
- cmW,
200
- x,
201
- } ;
202
-
188
+ for ( cf_u, cmT) in cf_us. into_iter ( ) . zip ( cf_cmTs) {
203
189
let cf_r_bits = CycleFoldChallengeGadget :: get_challenge_gadget (
204
190
transcript,
205
191
pp_hash. clone ( ) ,
@@ -401,63 +387,33 @@ where
401
387
402
388
// CycleFold part
403
389
// C.1. Compute cf1_u_i.x and cf2_u_i.x
404
- let mut r0_bits = r[ 0 ] . to_bits_le ( ) ?;
405
- let mut r1_bits = r[ 1 ] . to_bits_le ( ) ?;
406
- r0_bits. resize ( C1 :: ScalarField :: MODULUS_BIT_SIZE as usize , Boolean :: FALSE ) ;
407
- r1_bits. resize ( C1 :: ScalarField :: MODULUS_BIT_SIZE as usize , Boolean :: FALSE ) ;
408
- let cf1_x = [
409
- r0_bits
410
- . chunks ( C1 :: BaseField :: MODULUS_BIT_SIZE as usize - 1 )
411
- . map ( |bits| {
412
- let mut bits = bits. to_vec ( ) ;
413
- bits. resize ( C1 :: BaseField :: MODULUS_BIT_SIZE as usize , Boolean :: FALSE ) ;
414
- NonNativeUintVar :: from ( & bits)
415
- } )
416
- . collect :: < Vec < _ > > ( ) ,
417
- vec ! [
418
- NonNativeUintVar :: new_constant( cs. clone( ) , C1 :: BaseField :: zero( ) ) ?,
419
- NonNativeUintVar :: new_constant( cs. clone( ) , C1 :: BaseField :: zero( ) ) ?,
420
- U_i . phi. x. clone( ) ,
421
- U_i . phi. y. clone( ) ,
422
- phi_stars[ 0 ] . x. clone( ) ,
423
- phi_stars[ 0 ] . y. clone( ) ,
424
- ] ,
425
- ]
426
- . concat ( ) ;
427
- let cf2_x = [
428
- r1_bits
429
- . chunks ( C1 :: BaseField :: MODULUS_BIT_SIZE as usize - 1 )
430
- . map ( |bits| {
431
- let mut bits = bits. to_vec ( ) ;
432
- bits. resize ( C1 :: BaseField :: MODULUS_BIT_SIZE as usize , Boolean :: FALSE ) ;
433
- NonNativeUintVar :: from ( & bits)
434
- } )
435
- . collect :: < Vec < _ > > ( ) ,
436
- vec ! [
437
- phi_stars[ 0 ] . x. clone( ) ,
438
- phi_stars[ 0 ] . y. clone( ) ,
439
- u_i_phi. x. clone( ) ,
440
- u_i_phi. y. clone( ) ,
441
- U_i1 . phi. x. clone( ) ,
442
- U_i1 . phi. y. clone( ) ,
443
- ] ,
444
- ]
445
- . concat ( ) ;
446
-
447
- // C.2. Prepare incoming CycleFold instances
448
- // C.3. Fold incoming CycleFold instances into the running instance
449
- let cf_U_i1 =
450
- AugmentationGadget :: prepare_and_fold_cyclefold :: < C1 , C2 , GC2 , PoseidonSponge < CF1 < C1 > > > (
451
- & mut transcript,
452
- pp_hash. clone ( ) ,
453
- cf_U_i,
454
- vec ! [
455
- GC2 :: new_witness( cs. clone( ) , || Ok ( self . cf1_u_i_cmW) ) ?,
456
- GC2 :: new_witness( cs. clone( ) , || Ok ( self . cf2_u_i_cmW) ) ?,
457
- ] ,
458
- vec ! [ cf1_x, cf2_x] ,
459
- vec ! [ cf1_cmT, cf2_cmT] ,
390
+ // C.2. Construct `cf1_u_i` and `cf2_u_i`
391
+ let cf1_u: CycleFoldCommittedInstanceVar < C2 , GC2 > =
392
+ CycleFoldCommittedInstanceVar :: new_incoming_from_components (
393
+ // `cf1_u_i.cmW` is provided by the prover as witness.
394
+ GC2 :: new_witness ( cs. clone ( ) , || Ok ( self . cf1_u_i_cmW ) ) ?,
395
+ // The computation of `cf1_u_i.x` requires the randomness `r[0]`, the
396
+ // commitments `phi` in CommittedInstances, and `phi_stars[0]`.
397
+ & r[ 0 ] . to_bits_le ( ) ?,
398
+ vec ! [ NonNativeAffineVar :: zero( ) , U_i . phi, phi_stars[ 0 ] . clone( ) ] ,
460
399
) ?;
400
+ let cf2_u = CycleFoldCommittedInstanceVar :: new_incoming_from_components (
401
+ // `cf2_u_i.cmW` is provided by the prover as witness.
402
+ GC2 :: new_witness ( cs. clone ( ) , || Ok ( self . cf2_u_i_cmW ) ) ?,
403
+ // The computation of `cf2_u_i.x` requires the randomness `r[1]`, the
404
+ // commitments `phi` in CommittedInstances, and `phi_stars[0]`.
405
+ & r[ 1 ] . to_bits_le ( ) ?,
406
+ vec ! [ phi_stars[ 0 ] . clone( ) , u_i_phi, U_i1 . phi] ,
407
+ ) ?;
408
+
409
+ // C.3. Fold incoming CycleFold instances into the running instance
410
+ let cf_U_i1 = AugmentationGadget :: fold_cyclefold :: < C1 , C2 , GC2 , PoseidonSponge < CF1 < C1 > > > (
411
+ & mut transcript,
412
+ pp_hash. clone ( ) ,
413
+ cf_U_i,
414
+ vec ! [ cf1_u, cf2_u] ,
415
+ vec ! [ cf1_cmT, cf2_cmT] ,
416
+ ) ?;
461
417
462
418
// Back to Primary Part
463
419
// P.4.b compute and check the second output of F'
0 commit comments