@@ -8,15 +8,13 @@ use crate::poly::opening_proof::{
88use crate :: poly:: split_eq_poly:: GruenSplitEqPolynomial ;
99use crate :: poly:: unipoly:: UniPoly ;
1010use crate :: subprotocols:: sumcheck_prover:: SumcheckInstanceProver ;
11- use crate :: subprotocols:: sumcheck_verifier:: SumcheckInstanceVerifier ;
11+ use crate :: subprotocols:: sumcheck_verifier:: { SumcheckInstanceParams , SumcheckInstanceVerifier } ;
1212use crate :: transcripts:: Transcript ;
13- use crate :: utils:: math:: Math ;
1413use crate :: zkvm:: witness:: VirtualPolynomial ;
1514use allocative:: Allocative ;
1615#[ cfg( feature = "allocative" ) ]
1716use allocative:: FlameGraphBuilder ;
1817use rayon:: prelude:: * ;
19- use std:: marker:: PhantomData ;
2018use tracer:: instruction:: Cycle ;
2119
2220// RAM Hamming booleanity sumcheck
@@ -30,53 +28,74 @@ use tracer::instruction::Cycle;
3028/// Degree bound of the sumcheck round polynomials in [`HammingBooleanitySumcheckVerifier`].
3129const DEGREE_BOUND : usize = 3 ;
3230
31+ #[ derive( Allocative ) ]
32+ pub struct HammingBooleanityParams < F : JoltField > {
33+ r_cycle : OpeningPoint < BIG_ENDIAN , F > ,
34+ }
35+
36+ impl < F : JoltField > HammingBooleanityParams < F > {
37+ pub fn new ( opening_accumulator : & dyn OpeningAccumulator < F > ) -> Self {
38+ let ( r_cycle, _) = opening_accumulator. get_virtual_polynomial_opening (
39+ VirtualPolynomial :: LookupOutput ,
40+ SumcheckId :: SpartanOuter ,
41+ ) ;
42+
43+ Self { r_cycle }
44+ }
45+ }
46+
47+ impl < F : JoltField > SumcheckInstanceParams < F > for HammingBooleanityParams < F > {
48+ fn degree ( & self ) -> usize {
49+ DEGREE_BOUND
50+ }
51+
52+ fn num_rounds ( & self ) -> usize {
53+ self . r_cycle . len ( )
54+ }
55+
56+ fn input_claim ( & self , _: & dyn OpeningAccumulator < F > ) -> F {
57+ F :: zero ( )
58+ }
59+
60+ fn normalize_opening_point (
61+ & self ,
62+ challenges : & [ <F as JoltField >:: Challenge ] ,
63+ ) -> OpeningPoint < BIG_ENDIAN , F > {
64+ OpeningPoint :: < LITTLE_ENDIAN , F > :: new ( challenges. to_vec ( ) ) . match_endianness ( )
65+ }
66+ }
67+
3368#[ derive( Allocative ) ]
3469pub struct HammingBooleanitySumcheckProver < F : JoltField > {
3570 eq_r_cycle : GruenSplitEqPolynomial < F > ,
3671 H : MultilinearPolynomial < F > ,
37- log_T : usize ,
72+ params : HammingBooleanityParams < F > ,
3873}
3974
4075impl < F : JoltField > HammingBooleanitySumcheckProver < F > {
41- #[ tracing:: instrument( skip_all, name = "RamHammingBooleanitySumcheckProver::gen" ) ]
42- pub fn gen ( trace : & [ Cycle ] , opening_accumulator : & ProverOpeningAccumulator < F > ) -> Self {
43- let T = trace. len ( ) ;
44- let log_T = T . log_2 ( ) ;
45-
76+ #[ tracing:: instrument( skip_all, name = "RamHammingBooleanitySumcheckProver::initialize" ) ]
77+ pub fn initialize ( params : HammingBooleanityParams < F > , trace : & [ Cycle ] ) -> Self {
4678 let H = trace
4779 . par_iter ( )
4880 . map ( |cycle| cycle. ram_access ( ) . address ( ) != 0 )
4981 . collect :: < Vec < bool > > ( ) ;
5082 let H = MultilinearPolynomial :: from ( H ) ;
5183
52- let ( r_cycle, _) = opening_accumulator. get_virtual_polynomial_opening (
53- VirtualPolynomial :: LookupOutput ,
54- SumcheckId :: SpartanOuter ,
55- ) ;
56-
57- let eq_r_cycle = GruenSplitEqPolynomial :: new ( & r_cycle. r , BindingOrder :: LowToHigh ) ;
84+ let eq_r_cycle = GruenSplitEqPolynomial :: new ( & params. r_cycle . r , BindingOrder :: LowToHigh ) ;
5885
5986 Self {
6087 eq_r_cycle,
6188 H ,
62- log_T ,
89+ params ,
6390 }
6491 }
6592}
6693
6794impl < F : JoltField , T : Transcript > SumcheckInstanceProver < F , T >
6895 for HammingBooleanitySumcheckProver < F >
6996{
70- fn degree ( & self ) -> usize {
71- DEGREE_BOUND
72- }
73-
74- fn num_rounds ( & self ) -> usize {
75- self . log_T
76- }
77-
78- fn input_claim ( & self , _accumulator : & ProverOpeningAccumulator < F > ) -> F {
79- F :: zero ( )
97+ fn get_params ( & self ) -> Box < & dyn SumcheckInstanceParams < F > > {
98+ Box :: new ( & self . params )
8099 }
81100
82101 #[ tracing:: instrument( skip_all, name = "RamHammingBooleanitySumcheckProver::compute_message" ) ]
@@ -113,7 +132,7 @@ impl<F: JoltField, T: Transcript> SumcheckInstanceProver<F, T>
113132 transcript,
114133 VirtualPolynomial :: RamHammingWeight ,
115134 SumcheckId :: RamHammingBooleanity ,
116- get_opening_point ( sumcheck_challenges) ,
135+ self . params . normalize_opening_point ( sumcheck_challenges) ,
117136 self . H . final_sumcheck_claim ( ) ,
118137 ) ;
119138 }
@@ -125,33 +144,22 @@ impl<F: JoltField, T: Transcript> SumcheckInstanceProver<F, T>
125144}
126145
127146pub struct HammingBooleanitySumcheckVerifier < F : JoltField > {
128- log_T : usize ,
129- _phantom : PhantomData < F > ,
147+ params : HammingBooleanityParams < F > ,
130148}
131149
132150impl < F : JoltField > HammingBooleanitySumcheckVerifier < F > {
133- pub fn new ( n_cycle_vars : usize ) -> Self {
151+ pub fn new ( opening_accumulator : & dyn OpeningAccumulator < F > ) -> Self {
134152 Self {
135- // TODO: Make the name for this consistent across the codebase.
136- log_T : n_cycle_vars,
137- _phantom : PhantomData ,
153+ params : HammingBooleanityParams :: new ( opening_accumulator) ,
138154 }
139155 }
140156}
141157
142158impl < F : JoltField , T : Transcript > SumcheckInstanceVerifier < F , T >
143159 for HammingBooleanitySumcheckVerifier < F >
144160{
145- fn degree ( & self ) -> usize {
146- DEGREE_BOUND
147- }
148-
149- fn num_rounds ( & self ) -> usize {
150- self . log_T
151- }
152-
153- fn input_claim ( & self , _accumulator : & VerifierOpeningAccumulator < F > ) -> F {
154- F :: zero ( )
161+ fn get_params ( & self ) -> Box < & dyn SumcheckInstanceParams < F > > {
162+ Box :: new ( & self . params )
155163 }
156164
157165 fn expected_output_claim (
@@ -194,13 +202,7 @@ impl<F: JoltField, T: Transcript> SumcheckInstanceVerifier<F, T>
194202 transcript,
195203 VirtualPolynomial :: RamHammingWeight ,
196204 SumcheckId :: RamHammingBooleanity ,
197- get_opening_point ( sumcheck_challenges) ,
205+ self . params . normalize_opening_point ( sumcheck_challenges) ,
198206 ) ;
199207 }
200208}
201-
202- fn get_opening_point < F : JoltField > (
203- sumcheck_challenges : & [ F :: Challenge ] ,
204- ) -> OpeningPoint < BIG_ENDIAN , F > {
205- OpeningPoint :: < LITTLE_ENDIAN , F > :: new ( sumcheck_challenges. to_vec ( ) ) . match_endianness ( )
206- }
0 commit comments