@@ -56,6 +56,7 @@ use scalar::SpartanExtensionField;
5656use serde:: { Deserialize , Serialize } ;
5757use timer:: Timer ;
5858use transcript:: { AppendToTranscript , ProofTranscript } ;
59+ use std:: sync:: Arc ;
5960
6061const INIT_PHY_MEM_WIDTH : usize = 4 ;
6162const INIT_VIR_MEM_WIDTH : usize = 4 ;
@@ -643,7 +644,7 @@ impl PartialEq for InstanceSortHelper {
643644}
644645impl Eq for InstanceSortHelper { }
645646
646- impl < S : SpartanExtensionField > SNARK < S > {
647+ impl < S : SpartanExtensionField + ' static > SNARK < S > {
647648 fn protocol_name ( ) -> & ' static [ u8 ] {
648649 b"Spartan SNARK proof"
649650 }
@@ -859,7 +860,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
859860 block_num_instances_bound : usize ,
860861 block_max_num_proofs : usize ,
861862 block_num_proofs : & Vec < usize > ,
862- block_inst : & mut Instance < S > ,
863+ mut block_inst : Instance < S > ,
863864 block_comm_map : & Vec < Vec < usize > > ,
864865 block_comm_list : & Vec < ComputationCommitment < S > > ,
865866 block_decomm_list : & Vec < ComputationDecommitment < S > > ,
@@ -869,7 +870,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
869870 total_num_init_vir_mem_accesses : usize ,
870871 total_num_phy_mem_accesses : usize ,
871872 total_num_vir_mem_accesses : usize ,
872- pairwise_check_inst : & mut Instance < S > ,
873+ mut pairwise_check_inst : Instance < S > ,
873874 pairwise_check_comm : & ComputationCommitment < S > ,
874875 pairwise_check_decomm : & ComputationDecommitment < S > ,
875876
@@ -881,7 +882,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
881882 addr_vir_mems_list : Vec < MemsAssignment < S > > ,
882883 addr_ts_bits_list : Vec < MemsAssignment < S > > ,
883884
884- perm_root_inst : & Instance < S > ,
885+ perm_root_inst : Instance < S > ,
885886 perm_root_comm : & ComputationCommitment < S > ,
886887 perm_root_decomm : & ComputationDecommitment < S > ,
887888 transcript : & mut Transcript ,
@@ -1930,6 +1931,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
19301931 & block_w3_shifted_prover,
19311932 ] ;
19321933
1934+ let arc_block_inst = Arc :: new ( block_inst. inst ) ;
19331935 let ( block_r1cs_sat_proof, block_challenges) = {
19341936 let ( proof, block_challenges) = {
19351937 R1CSProof :: prove (
@@ -1939,7 +1941,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
19391941 num_vars,
19401942 & block_num_vars,
19411943 block_wit_secs,
1942- & block_inst . inst ,
1944+ arc_block_inst . clone ( ) ,
19431945 transcript,
19441946 )
19451947 } ;
@@ -1958,7 +1960,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
19581960 // Per instance evaluation is unsorted
19591961 let inst_evals_list = block_inst_unsorted. inst . multi_evaluate :: < true > ( & rx, & ry) ;
19601962 // RP-bound evaluation is sorted
1961- let ( _, inst_evals_bound_rp) = block_inst . inst . multi_evaluate_bound_rp :: < true > ( & rp, & rx, & ry) ;
1963+ let ( _, inst_evals_bound_rp) = R1CSInstance :: multi_evaluate_bound_rp :: < true > ( arc_block_inst . as_ref ( ) , & rp, & rx, & ry) ;
19621964 timer_eval. stop ( ) ;
19631965
19641966 for r in & inst_evals_list {
@@ -2038,6 +2040,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
20382040 }
20392041 ProverWitnessSecInfo :: concat ( components)
20402042 } ;
2043+ let arc_pairwise_check_inst = Arc :: new ( pairwise_check_inst. inst ) ;
20412044 let pairwise_num_instances = pairwise_prover. w_mat . len ( ) ;
20422045 let pairwise_num_proofs: Vec < usize > = pairwise_prover. w_mat . iter ( ) . map ( |i| i. len ( ) ) . collect ( ) ;
20432046 let ( pairwise_check_r1cs_sat_proof, pairwise_check_challenges) = {
@@ -2053,7 +2056,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
20532056 & pairwise_shifted_prover,
20542057 & addr_ts_bits_prover,
20552058 ] ,
2056- & pairwise_check_inst . inst ,
2059+ arc_pairwise_check_inst . clone ( ) ,
20572060 transcript,
20582061 )
20592062 } ;
@@ -2076,9 +2079,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
20762079 // Per instance evaluation is unsorted
20772080 let inst_evals_list = pairwise_check_inst_unsorted. inst . multi_evaluate :: < false > ( & rx, & ry) ;
20782081 // RP-bound evaluation is sorted
2079- let ( _, inst_evals_bound_rp) = pairwise_check_inst
2080- . inst
2081- . multi_evaluate_bound_rp :: < false > ( & rp, & rx, & ry) ;
2082+ let ( _, inst_evals_bound_rp) = R1CSInstance :: multi_evaluate_bound_rp :: < false > ( arc_pairwise_check_inst. as_ref ( ) , & rp, & rx, & ry) ;
20822083 timer_eval. stop ( ) ;
20832084
20842085 for r in & inst_evals_list {
@@ -2161,6 +2162,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
21612162 & phy_mem_addr_w3_shifted_prover,
21622163 & vir_mem_addr_w3_shifted_prover,
21632164 ] ) ;
2165+ let arc_perm_root_inst = Arc :: new ( perm_root_inst. inst ) ;
21642166 let perm_root_num_instances = perm_root_w1_prover. w_mat . len ( ) ;
21652167 let perm_root_num_proofs: Vec < usize > =
21662168 perm_root_w1_prover. w_mat . iter ( ) . map ( |i| i. len ( ) ) . collect ( ) ;
@@ -2179,7 +2181,7 @@ impl<S: SpartanExtensionField> SNARK<S> {
21792181 & perm_root_w3_prover,
21802182 & perm_root_w3_shifted_prover,
21812183 ] ,
2182- & perm_root_inst . inst ,
2184+ arc_perm_root_inst . clone ( ) ,
21832185 transcript,
21842186 )
21852187 } ;
@@ -2193,10 +2195,9 @@ impl<S: SpartanExtensionField> SNARK<S> {
21932195 // Final evaluation on PERM_ROOT
21942196 let ( perm_root_inst_evals, perm_root_r1cs_eval_proof) = {
21952197 let [ _, _, rx, ry] = perm_root_challenges;
2196- let inst = perm_root_inst;
21972198 let timer_eval = Timer :: new ( "eval_sparse_polys" ) ;
21982199 let inst_evals = {
2199- let ( Ar , Br , Cr ) = inst . inst . evaluate ( & rx, & ry) ;
2200+ let ( Ar , Br , Cr ) = R1CSInstance :: evaluate ( arc_perm_root_inst . as_ref ( ) , & rx, & ry) ;
22002201
22012202 for ( val, tag) in [ ( Ar , b"Ar_claim" ) , ( Br , b"Br_claim" ) , ( Cr , b"Cr_claim" ) ] . into_iter ( ) {
22022203 S :: append_field_to_transcript ( tag, transcript, val) ;
0 commit comments