3535use super :: mpt;
3636use super :: CtrlTransitionKind ;
3737use crate :: operation:: { Account , AccountOp , KeyValue } ;
38+ use halo2_proofs:: ff:: FromUniformBytes ;
39+ use halo2_proofs:: ff:: PrimeField ;
3840use halo2_proofs:: {
39- arithmetic:: FieldExt ,
4041 circuit:: { Chip , Region , Value } ,
4142 plonk:: { Advice , Column , ConstraintSystem , Error , Expression , Selector } ,
4243 poly:: Rotation ,
@@ -79,7 +80,7 @@ impl AccountGadget {
7980 /// + circuit selector * 1
8081 /// + exported col * 8 (MUST by following sequence: layout_flag, s_enable, old_val, new_val, key_val and 3 ext field for old/new/key_val)
8182 /// + free col * 4
82- pub fn configure < Fp : FieldExt > (
83+ pub fn configure < Fp : PrimeField + FromUniformBytes < 64 > + Ord > (
8384 meta : & mut ConstraintSystem < Fp > ,
8485 sel : Selector ,
8586 exported : & [ Column < Advice > ] ,
@@ -126,7 +127,7 @@ impl AccountGadget {
126127 //transition
127128 meta. lookup ( "account row trans" , |meta| {
128129 let s_enable = meta. query_advice ( s_enable, Rotation :: cur ( ) )
129- * ( Expression :: Constant ( Fp :: one ( ) )
130+ * ( Expression :: Constant ( Fp :: ONE )
130131 - meta. query_advice ( s_ctrl_type[ 0 ] , Rotation :: cur ( ) ) ) ;
131132
132133 tables. build_lookup (
@@ -184,7 +185,7 @@ impl AccountGadget {
184185 let is_diff_ext_boolean =
185186 data_ext_diff.clone() * meta.query_advice(state_change_aux[1], Rotation::cur());
186187
187- let one = Expression::Constant(Fp::one() );
188+ let one = Expression::Constant(Fp::ONE );
188189 // switch A || B to ! (!A ^ !B)
189190 let has_diff = one.clone()
190191 - (one.clone() - is_diff_boolean.clone())
@@ -217,7 +218,7 @@ impl AccountGadget {
217218 s_enable
218219 * row0
219220 * (new_nonce.clone() - old_nonce.clone())
220- * (new_nonce - old_nonce - Expression::Constant(Fp::one() )),
221+ * (new_nonce - old_nonce - Expression::Constant(Fp::ONE )),
221222 ]
222223 });*/
223224
@@ -250,7 +251,7 @@ impl AccountGadget {
250251 }
251252
252253 /// assign data and enable flag for account circuit
253- pub fn assign < ' d , Fp : FieldExt > (
254+ pub fn assign < ' d , Fp : PrimeField < Repr = [ u8 ; 32 ] > + FromUniformBytes < 64 > + Ord > (
254255 & self ,
255256 region : & mut Region < ' _ , Fp > ,
256257 offset : usize ,
@@ -298,7 +299,7 @@ impl AccountGadget {
298299 || "enable account circuit" ,
299300 self . s_enable ,
300301 offset,
301- || Value :: known ( Fp :: one ( ) ) ,
302+ || Value :: known ( Fp :: ONE ) ,
302303 ) ?;
303304 region. assign_advice (
304305 || "account circuit rows" ,
@@ -310,31 +311,31 @@ impl AccountGadget {
310311 || "enable s_ctrl" ,
311312 self . s_ctrl_type [ index] ,
312313 offset,
313- || Value :: known ( Fp :: one ( ) ) ,
314+ || Value :: known ( Fp :: ONE ) ,
314315 ) ?;
315316 if index == LAST_ROW {
316317 region. assign_advice (
317318 || "padding last row" ,
318319 self . old_state . intermediate_2 ,
319320 offset,
320- || Value :: known ( Fp :: zero ( ) ) ,
321+ || Value :: known ( Fp :: ZERO ) ,
321322 ) ?;
322323
323324 region. assign_advice (
324325 || "padding last row" ,
325326 self . new_state . intermediate_2 ,
326327 offset,
327- || Value :: known ( Fp :: zero ( ) ) ,
328+ || Value :: known ( Fp :: ZERO ) ,
328329 ) ?;
329330 }
330331 let data_delta = match index {
331- 0 => [ data. 0 . nonce - data. 1 . nonce , Fp :: zero ( ) ] ,
332- 1 => [ data. 0 . balance - data. 1 . balance , Fp :: zero ( ) ] ,
332+ 0 => [ data. 0 . nonce - data. 1 . nonce , Fp :: ZERO ] ,
333+ 1 => [ data. 0 . balance - data. 1 . balance , Fp :: ZERO ] ,
333334 2 => [
334335 data. 0 . codehash . 0 - data. 1 . codehash . 0 ,
335336 data. 0 . codehash . 1 - data. 1 . codehash . 1 ,
336337 ] ,
337- 3 => [ data. 0 . state_root - data. 1 . state_root , Fp :: zero ( ) ] ,
338+ 3 => [ data. 0 . state_root - data. 1 . state_root , Fp :: ZERO ] ,
338339 _ => unreachable ! ( "no such row number" ) ,
339340 } ;
340341
@@ -350,7 +351,7 @@ impl AccountGadget {
350351 offset,
351352 || {
352353 Value :: known ( if bool:: from ( val. is_zero ( ) ) {
353- Fp :: zero ( )
354+ Fp :: ZERO
354355 } else {
355356 val. invert ( ) . unwrap ( )
356357 } )
@@ -362,13 +363,7 @@ impl AccountGadget {
362363 || "is data delta" ,
363364 self . state_change_key ,
364365 offset,
365- || {
366- Value :: known ( if has_data_delta {
367- Fp :: one ( )
368- } else {
369- Fp :: zero ( )
370- } )
371- } ,
366+ || Value :: known ( if has_data_delta { Fp :: ONE } else { Fp :: ZERO } ) ,
372367 ) ?;
373368 }
374369
@@ -391,7 +386,7 @@ struct AccountChip<'d, F> {
391386 data : & ' d Account < F > ,
392387}
393388
394- impl < Fp : FieldExt > Chip < Fp > for AccountChip < ' _ , Fp > {
389+ impl < Fp : PrimeField + FromUniformBytes < 64 > + Ord > Chip < Fp > for AccountChip < ' _ , Fp > {
395390 type Config = AccountChipConfig ;
396391 type Loaded = Account < Fp > ;
397392
@@ -404,7 +399,7 @@ impl<Fp: FieldExt> Chip<Fp> for AccountChip<'_, Fp> {
404399 }
405400}
406401
407- impl < ' d , Fp : FieldExt > AccountChip < ' d , Fp > {
402+ impl < ' d , Fp : PrimeField + FromUniformBytes < 64 > + Ord > AccountChip < ' d , Fp > {
408403 fn lagrange_polynomial_for_row < const T : usize > ( ref_n : Expression < Fp > ) -> Expression < Fp > {
409404 super :: lagrange_polynomial :: < Fp , T , LAST_ROW > ( ref_n)
410405 }
@@ -510,7 +505,7 @@ impl<'d, Fp: FieldExt> AccountChip<'d, Fp> {
510505 ) ,
511506 (
512507 config. acc_data_fields_ext ,
513- [ Fp :: zero ( ) , Fp :: zero ( ) , data. codehash . 1 ] ,
508+ [ Fp :: ZERO , Fp :: ZERO , data. codehash . 1 ] ,
514509 "data field ext" ,
515510 ) ,
516511 (
@@ -520,7 +515,7 @@ impl<'d, Fp: FieldExt> AccountChip<'d, Fp> {
520515 ) ,
521516 (
522517 config. intermediate_1 ,
523- [ Fp :: zero ( ) , data. hash_traces ( 2 ) , data. hash_traces ( 0 ) ] ,
518+ [ Fp :: ZERO , data. hash_traces ( 2 ) , data. hash_traces ( 0 ) ] ,
524519 "intermedia 1" ,
525520 ) ,
526521 ] {
@@ -545,7 +540,7 @@ impl<'d, Fp: FieldExt> AccountChip<'d, Fp> {
545540 || "state root padding" ,
546541 config. acc_data_fields_ext ,
547542 self . offset + LAST_ROW ,
548- || Value :: known ( Fp :: zero ( ) ) ,
543+ || Value :: known ( Fp :: ZERO ) ,
549544 ) ?;
550545
551546 Ok ( self . offset + LAST_ROW )
@@ -565,7 +560,7 @@ struct StorageChip<'d, F> {
565560 value : Option < KeyValue < F > > ,
566561}
567562
568- impl < ' d , Fp : FieldExt > StorageChip < ' d , Fp > {
563+ impl < ' d , Fp : PrimeField < Repr = [ u8 ; 32 ] > + FromUniformBytes < 64 > + Ord > StorageChip < ' d , Fp > {
569564 fn configure (
570565 meta : & mut ConstraintSystem < Fp > ,
571566 _sel : Selector ,
@@ -593,14 +588,14 @@ impl<'d, Fp: FieldExt> StorageChip<'d, Fp> {
593588 || "val limb 0" ,
594589 config. v_limbs [ 0 ] ,
595590 self . offset ,
596- || Value :: known ( self . value . as_ref ( ) . map_or_else ( Fp :: zero , |v| v. limb_0 ( ) ) ) ,
591+ || Value :: known ( self . value . as_ref ( ) . map_or ( Fp :: ZERO , |v| v. limb_0 ( ) ) ) ,
597592 ) ?;
598593
599594 region. assign_advice (
600595 || "val limb 1" ,
601596 config. v_limbs [ 1 ] ,
602597 self . offset ,
603- || Value :: known ( self . value . as_ref ( ) . map_or_else ( Fp :: zero , |v| v. limb_1 ( ) ) ) ,
598+ || Value :: known ( self . value . as_ref ( ) . map_or ( Fp :: ZERO , |v| v. limb_1 ( ) ) ) ,
604599 ) ?;
605600
606601 Ok ( self . offset + 1 )
@@ -630,7 +625,7 @@ impl StorageGadget {
630625 /// + circuit selector * 1
631626 /// + exported col * 5 (MUST by following sequence: layout_flag, s_enable, old_val, new_val, key_val)
632627 /// + free col * 4
633- pub fn configure < Fp : FieldExt > (
628+ pub fn configure < Fp : PrimeField < Repr = [ u8 ; 32 ] > + FromUniformBytes < 64 > + Ord > (
634629 meta : & mut ConstraintSystem < Fp > ,
635630 sel : Selector ,
636631 exported : & [ Column < Advice > ] ,
@@ -671,7 +666,7 @@ impl StorageGadget {
671666 [ ] . into_iter ( )
672667 }
673668
674- pub fn assign < Fp : FieldExt > (
669+ pub fn assign < Fp : PrimeField < Repr = [ u8 ; 32 ] > + FromUniformBytes < 64 > + Ord > (
675670 & self ,
676671 region : & mut Region < ' _ , Fp > ,
677672 offset : usize ,
@@ -681,21 +676,21 @@ impl StorageGadget {
681676 || "enable storage leaf circuit" ,
682677 self . s_enable ,
683678 offset,
684- || Value :: known ( Fp :: one ( ) ) ,
679+ || Value :: known ( Fp :: ONE ) ,
685680 ) ?;
686681
687682 region. assign_advice (
688683 || "storage leaf circuit row" ,
689684 self . ctrl_type ,
690685 offset,
691- || Value :: known ( Fp :: zero ( ) ) ,
686+ || Value :: known ( Fp :: ZERO ) ,
692687 ) ?;
693688
694689 region. assign_advice (
695690 || "enable s_ctrl" ,
696691 self . s_ctrl_type ,
697692 offset,
698- || Value :: known ( Fp :: one ( ) ) ,
693+ || Value :: known ( Fp :: ONE ) ,
699694 ) ?;
700695
701696 for ( config, value) in [
@@ -815,7 +810,7 @@ mod test {
815810 || "flush top row" ,
816811 col,
817812 0 ,
818- || Value :: known ( Fp :: zero ( ) ) ,
813+ || Value :: known ( Fp :: ZERO ) ,
819814 ) ?;
820815 }
821816
@@ -825,7 +820,7 @@ mod test {
825820 || "flush s_ctrl" ,
826821 col,
827822 offset,
828- || Value :: known ( Fp :: zero ( ) ) ,
823+ || Value :: known ( Fp :: ZERO ) ,
829824 ) ?;
830825 }
831826 }
@@ -845,7 +840,7 @@ mod test {
845840 || "flush last row" ,
846841 col,
847842 till,
848- || Value :: known ( Fp :: zero ( ) ) ,
843+ || Value :: known ( Fp :: ZERO ) ,
849844 ) ?;
850845 }
851846 Ok ( ( ) )
0 commit comments