@@ -11,7 +11,7 @@ use crate::{
11
11
error:: ZKVMError ,
12
12
expression:: { ToExpr , WitIn } ,
13
13
instructions:: {
14
- GKRIOPInstruction , Instruction ,
14
+ GKRIOPInstruction , GKRinfo , Instruction ,
15
15
riscv:: { constants:: UInt , insn_base:: WriteRD } ,
16
16
} ,
17
17
set_val,
@@ -21,10 +21,7 @@ use ff_ext::FieldInto;
21
21
22
22
use gkr_iop:: {
23
23
ProtocolWitnessGenerator ,
24
- precompiles:: {
25
- AND_LOOKUPS_PER_ROUND , KeccakLayout , KeccakTrace , RANGE_LOOKUPS_PER_ROUND ,
26
- XOR_LOOKUPS_PER_ROUND ,
27
- } ,
24
+ precompiles:: { AND_LOOKUPS , KeccakLayout , KeccakTrace , RANGE_LOOKUPS , XOR_LOOKUPS } ,
28
25
} ;
29
26
30
27
/// LargeEcallDummy can handle any instruction and produce its effects,
@@ -37,7 +34,7 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
37
34
type InstructionConfig = LargeEcallConfig < E > ;
38
35
39
36
fn name ( ) -> String {
40
- format ! ( "{}_DUMMY" , S :: NAME )
37
+ S :: NAME . to_owned ( )
41
38
}
42
39
fn construct_circuit ( cb : & mut CircuitBuilder < E > ) -> Result < Self :: InstructionConfig , ZKVMError > {
43
40
let dummy_insn = DummyConfig :: construct_circuit (
@@ -78,45 +75,9 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
78
75
} )
79
76
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
80
77
81
- // Temporarily set this to < 24 to avoid cb.num_witin overflow
82
- let active_rounds = 24 ;
83
-
84
- let mut lookups = Vec :: with_capacity (
85
- active_rounds
86
- * ( 3 * AND_LOOKUPS_PER_ROUND + 3 * XOR_LOOKUPS_PER_ROUND + RANGE_LOOKUPS_PER_ROUND ) ,
87
- ) ;
88
-
89
- let mut aux_wits = vec ! [ ] ;
90
-
91
- if S :: HAS_LOOKUPS {
92
- dbg ! ( lookups. capacity( ) ) ;
93
-
94
- for round in 0 ..active_rounds {
95
- for i in 0 ..AND_LOOKUPS_PER_ROUND {
96
- let a = cb. create_witin ( || format ! ( "and_lookup_{round}_{i}_a" ) ) ;
97
- let b = cb. create_witin ( || format ! ( "and_lookup_{round}_{i}_b" ) ) ;
98
- let c = cb. create_witin ( || format ! ( "and_lookup_{round}_{i}_c" ) ) ;
99
- cb. lookup_and_byte ( a. into ( ) , b. into ( ) , c. into ( ) ) ?;
100
- lookups. extend ( vec ! [ a, b, c] ) ;
101
- }
102
- for i in 0 ..XOR_LOOKUPS_PER_ROUND {
103
- let a = cb. create_witin ( || format ! ( "xor_lookup_{round}_{i}_a" ) ) ;
104
- let b = cb. create_witin ( || format ! ( "xor_lookup_{round}_{i}_b" ) ) ;
105
- let c = cb. create_witin ( || format ! ( "xor_lookup_{round}_{i}_c" ) ) ;
106
- cb. lookup_xor_byte ( a. into ( ) , b. into ( ) , c. into ( ) ) ?;
107
- lookups. extend ( vec ! [ a, b, c] ) ;
108
- }
109
- for i in 0 ..RANGE_LOOKUPS_PER_ROUND {
110
- let wit = cb. create_witin ( || format ! ( "range_lookup_{round}_{i}" ) ) ;
111
- cb. assert_ux :: < _ , _ , 16 > ( || "nada" , wit. into ( ) ) ?;
112
- lookups. push ( wit) ;
113
- }
114
- }
115
-
116
- for i in 0 ..40144 {
117
- aux_wits. push ( cb. create_witin ( || format ! ( "aux_wit{i}" ) ) ) ;
118
- }
119
- }
78
+ // Will be filled in by GKR Instruction trait
79
+ let lookups = vec ! [ ] ;
80
+ let aux_wits = vec ! [ ] ;
120
81
121
82
Ok ( LargeEcallConfig {
122
83
dummy_insn,
@@ -164,6 +125,57 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
164
125
impl < E : ExtensionField > GKRIOPInstruction < E > for LargeEcallDummy < E , KeccakSpec > {
165
126
type Layout = KeccakLayout < E > ;
166
127
128
+ fn gkr_info ( ) -> crate :: instructions:: GKRinfo {
129
+ GKRinfo {
130
+ and_lookups : 3 * AND_LOOKUPS ,
131
+ xor_lookups : 3 * XOR_LOOKUPS ,
132
+ range_lookups : RANGE_LOOKUPS ,
133
+ aux_wits : 40144 ,
134
+ }
135
+ }
136
+
137
+ fn construct_circuit_with_gkr_iop (
138
+ cb : & mut CircuitBuilder < E > ,
139
+ ) -> Result < Self :: InstructionConfig , ZKVMError > {
140
+ let mut partial_config = Self :: construct_circuit ( cb) ?;
141
+
142
+ assert ! ( partial_config. lookups. is_empty( ) ) ;
143
+ assert ! ( partial_config. aux_wits. is_empty( ) ) ;
144
+
145
+ // TODO: capacity
146
+ let mut lookups = vec ! [ ] ;
147
+ let mut aux_wits = vec ! [ ] ;
148
+
149
+ for i in 0 ..AND_LOOKUPS {
150
+ let a = cb. create_witin ( || format ! ( "and_lookup_{i}_a" ) ) ;
151
+ let b = cb. create_witin ( || format ! ( "and_lookup_{i}_b" ) ) ;
152
+ let c = cb. create_witin ( || format ! ( "and_lookup_{i}_c" ) ) ;
153
+ cb. lookup_and_byte ( a. into ( ) , b. into ( ) , c. into ( ) ) ?;
154
+ lookups. extend ( vec ! [ a, b, c] ) ;
155
+ }
156
+ for i in 0 ..XOR_LOOKUPS {
157
+ let a = cb. create_witin ( || format ! ( "xor_lookup_{i}_a" ) ) ;
158
+ let b = cb. create_witin ( || format ! ( "xor_lookup_{i}_b" ) ) ;
159
+ let c = cb. create_witin ( || format ! ( "xor_lookup_{i}_c" ) ) ;
160
+ cb. lookup_xor_byte ( a. into ( ) , b. into ( ) , c. into ( ) ) ?;
161
+ lookups. extend ( vec ! [ a, b, c] ) ;
162
+ }
163
+ for i in 0 ..RANGE_LOOKUPS {
164
+ let wit = cb. create_witin ( || format ! ( "range_lookup_{i}" ) ) ;
165
+ cb. assert_ux :: < _ , _ , 16 > ( || "nada" , wit. into ( ) ) ?;
166
+ lookups. push ( wit) ;
167
+ }
168
+
169
+ for i in 0 ..40144 {
170
+ aux_wits. push ( cb. create_witin ( || format ! ( "aux_wit{i}" ) ) ) ;
171
+ }
172
+
173
+ partial_config. lookups = lookups;
174
+ partial_config. aux_wits = aux_wits;
175
+
176
+ Ok ( partial_config)
177
+ }
178
+
167
179
fn phase1_witness_from_steps (
168
180
layout : & Self :: Layout ,
169
181
steps : & [ StepRecord ] ,
@@ -195,7 +207,6 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
195
207
) -> Result < ( ) , ZKVMError > {
196
208
Self :: assign_instance ( config, instance, lk_multiplicity, step) ?;
197
209
198
- let active_rounds = 24 ;
199
210
let mut wit_iter = lookups. iter ( ) . map ( |f| f. to_canonical_u64 ( ) ) ;
200
211
let mut var_iter = config. lookups . iter ( ) ;
201
212
@@ -206,29 +217,19 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
206
217
let wit = wit_iter. next ( ) . unwrap ( ) ;
207
218
let var = var_iter. next ( ) . unwrap ( ) ;
208
219
set_val ! ( instance, var, wit) ;
209
- // set_val!(instance, var, 0);
210
220
wit
211
221
} ;
212
222
213
- for _round in 0 ..active_rounds {
214
- for _i in 0 ..AND_LOOKUPS_PER_ROUND {
215
- lk_multiplicity. lookup_and_byte ( pop_arg ( ) , pop_arg ( ) ) ;
216
- // lk_multiplicity.lookup_and_byte(0, 0);
217
- // pop_arg();
218
- // pop_arg();
219
- pop_arg ( ) ;
220
- }
221
- for _i in 0 ..XOR_LOOKUPS_PER_ROUND {
222
- lk_multiplicity. lookup_xor_byte ( pop_arg ( ) , pop_arg ( ) ) ;
223
- // lk_multiplicity.lookup_xor_byte(0, 0);
224
- // pop_arg();
225
- // pop_arg();
226
- pop_arg ( ) ;
227
- }
228
- for _i in 0 ..RANGE_LOOKUPS_PER_ROUND {
229
- lk_multiplicity. assert_ux :: < 16 > ( pop_arg ( ) ) ;
230
- // pop_arg();
231
- }
223
+ for _i in 0 ..AND_LOOKUPS {
224
+ lk_multiplicity. lookup_and_byte ( pop_arg ( ) , pop_arg ( ) ) ;
225
+ pop_arg ( ) ;
226
+ }
227
+ for _i in 0 ..XOR_LOOKUPS {
228
+ lk_multiplicity. lookup_xor_byte ( pop_arg ( ) , pop_arg ( ) ) ;
229
+ pop_arg ( ) ;
230
+ }
231
+ for _i in 0 ..RANGE_LOOKUPS {
232
+ lk_multiplicity. assert_ux :: < 16 > ( pop_arg ( ) ) ;
232
233
}
233
234
234
235
dbg ! ( aux_wits. len( ) ) ;
0 commit comments