@@ -11,7 +11,7 @@ use crate::{
1111 error:: ZKVMError ,
1212 expression:: { ToExpr , WitIn } ,
1313 instructions:: {
14- GKRIOPInstruction , Instruction ,
14+ GKRIOPInstruction , GKRinfo , Instruction ,
1515 riscv:: { constants:: UInt , insn_base:: WriteRD } ,
1616 } ,
1717 set_val,
@@ -21,10 +21,7 @@ use ff_ext::FieldInto;
2121
2222use gkr_iop:: {
2323 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 } ,
2825} ;
2926
3027/// LargeEcallDummy can handle any instruction and produce its effects,
@@ -37,7 +34,7 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
3734 type InstructionConfig = LargeEcallConfig < E > ;
3835
3936 fn name ( ) -> String {
40- format ! ( "{}_DUMMY" , S :: NAME )
37+ S :: NAME . to_owned ( )
4138 }
4239 fn construct_circuit ( cb : & mut CircuitBuilder < E > ) -> Result < Self :: InstructionConfig , ZKVMError > {
4340 let dummy_insn = DummyConfig :: construct_circuit (
@@ -78,45 +75,9 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
7875 } )
7976 . collect :: < Result < Vec < _ > , _ > > ( ) ?;
8077
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 ! [ ] ;
12081
12182 Ok ( LargeEcallConfig {
12283 dummy_insn,
@@ -164,6 +125,57 @@ impl<E: ExtensionField, S: SyscallSpec> Instruction<E> for LargeEcallDummy<E, S>
164125impl < E : ExtensionField > GKRIOPInstruction < E > for LargeEcallDummy < E , KeccakSpec > {
165126 type Layout = KeccakLayout < E > ;
166127
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+
167179 fn phase1_witness_from_steps (
168180 layout : & Self :: Layout ,
169181 steps : & [ StepRecord ] ,
@@ -195,7 +207,6 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
195207 ) -> Result < ( ) , ZKVMError > {
196208 Self :: assign_instance ( config, instance, lk_multiplicity, step) ?;
197209
198- let active_rounds = 24 ;
199210 let mut wit_iter = lookups. iter ( ) . map ( |f| f. to_canonical_u64 ( ) ) ;
200211 let mut var_iter = config. lookups . iter ( ) ;
201212
@@ -206,29 +217,19 @@ impl<E: ExtensionField> GKRIOPInstruction<E> for LargeEcallDummy<E, KeccakSpec>
206217 let wit = wit_iter. next ( ) . unwrap ( ) ;
207218 let var = var_iter. next ( ) . unwrap ( ) ;
208219 set_val ! ( instance, var, wit) ;
209- // set_val!(instance, var, 0);
210220 wit
211221 } ;
212222
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 ( ) ) ;
232233 }
233234
234235 dbg ! ( aux_wits. len( ) ) ;
0 commit comments