1
1
use ceno_emul:: StepRecord ;
2
2
use 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 } ;
8
4
use itertools:: Itertools ;
9
5
use multilinear_extensions:: util:: max_usable_threads;
10
6
use rayon:: {
@@ -87,31 +83,34 @@ impl GKRinfo {
87
83
}
88
84
}
89
85
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
90
91
pub trait GKRIOPInstruction < E : ExtensionField >
91
92
where
92
93
Self : Instruction < E > ,
93
94
{
94
95
type Layout : ProtocolWitnessGenerator < E > + ProtocolBuilder ;
95
96
97
+ /// Similar to Instruction::construct_circuit; generally
98
+ /// meant to extend InstructionConfig with GKR-specific
99
+ /// fields
100
+ #[ allow( unused_variables) ]
96
101
fn construct_circuit_with_gkr_iop (
97
102
cb : & mut CircuitBuilder < E > ,
98
103
) -> Result < Self :: InstructionConfig , ZKVMError > {
99
104
unimplemented ! ( ) ;
100
105
}
101
106
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
107
108
fn phase1_witness_from_steps (
108
109
layout : & Self :: Layout ,
109
110
steps : & [ StepRecord ] ,
110
111
) -> Vec < Vec < E :: BaseField > > ;
111
112
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
115
114
fn assign_instance_with_gkr_iop (
116
115
config : & Self :: InstructionConfig ,
117
116
instance : & mut [ E :: BaseField ] ,
@@ -121,6 +120,8 @@ where
121
120
aux_wits : & [ E :: BaseField ] ,
122
121
) -> Result < ( ) , ZKVMError > ;
123
122
123
+ /// Similar to Instruction::assign_instances, but with access to the GKR layout.
124
+ #[ allow( clippy:: type_complexity) ]
124
125
fn assign_instances_with_gkr_iop (
125
126
config : & Self :: InstructionConfig ,
126
127
num_witin : usize ,
@@ -146,10 +147,8 @@ where
146
147
RowMajorMatrix :: < E :: BaseField > :: new ( steps. len ( ) , num_witin, Self :: padding_strategy ( ) ) ;
147
148
let raw_witin_iter = raw_witin. par_batch_iter_mut ( num_instance_per_batch) ;
148
149
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) , & [ ] ) ;
153
152
154
153
let ( lookups, aux_wits) = {
155
154
// Extract lookups and auxiliary witnesses from GKR protocol
@@ -159,7 +158,10 @@ where
159
158
let mut lookups = vec ! [ vec![ ] ; steps. len( ) ] ;
160
159
let last_layer = gkr_witness. layers . last ( ) . unwrap ( ) . bases . clone ( ) ;
161
160
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
+ {
163
165
for i in 0 ..witness. len ( ) {
164
166
lookups[ i] . push ( witness[ i] ) ;
165
167
}
@@ -194,7 +196,6 @@ where
194
196
. chunks_mut ( num_witin)
195
197
. zip ( steps)
196
198
. map ( |( instance, ( i, step) ) | {
197
- // dbg!(i, step);
198
199
Self :: assign_instance_with_gkr_iop (
199
200
config,
200
201
instance,
@@ -211,4 +212,21 @@ where
211
212
raw_witin. padding_by_strategy ( ) ;
212
213
Ok ( ( raw_witin, gkr_witness, lk_multiplicity) )
213
214
}
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
+ }
214
232
}
0 commit comments