@@ -12,7 +12,7 @@ use sumcheck::structs::IOPProverMessage;
12
12
13
13
use crate :: {
14
14
instructions:: { Instruction , riscv:: ecall:: HaltInstruction } ,
15
- structs:: TowerProofs ,
15
+ structs:: { TowerProofs , ZKVMVerifyingKey } ,
16
16
} ;
17
17
18
18
pub mod constants;
@@ -70,9 +70,6 @@ pub struct ZKVMTableProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>>
70
70
71
71
pub tower_proof : TowerProofs < E > ,
72
72
73
- // num_vars hint for rw dynamic address to work
74
- pub rw_hints_num_vars : Vec < usize > ,
75
-
76
73
pub fixed_in_evals : Vec < E > ,
77
74
pub fixed_opening_proof : Option < PCS :: Proof > ,
78
75
pub wits_commit : PCS :: Commitment ,
@@ -143,8 +140,8 @@ pub struct ZKVMProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
143
140
pub pi_evals : Vec < E > ,
144
141
// circuit size -> instance mapping
145
142
pub num_instances : Vec < ( usize , usize ) > ,
146
- opcode_proofs : BTreeMap < String , ( usize , ZKVMOpcodeProof < E , PCS > ) > ,
147
- table_proofs : BTreeMap < String , ( usize , ZKVMTableProof < E , PCS > ) > ,
143
+ opcode_proofs : BTreeMap < usize , ZKVMOpcodeProof < E , PCS > > ,
144
+ table_proofs : BTreeMap < usize , ZKVMTableProof < E , PCS > > ,
148
145
}
149
146
150
147
impl < E : ExtensionField , PCS : PolynomialCommitmentScheme < E > > ZKVMProof < E , PCS > {
@@ -166,6 +163,7 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
166
163
Self {
167
164
raw_pi,
168
165
pi_evals,
166
+ num_instances : vec ! [ ] ,
169
167
opcode_proofs : BTreeMap :: new ( ) ,
170
168
table_proofs : BTreeMap :: new ( ) ,
171
169
}
@@ -179,11 +177,19 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
179
177
self . opcode_proofs . len ( ) + self . table_proofs . len ( )
180
178
}
181
179
182
- pub fn has_halt ( & self ) -> bool {
180
+ pub fn has_halt ( & self , vk : & ZKVMVerifyingKey < E , PCS > ) -> bool {
183
181
let halt_instance_count = self
184
- . opcode_proofs
185
- . get ( & HaltInstruction :: < E > :: name ( ) )
186
- . map ( |( _, p) | p. num_instances )
182
+ . num_instances
183
+ . iter ( )
184
+ . find_map ( |( circuit_index, num_instances) | {
185
+ ( * circuit_index
186
+ == vk
187
+ . circuit_vks
188
+ . keys ( )
189
+ . position ( |circuit_name| * circuit_name == HaltInstruction :: < E > :: name ( ) )
190
+ . expect ( "halt circuit not exist" ) )
191
+ . then_some ( * num_instances)
192
+ } )
187
193
. unwrap_or ( 0 ) ;
188
194
if halt_instance_count > 0 {
189
195
assert_eq ! (
@@ -207,10 +213,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
207
213
let mpcs_opcode_commitment = self
208
214
. opcode_proofs
209
215
. iter ( )
210
- . map ( |( circuit_name , ( _ , proof) ) | {
216
+ . map ( |( circuit_index , proof) | {
211
217
let size = bincode:: serialized_size ( & proof. wits_commit ) ;
212
218
size. inspect ( |size| {
213
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
219
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
214
220
} )
215
221
} )
216
222
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -220,10 +226,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
220
226
let mpcs_opcode_opening = self
221
227
. opcode_proofs
222
228
. iter ( )
223
- . map ( |( circuit_name , ( _ , proof) ) | {
229
+ . map ( |( circuit_index , proof) | {
224
230
let size = bincode:: serialized_size ( & proof. wits_opening_proof ) ;
225
231
size. inspect ( |size| {
226
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
232
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
227
233
} )
228
234
} )
229
235
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -234,10 +240,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
234
240
let tower_proof_opcode = self
235
241
. opcode_proofs
236
242
. iter ( )
237
- . map ( |( circuit_name , ( _ , proof) ) | {
243
+ . map ( |( circuit_index , proof) | {
238
244
let size = bincode:: serialized_size ( & proof. tower_proof ) ;
239
245
size. inspect ( |size| {
240
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
246
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
241
247
} )
242
248
} )
243
249
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -248,10 +254,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
248
254
let main_sumcheck_opcode = self
249
255
. opcode_proofs
250
256
. iter ( )
251
- . map ( |( circuit_name , ( _ , proof) ) | {
257
+ . map ( |( circuit_index , proof) | {
252
258
let size = bincode:: serialized_size ( & proof. main_sel_sumcheck_proofs ) ;
253
259
size. inspect ( |size| {
254
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
260
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
255
261
} )
256
262
} )
257
263
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -262,10 +268,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
262
268
let mpcs_table_commitment = self
263
269
. table_proofs
264
270
. iter ( )
265
- . map ( |( circuit_name , ( _ , proof) ) | {
271
+ . map ( |( circuit_index , proof) | {
266
272
let size = bincode:: serialized_size ( & proof. wits_commit ) ;
267
273
size. inspect ( |size| {
268
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
274
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
269
275
} )
270
276
} )
271
277
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -275,10 +281,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
275
281
let mpcs_table_opening = self
276
282
. table_proofs
277
283
. iter ( )
278
- . map ( |( circuit_name , ( _ , proof) ) | {
284
+ . map ( |( circuit_index , proof) | {
279
285
let size = bincode:: serialized_size ( & proof. wits_opening_proof ) ;
280
286
size. inspect ( |size| {
281
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
287
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
282
288
} )
283
289
} )
284
290
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -288,10 +294,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
288
294
let mpcs_table_fixed_opening = self
289
295
. table_proofs
290
296
. iter ( )
291
- . map ( |( circuit_name , ( _ , proof) ) | {
297
+ . map ( |( circuit_index , proof) | {
292
298
let size = bincode:: serialized_size ( & proof. fixed_opening_proof ) ;
293
299
size. inspect ( |size| {
294
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
300
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
295
301
} )
296
302
} )
297
303
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -302,10 +308,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
302
308
let tower_proof_table = self
303
309
. table_proofs
304
310
. iter ( )
305
- . map ( |( circuit_name , ( _ , proof) ) | {
311
+ . map ( |( circuit_index , proof) | {
306
312
let size = bincode:: serialized_size ( & proof. tower_proof ) ;
307
313
size. inspect ( |size| {
308
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
314
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
309
315
} )
310
316
} )
311
317
. collect :: < Result < Vec < u64 > , _ > > ( )
@@ -316,10 +322,10 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
316
322
let same_r_sumcheck_table = self
317
323
. table_proofs
318
324
. iter ( )
319
- . map ( |( circuit_name , ( _ , proof) ) | {
325
+ . map ( |( circuit_index , proof) | {
320
326
let size = bincode:: serialized_size ( & proof. same_r_sumcheck_proofs ) ;
321
327
size. inspect ( |size| {
322
- * by_circuitname_stats. entry ( circuit_name ) . or_insert ( 0 ) += size;
328
+ * by_circuitname_stats. entry ( circuit_index ) . or_insert ( 0 ) += size;
323
329
} )
324
330
} )
325
331
. collect :: < Result < Vec < u64 > , _ > > ( )
0 commit comments