@@ -29,6 +29,7 @@ use crate::{
2929 thread:: unsafe_allocate_zero_vec,
3030 } ,
3131 zkvm:: {
32+ bytecode:: BytecodePreprocessing ,
3233 dag:: state_manager:: StateManager ,
3334 instruction:: {
3435 CircuitFlags , Flags , InstructionFlags , InstructionLookup , InterleavedBitsMarker ,
@@ -45,7 +46,7 @@ use common::constants::{REGISTER_COUNT, XLEN};
4546use itertools:: { chain, zip_eq, Itertools } ;
4647use rayon:: prelude:: * ;
4748use strum:: { EnumCount , IntoEnumIterator } ;
48- use tracer:: instruction:: NormalizedInstruction ;
49+ use tracer:: instruction:: { Instruction , NormalizedInstruction } ;
4950
5051/// Number of batched read-checking sumchecks bespokely
5152const N_STAGES : usize = 5 ;
@@ -130,7 +131,14 @@ impl<F: JoltField> ReadRafSumcheckProver<F> {
130131 opening_accumulator : & ProverOpeningAccumulator < F > ,
131132 transcript : & mut impl Transcript ,
132133 ) -> Self {
133- let params = ReadRafSumcheckParams :: gen ( state_manager, opening_accumulator, transcript) ;
134+ let ( preprocessing, _, trace, _, _) = state_manager. get_prover_data ( ) ;
135+
136+ let params = ReadRafSumcheckParams :: gen (
137+ & preprocessing. shared . bytecode ,
138+ trace. len ( ) . log_2 ( ) ,
139+ opening_accumulator,
140+ transcript,
141+ ) ;
134142
135143 let claim_per_stage = [
136144 params. rv_claims [ 0 ] + params. gamma_powers [ 5 ] * params. raf_claim ,
@@ -149,7 +157,6 @@ impl<F: JoltField> ReadRafSumcheckProver<F> {
149157 . each_ref ( )
150158 . map ( |r_cycle| EqPolynomial :: evals ( & r_cycle[ ..prefix_n_vars] ) ) ;
151159
152- let ( preprocessing, _, trace, _, _) = state_manager. get_prover_data ( ) ;
153160 let F = trace
154161 . par_chunks ( chunk_size)
155162 . enumerate ( )
@@ -529,12 +536,18 @@ pub struct ReadRafSumcheckVerifier<F: JoltField> {
529536
530537impl < F : JoltField > ReadRafSumcheckVerifier < F > {
531538 pub fn gen (
532- state_manager : & mut StateManager < ' _ , F , impl CommitmentScheme < Field = F > > ,
539+ bytecode_preprocessing : & BytecodePreprocessing ,
540+ n_cycle_vars : usize ,
533541 opening_accumulator : & VerifierOpeningAccumulator < F > ,
534542 transcript : & mut impl Transcript ,
535543 ) -> Self {
536544 Self {
537- params : ReadRafSumcheckParams :: gen ( state_manager, opening_accumulator, transcript) ,
545+ params : ReadRafSumcheckParams :: gen (
546+ bytecode_preprocessing,
547+ n_cycle_vars,
548+ opening_accumulator,
549+ transcript,
550+ ) ,
538551 }
539552 }
540553}
@@ -658,44 +671,44 @@ struct ReadRafSumcheckParams<F: JoltField> {
658671
659672impl < F : JoltField > ReadRafSumcheckParams < F > {
660673 fn gen (
661- state_manager : & mut StateManager < ' _ , F , impl CommitmentScheme < Field = F > > ,
674+ bytecode_preprocessing : & BytecodePreprocessing ,
675+ n_cycle_vars : usize ,
662676 opening_accumulator : & dyn OpeningAccumulator < F > ,
663677 transcript : & mut impl Transcript ,
664678 ) -> Self {
665- let preprocessing = state_manager. get_shared_preprocessing ( ) ;
666- let K = preprocessing. bytecode . code_size ;
679+ let K = bytecode_preprocessing. code_size ;
667680 let log_K = K . log_2 ( ) ;
668- let d = preprocessing. bytecode . d ;
669- let log_T = state_manager. get_trace_len ( ) . log_2 ( ) ;
681+ let d = bytecode_preprocessing. d ;
670682 let log_K_chunk = log_K. div_ceil ( d) ;
671683 let gamma_powers = transcript. challenge_scalar_powers ( 7 ) ;
672684
685+ let bytecode = & bytecode_preprocessing. bytecode ;
673686 let ( val_1, rv_claim_1) = Self :: compute_val_rv (
674- state_manager ,
687+ bytecode ,
675688 opening_accumulator,
676689 ReadCheckingValType :: Stage1 ,
677690 transcript,
678691 ) ;
679692 let ( val_2, rv_claim_2) = Self :: compute_val_rv (
680- state_manager ,
693+ bytecode ,
681694 opening_accumulator,
682695 ReadCheckingValType :: Stage2 ,
683696 transcript,
684697 ) ;
685698 let ( val_3, rv_claim_3) = Self :: compute_val_rv (
686- state_manager ,
699+ bytecode ,
687700 opening_accumulator,
688701 ReadCheckingValType :: Stage3 ,
689702 transcript,
690703 ) ;
691704 let ( val_4, rv_claim_4) = Self :: compute_val_rv (
692- state_manager ,
705+ bytecode ,
693706 opening_accumulator,
694707 ReadCheckingValType :: Stage4 ,
695708 transcript,
696709 ) ;
697710 let ( val_5, rv_claim_5) = Self :: compute_val_rv (
698- state_manager ,
711+ bytecode ,
699712 opening_accumulator,
700713 ReadCheckingValType :: Stage5 ,
701714 transcript,
@@ -765,7 +778,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
765778 log_K_chunk,
766779 K_chunk : 1 << log_K_chunk,
767780 d,
768- log_T,
781+ log_T : n_cycle_vars ,
769782 val_polys,
770783 rv_claims,
771784 raf_claim,
@@ -776,7 +789,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
776789 }
777790
778791 fn compute_val_rv (
779- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
792+ bytecode : & [ Instruction ] ,
780793 opening_accumulator : & dyn OpeningAccumulator < F > ,
781794 val_type : ReadCheckingValType ,
782795 transcript : & mut impl Transcript ,
@@ -785,35 +798,35 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
785798 ReadCheckingValType :: Stage1 => {
786799 let gamma_powers = transcript. challenge_scalar_powers ( 2 + NUM_CIRCUIT_FLAGS ) ;
787800 (
788- Self :: compute_val_1 ( sm , & gamma_powers) ,
801+ Self :: compute_val_1 ( bytecode , & gamma_powers) ,
789802 Self :: compute_rv_claim_1 ( opening_accumulator, & gamma_powers) ,
790803 )
791804 }
792805 ReadCheckingValType :: Stage2 => {
793806 let gamma_powers = transcript. challenge_scalar_powers ( 4 ) ;
794807 (
795- Self :: compute_val_2 ( sm , & gamma_powers) ,
808+ Self :: compute_val_2 ( bytecode , & gamma_powers) ,
796809 Self :: compute_rv_claim_2 ( opening_accumulator, & gamma_powers) ,
797810 )
798811 }
799812 ReadCheckingValType :: Stage3 => {
800813 let gamma_powers = transcript. challenge_scalar_powers ( 9 ) ;
801814 (
802- Self :: compute_val_3 ( sm , & gamma_powers) ,
815+ Self :: compute_val_3 ( bytecode , & gamma_powers) ,
803816 Self :: compute_rv_claim_3 ( opening_accumulator, & gamma_powers) ,
804817 )
805818 }
806819 ReadCheckingValType :: Stage4 => {
807820 let gamma_powers = transcript. challenge_scalar_powers ( 3 ) ;
808821 (
809- Self :: compute_val_4 ( sm , opening_accumulator, & gamma_powers) ,
822+ Self :: compute_val_4 ( bytecode , opening_accumulator, & gamma_powers) ,
810823 Self :: compute_rv_claim_4 ( opening_accumulator, & gamma_powers) ,
811824 )
812825 }
813826 ReadCheckingValType :: Stage5 => {
814827 let gamma_powers = transcript. challenge_scalar_powers ( 2 + NUM_LOOKUP_TABLES ) ;
815828 (
816- Self :: compute_val_5 ( sm , opening_accumulator, & gamma_powers) ,
829+ Self :: compute_val_5 ( bytecode , opening_accumulator, & gamma_powers) ,
817830 Self :: compute_rv_claim_5 ( opening_accumulator, & gamma_powers) ,
818831 )
819832 }
@@ -824,11 +837,8 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
824837 /// Val(k) = unexpanded_pc(k) + gamma * imm(k)
825838 /// + gamma^2 * circuit_flags[0](k) + gamma^3 * circuit_flags[1](k) + ...
826839 /// This particular Val virtualizes claims output by Spartan's "outer" sumcheck
827- fn compute_val_1 (
828- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
829- gamma_powers : & [ F ] ,
830- ) -> Vec < F > {
831- sm. get_bytecode ( )
840+ fn compute_val_1 ( bytecode : & [ Instruction ] , gamma_powers : & [ F ] ) -> Vec < F > {
841+ bytecode
832842 . par_iter ( )
833843 . map ( |instruction| {
834844 let NormalizedInstruction {
@@ -897,11 +907,8 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
897907 /// rd_addr(k) is the rd address for instruction k;
898908 /// write_lookup_output_to_rd_flag(k) = 1 if instruction k writes lookup output to rd, 0 otherwise.
899909 /// This Val matches the fused product sumcheck.
900- fn compute_val_2 (
901- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
902- gamma_powers : & [ F ] ,
903- ) -> Vec < F > {
904- sm. get_bytecode ( )
910+ fn compute_val_2 ( bytecode : & [ Instruction ] , gamma_powers : & [ F ] ) -> Vec < F > {
911+ bytecode
905912 . par_iter ( )
906913 . map ( |instruction| {
907914 let flags = instruction. circuit_flags ( ) ;
@@ -965,11 +972,8 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
965972 /// + gamma^2 * left_operand_is_rs1_value(k)
966973 /// + gamma^3 * left_operand_is_pc(k) + ...
967974 /// This particular Val virtualizes claims output by the ShiftSumcheck.
968- fn compute_val_3 (
969- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
970- gamma_powers : & [ F ] ,
971- ) -> Vec < F > {
972- sm. get_bytecode ( )
975+ fn compute_val_3 ( bytecode : & [ Instruction ] , gamma_powers : & [ F ] ) -> Vec < F > {
976+ bytecode
973977 . par_iter ( )
974978 . map ( |instruction| {
975979 let instr = instruction. normalize ( ) ;
@@ -1085,7 +1089,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
10851089 /// and analogously for rs1(k, k') and rs2(k, k').
10861090 /// This particular Val virtualizes claims output by the registers read/write checking sumcheck.
10871091 fn compute_val_4 (
1088- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
1092+ bytecode : & [ Instruction ] ,
10891093 opening_accumulator : & dyn OpeningAccumulator < F > ,
10901094 gamma_powers : & [ F ] ,
10911095 ) -> Vec < F > {
@@ -1100,7 +1104,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
11001104 let eq_r_register = EqPolynomial :: < F > :: evals ( r_register) ;
11011105 debug_assert_eq ! ( eq_r_register. len( ) , REGISTER_COUNT as usize ) ;
11021106
1103- sm . get_bytecode ( )
1107+ bytecode
11041108 . par_iter ( )
11051109 . map ( |instruction| {
11061110 let instr = instruction. normalize ( ) ;
@@ -1143,7 +1147,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
11431147 /// This particular Val virtualizes the claim output by the registers val-evaluation sumcheck
11441148 /// and the instruction lookups sumcheck.
11451149 fn compute_val_5 (
1146- sm : & mut StateManager < F , impl CommitmentScheme < Field = F > > ,
1150+ bytecode : & [ Instruction ] ,
11471151 opening_accumulator : & dyn OpeningAccumulator < F > ,
11481152 gamma_powers : & [ F ] ,
11491153 ) -> Vec < F > {
@@ -1158,7 +1162,7 @@ impl<F: JoltField> ReadRafSumcheckParams<F> {
11581162 let eq_r_register = EqPolynomial :: evals ( & r_register) ;
11591163 debug_assert_eq ! ( eq_r_register. len( ) , REGISTER_COUNT as usize ) ;
11601164
1161- sm . get_bytecode ( )
1165+ bytecode
11621166 . par_iter ( )
11631167 . map ( |instruction| {
11641168 let instr = instruction. normalize ( ) ;
0 commit comments