11use ceno_emul:: StepRecord ;
22use ff_ext:: ExtensionField ;
3- use gkr_iop:: {
4- ProtocolBuilder , ProtocolWitnessGenerator ,
5- gkr:: { GKRCircuitWitness , layer:: LayerWitness } ,
6- precompiles:: KeccakLayout ,
7- } ;
3+ use gkr_iop:: { ProtocolBuilder , ProtocolWitnessGenerator , gkr:: GKRCircuitWitness } ;
84use itertools:: Itertools ;
95use multilinear_extensions:: util:: max_usable_threads;
106use rayon:: {
@@ -87,31 +83,34 @@ impl GKRinfo {
8783 }
8884}
8985
86+ // Trait that should be implemented by opcodes which use the
87+ // GKR-IOP prover. Presently, such opcodes should also implement
88+ // the Instruction trait and in general methods of GKRIOPInstruction
89+ // will call corresponding methods of Instruction and do something extra
90+ // with respect to syncing state between GKR-IOP and old-style circuits/witnesses
9091pub trait GKRIOPInstruction < E : ExtensionField >
9192where
9293 Self : Instruction < E > ,
9394{
9495 type Layout : ProtocolWitnessGenerator < E > + ProtocolBuilder ;
9596
97+ /// Similar to Instruction::construct_circuit; generally
98+ /// meant to extend InstructionConfig with GKR-specific
99+ /// fields
100+ #[ allow( unused_variables) ]
96101 fn construct_circuit_with_gkr_iop (
97102 cb : & mut CircuitBuilder < E > ,
98103 ) -> Result < Self :: InstructionConfig , ZKVMError > {
99104 unimplemented ! ( ) ;
100105 }
101106
102- // Returns index of `i-th` GKR-IOP output-eval in PCS
103- fn output_map ( i : usize ) -> usize {
104- unimplemented ! ( ) ;
105- }
106-
107+ /// Should generate phase1 witness for GKR from step records
107108 fn phase1_witness_from_steps (
108109 layout : & Self :: Layout ,
109110 steps : & [ StepRecord ] ,
110111 ) -> Vec < Vec < E :: BaseField > > ;
111112
112- // Number of lookup arguments used by this GKR proof
113- fn gkr_info ( ) -> GKRinfo ;
114-
113+ /// Similar to Instruction::assign_instance, but with access to GKR lookups and wits
115114 fn assign_instance_with_gkr_iop (
116115 config : & Self :: InstructionConfig ,
117116 instance : & mut [ E :: BaseField ] ,
@@ -121,6 +120,8 @@ where
121120 aux_wits : & [ E :: BaseField ] ,
122121 ) -> Result < ( ) , ZKVMError > ;
123122
123+ /// Similar to Instruction::assign_instances, but with access to the GKR layout.
124+ #[ allow( clippy:: type_complexity) ]
124125 fn assign_instances_with_gkr_iop (
125126 config : & Self :: InstructionConfig ,
126127 num_witin : usize ,
@@ -146,10 +147,8 @@ where
146147 RowMajorMatrix :: < E :: BaseField > :: new ( steps. len ( ) , num_witin, Self :: padding_strategy ( ) ) ;
147148 let raw_witin_iter = raw_witin. par_batch_iter_mut ( num_instance_per_batch) ;
148149
149- let gkr_witness = gkr_layout. gkr_witness (
150- & Self :: phase1_witness_from_steps ( gkr_layout, & steps) ,
151- & vec ! [ ] ,
152- ) ;
150+ let gkr_witness =
151+ gkr_layout. gkr_witness ( & Self :: phase1_witness_from_steps ( gkr_layout, & steps) , & [ ] ) ;
153152
154153 let ( lookups, aux_wits) = {
155154 // Extract lookups and auxiliary witnesses from GKR protocol
@@ -159,7 +158,10 @@ where
159158 let mut lookups = vec ! [ vec![ ] ; steps. len( ) ] ;
160159 let last_layer = gkr_witness. layers . last ( ) . unwrap ( ) . bases . clone ( ) ;
161160 let len = last_layer. len ( ) ;
162- for witness in last_layer[ len - Self :: gkr_info ( ) . lookup_total ( ) ..] . iter ( ) {
161+ for witness in last_layer
162+ . iter ( )
163+ . skip ( len - Self :: gkr_info ( ) . lookup_total ( ) )
164+ {
163165 for i in 0 ..witness. len ( ) {
164166 lookups[ i] . push ( witness[ i] ) ;
165167 }
@@ -194,7 +196,6 @@ where
194196 . chunks_mut ( num_witin)
195197 . zip ( steps)
196198 . map ( |( instance, ( i, step) ) | {
197- // dbg!(i, step);
198199 Self :: assign_instance_with_gkr_iop (
199200 config,
200201 instance,
@@ -211,4 +212,21 @@ where
211212 raw_witin. padding_by_strategy ( ) ;
212213 Ok ( ( raw_witin, gkr_witness, lk_multiplicity) )
213214 }
215+
216+ /// Lookup and witness counts used by GKR proof
217+ fn gkr_info ( ) -> GKRinfo ;
218+
219+ /// Returns corresponding column in RMM for the i-th
220+ /// output evaluation of the GKR proof
221+ #[ allow( unused_variables) ]
222+ fn output_evals_map ( i : usize ) -> usize {
223+ unimplemented ! ( ) ;
224+ }
225+
226+ /// Returns corresponding column in RMM for the i-th
227+ /// witness of the GKR proof
228+ #[ allow( unused_variables) ]
229+ fn witness_map ( i : usize ) -> usize {
230+ unimplemented ! ( ) ;
231+ }
214232}
0 commit comments