11use std:: { borrow:: Borrow , sync:: Arc } ;
22
33use ceno_emul:: { FullTracer as Tracer , WORD_SIZE } ;
4- use ceno_zkvm:: instructions:: riscv:: constants:: {
5- END_CYCLE_IDX , END_PC_IDX , EXIT_CODE_IDX , EXIT_PC , HEAP_LENGTH_IDX , HEAP_START_ADDR_IDX ,
6- HINT_LENGTH_IDX , HINT_START_ADDR_IDX , INIT_CYCLE_IDX , INIT_PC_IDX , PUBIO_DIGEST_IDX ,
7- SHARD_ID_IDX , SHARD_RW_SUM_IDX ,
4+ use ceno_zkvm:: {
5+ instructions:: riscv:: constants:: {
6+ END_CYCLE_IDX , END_PC_IDX , EXIT_CODE_IDX , EXIT_PC , HEAP_LENGTH_IDX , HEAP_START_ADDR_IDX ,
7+ HINT_LENGTH_IDX , HINT_START_ADDR_IDX , INIT_CYCLE_IDX , INIT_PC_IDX , PUBIO_DIGEST_IDX ,
8+ SHARD_ID_IDX , SHARD_RW_SUM_IDX ,
9+ } ,
10+ scheme:: PublicValues ,
811} ;
912use openvm_circuit_primitives:: utils:: { and, assert_array_eq, not} ;
1013use openvm_stark_backend:: {
@@ -21,7 +24,11 @@ use stark_recursion_circuit_derive::AlignedBorrow;
2124
2225use crate :: {
2326 bus:: { LookupChallengeBus , LookupChallengeKind , LookupChallengeMessage } ,
24- circuit:: inner:: { bus:: PvsAirConsistencyBus , vm_pvs:: VmPvs } ,
27+ circuit:: inner:: {
28+ bus:: { PvsAirConsistencyBus , PvsAirConsistencyMessage } ,
29+ vm_pvs:: VmPvs ,
30+ } ,
31+ utils:: TranscriptLabel ,
2532} ;
2633
2734#[ repr( C ) ]
@@ -35,6 +42,9 @@ pub struct VmPvsCols<F> {
3542 pub lookup_challenge_beta : [ F ; D_EF ] ,
3643 pub lookup_challenge_alpha_lookup_count : F ,
3744 pub lookup_challenge_beta_lookup_count : F ,
45+ pub fixed_commit_log2_max_codeword_size : F ,
46+ pub fixed_no_omc_init_commit_log2_max_codeword_size : F ,
47+ pub witness_commit_log2_max_codeword_size : F ,
3848 pub child_pvs : VmPvs < F > ,
3949}
4050
@@ -45,6 +55,8 @@ pub struct VmPvsAir {
4555 pub lookup_challenge_bus : LookupChallengeBus ,
4656 pub pvs_air_consistency_bus : PvsAirConsistencyBus ,
4757 pub deferral_enabled : bool ,
58+ pub has_fixed_commit : bool ,
59+ pub has_fixed_no_omc_init_commit : bool ,
4860 pub instance_public_value_indices : Arc < Vec < Vec < usize > > > ,
4961}
5062
@@ -189,41 +201,60 @@ impl<AB: AirBuilder + InteractionBuilder + AirBuilderWithPublicValues> Air<AB> f
189201 // );
190202
191203 // Commitments are observed after transcript-visible public values in preflight.
192- let start_tidx_after_public_value = VmPvs :: < u8 > :: width ( ) - 3 * DIGEST_SIZE ;
193- for ( didx, value) in local. child_pvs . fixed_commit . iter ( ) . enumerate ( ) {
194- self . transcript_bus . receive (
204+ let mut commit_tidx = TranscriptLabel :: Riscv . field_len ( ) + PublicValues :: flattened_len ( ) ;
205+ if self . has_fixed_commit {
206+ receive_commitment (
207+ self ,
195208 builder,
196209 local. proof_idx ,
197- TranscriptBusMessage {
198- tidx : AB :: Expr :: from_usize ( start_tidx_after_public_value + didx) ,
199- value : ( * value) . into ( ) ,
200- is_sample : AB :: Expr :: ZERO ,
201- } ,
210+ commit_tidx,
211+ local. child_pvs . fixed_commit ,
212+ local. fixed_commit_log2_max_codeword_size ,
202213 local. is_valid ,
203214 ) ;
215+ commit_tidx += DIGEST_SIZE + 1 ;
204216 }
205- for ( didx, value) in local. child_pvs . fixed_no_omc_init_commit . iter ( ) . enumerate ( ) {
217+ if self . has_fixed_no_omc_init_commit {
218+ receive_commitment (
219+ self ,
220+ builder,
221+ local. proof_idx ,
222+ commit_tidx,
223+ local. child_pvs . fixed_no_omc_init_commit ,
224+ local. fixed_no_omc_init_commit_log2_max_codeword_size ,
225+ local. is_valid ,
226+ ) ;
227+ commit_tidx += DIGEST_SIZE + 1 ;
228+ }
229+ receive_commitment (
230+ self ,
231+ builder,
232+ local. proof_idx ,
233+ commit_tidx,
234+ local. child_pvs . witness_commit ,
235+ local. witness_commit_log2_max_codeword_size ,
236+ local. is_valid ,
237+ ) ;
238+ commit_tidx += DIGEST_SIZE + 1 ;
239+
240+ for i in 0 ..D_EF {
206241 self . transcript_bus . receive (
207242 builder,
208243 local. proof_idx ,
209244 TranscriptBusMessage {
210- tidx : AB :: Expr :: from_usize ( start_tidx_after_public_value + DIGEST_SIZE + didx ) ,
211- value : ( * value ) . into ( ) ,
212- is_sample : AB :: Expr :: ZERO ,
245+ tidx : AB :: Expr :: from_usize ( commit_tidx + i ) ,
246+ value : local . lookup_challenge_alpha [ i ] . into ( ) ,
247+ is_sample : AB :: Expr :: ONE ,
213248 } ,
214249 local. is_valid ,
215250 ) ;
216- }
217- for ( didx, value) in local. child_pvs . witness_commit . iter ( ) . enumerate ( ) {
218251 self . transcript_bus . receive (
219252 builder,
220253 local. proof_idx ,
221254 TranscriptBusMessage {
222- tidx : AB :: Expr :: from_usize (
223- start_tidx_after_public_value + 2 * DIGEST_SIZE + didx,
224- ) ,
225- value : ( * value) . into ( ) ,
226- is_sample : AB :: Expr :: ZERO ,
255+ tidx : AB :: Expr :: from_usize ( commit_tidx + D_EF + i) ,
256+ value : local. lookup_challenge_beta [ i] . into ( ) ,
257+ is_sample : AB :: Expr :: ONE ,
227258 } ,
228259 local. is_valid ,
229260 ) ;
@@ -253,15 +284,15 @@ impl<AB: AirBuilder + InteractionBuilder + AirBuilderWithPublicValues> Air<AB> f
253284 }
254285
255286 // We look up proof metadata from VerifierPvsAir here to ensure consistency on each row.
256- // self.pvs_air_consistency_bus.lookup_key(
257- // builder,
258- // local.proof_idx,
259- // PvsAirConsistencyMessage {
260- // deferral_flag,
261- // has_verifier_pvs: local.has_verifier_pvs.into(),
262- // },
263- // local.is_valid,
264- // );
287+ self . pvs_air_consistency_bus . lookup_key (
288+ builder,
289+ local. proof_idx ,
290+ PvsAirConsistencyMessage {
291+ deferral_flag,
292+ has_verifier_pvs : local. has_verifier_pvs . into ( ) ,
293+ } ,
294+ local. is_valid ,
295+ ) ;
265296
266297 // Finally, constrain that this AIR's output public values are consistent with child_pvs.
267298 let & VmPvs :: < _ > {
@@ -383,6 +414,41 @@ where
383414 }
384415}
385416
417+ fn receive_commitment < AB > (
418+ air : & VmPvsAir ,
419+ builder : & mut AB ,
420+ proof_idx : AB :: Var ,
421+ start_tidx : usize ,
422+ commit : [ AB :: Var ; DIGEST_SIZE ] ,
423+ log2_max_codeword_size : AB :: Var ,
424+ mult : AB :: Var ,
425+ ) where
426+ AB : AirBuilder + InteractionBuilder + AirBuilderWithPublicValues ,
427+ {
428+ for ( didx, value) in commit. into_iter ( ) . enumerate ( ) {
429+ air. transcript_bus . receive (
430+ builder,
431+ proof_idx,
432+ TranscriptBusMessage {
433+ tidx : AB :: Expr :: from_usize ( start_tidx + didx) ,
434+ value : value. into ( ) ,
435+ is_sample : AB :: Expr :: ZERO ,
436+ } ,
437+ mult,
438+ ) ;
439+ }
440+ air. transcript_bus . receive (
441+ builder,
442+ proof_idx,
443+ TranscriptBusMessage {
444+ tidx : AB :: Expr :: from_usize ( start_tidx + DIGEST_SIZE ) ,
445+ value : log2_max_codeword_size. into ( ) ,
446+ is_sample : AB :: Expr :: ZERO ,
447+ } ,
448+ mult,
449+ ) ;
450+ }
451+
386452impl VmPvsAir {
387453 fn eval_deferrals < AB > (
388454 & self ,
0 commit comments