@@ -49,6 +49,7 @@ pub struct ZKVMChipProof<E: ExtensionField> {
4949
5050 pub tower_proof : TowerProofs < E > ,
5151
52+ pub num_instances : usize ,
5253 pub fixed_in_evals : Vec < E > ,
5354 pub wits_in_evals : Vec < E > ,
5455}
@@ -114,32 +115,25 @@ pub struct ZKVMProof<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> {
114115 pub raw_pi : Vec < Vec < E :: BaseField > > ,
115116 // the evaluation of raw_pi.
116117 pub pi_evals : Vec < E > ,
117- // circuit size -> instance mapping
118- pub num_instances : Vec < ( usize , usize ) > ,
119- opcode_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
120- table_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
118+ chip_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
121119 witin_commit : <PCS as PolynomialCommitmentScheme < E > >:: Commitment ,
122- pub fixed_witin_opening_proof : PCS :: Proof ,
120+ pub opening_proof : PCS :: Proof ,
123121}
124122
125123impl < E : ExtensionField , PCS : PolynomialCommitmentScheme < E > > ZKVMProof < E , PCS > {
126124 pub fn new (
127125 raw_pi : Vec < Vec < E :: BaseField > > ,
128126 pi_evals : Vec < E > ,
129- opcode_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
130- table_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
127+ chip_proofs : BTreeMap < usize , ZKVMChipProof < E > > ,
131128 witin_commit : <PCS as PolynomialCommitmentScheme < E > >:: Commitment ,
132- fixed_witin_opening_proof : PCS :: Proof ,
133- num_instances : Vec < ( usize , usize ) > ,
129+ opening_proof : PCS :: Proof ,
134130 ) -> Self {
135131 Self {
136132 raw_pi,
137133 pi_evals,
138- opcode_proofs,
139- table_proofs,
134+ chip_proofs,
140135 witin_commit,
141- fixed_witin_opening_proof,
142- num_instances,
136+ opening_proof,
143137 }
144138 }
145139
@@ -164,23 +158,19 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProof<E, PCS> {
164158 }
165159
166160 pub fn num_circuits ( & self ) -> usize {
167- self . opcode_proofs . len ( ) + self . table_proofs . len ( )
161+ self . chip_proofs . len ( )
168162 }
169163
170164 pub fn has_halt ( & self , vk : & ZKVMVerifyingKey < E , PCS > ) -> bool {
165+ let halt_circuit_index = vk
166+ . circuit_vks
167+ . keys ( )
168+ . position ( |circuit_name| * circuit_name == HaltInstruction :: < E > :: name ( ) )
169+ . expect ( "halt circuit not exist" ) ;
171170 let halt_instance_count = self
172- . num_instances
173- . iter ( )
174- . find_map ( |( circuit_index, num_instances) | {
175- ( * circuit_index
176- == vk
177- . circuit_vks
178- . keys ( )
179- . position ( |circuit_name| * circuit_name == HaltInstruction :: < E > :: name ( ) )
180- . expect ( "halt circuit not exist" ) )
181- . then_some ( * num_instances)
182- } )
183- . unwrap_or ( 0 ) ;
171+ . chip_proofs
172+ . get ( & halt_circuit_index)
173+ . map_or ( 0 , |proof| proof. num_instances ) ;
184174 if halt_instance_count > 0 {
185175 assert_eq ! (
186176 halt_instance_count, 1 ,
@@ -203,39 +193,11 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
203193 let mpcs_opcode_commitment =
204194 bincode:: serialized_size ( & self . witin_commit ) . expect ( "serialization error" ) ;
205195 let mpcs_opcode_opening =
206- bincode:: serialized_size ( & self . fixed_witin_opening_proof ) . expect ( "serialization error" ) ;
196+ bincode:: serialized_size ( & self . opening_proof ) . expect ( "serialization error" ) ;
207197
208- // opcode circuit for tower proof size
209- let tower_proof_opcode = self
210- . opcode_proofs
211- . iter ( )
212- . map ( |( circuit_index, proof) | {
213- let size = bincode:: serialized_size ( & proof. tower_proof ) ;
214- size. inspect ( |size| {
215- * by_circuitname_stats. entry ( circuit_index) . or_insert ( 0 ) += size;
216- } )
217- } )
218- . collect :: < Result < Vec < u64 > , _ > > ( )
219- . expect ( "serialization error" )
220- . iter ( )
221- . sum :: < u64 > ( ) ;
222- // opcode circuit main sumcheck
223- let main_sumcheck_opcode = self
224- . opcode_proofs
225- . iter ( )
226- . map ( |( circuit_index, proof) | {
227- let size = bincode:: serialized_size ( & proof. main_sumcheck_proofs ) ;
228- size. inspect ( |size| {
229- * by_circuitname_stats. entry ( circuit_index) . or_insert ( 0 ) += size;
230- } )
231- } )
232- . collect :: < Result < Vec < u64 > , _ > > ( )
233- . expect ( "serialization error" )
234- . iter ( )
235- . sum :: < u64 > ( ) ;
236- // table circuit for tower proof size
237- let tower_proof_table = self
238- . table_proofs
198+ // tower proof size
199+ let tower_proof = self
200+ . chip_proofs
239201 . iter ( )
240202 . map ( |( circuit_index, proof) | {
241203 let size = bincode:: serialized_size ( & proof. tower_proof ) ;
@@ -247,9 +209,9 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
247209 . expect ( "serialization error" )
248210 . iter ( )
249211 . sum :: < u64 > ( ) ;
250- // table circuit same r sumcheck
251- let same_r_sumcheck_table = self
252- . table_proofs
212+ // main sumcheck
213+ let main_sumcheck = self
214+ . chip_proofs
253215 . iter ( )
254216 . map ( |( circuit_index, proof) | {
255217 let size = bincode:: serialized_size ( & proof. main_sumcheck_proofs ) ;
@@ -286,20 +248,16 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E> + Serialize> fmt::Dis
286248 "overall_size {:.2}mb. \n \
287249 mpcs commitment {:?}% \n \
288250 mpcs opening {:?}% \n \
289- opcode tower proof {:?}% \n \
290- opcode main sumcheck proof {:?}% \n \
291- table tower proof {:?}% \n \
292- table same r sumcheck proof {:?}% \n \n \
251+ tower proof {:?}% \n \
252+ main sumcheck proof {:?}% \n \
293253 by circuit_name break down: \n \
294254 {}
295255 " ,
296256 byte_to_mb( overall_size) ,
297257 ( mpcs_opcode_commitment * 100 ) . div( overall_size) ,
298258 ( mpcs_opcode_opening * 100 ) . div( overall_size) ,
299- ( tower_proof_opcode * 100 ) . div( overall_size) ,
300- ( main_sumcheck_opcode * 100 ) . div( overall_size) ,
301- ( tower_proof_table * 100 ) . div( overall_size) ,
302- ( same_r_sumcheck_table * 100 ) . div( overall_size) ,
259+ ( tower_proof * 100 ) . div( overall_size) ,
260+ ( main_sumcheck * 100 ) . div( overall_size) ,
303261 by_circuitname_stats,
304262 )
305263 }
0 commit comments