@@ -7,6 +7,7 @@ use super::r1csinstance::R1CSInstance;
7
7
use super :: sumcheck:: SumcheckInstanceProof ;
8
8
use super :: timer:: Timer ;
9
9
use super :: transcript:: ProofTranscript ;
10
+ use crate :: custom_dense_mlpoly:: rev_bits;
10
11
use crate :: scalar:: SpartanExtensionField ;
11
12
use crate :: { ProverWitnessSecInfo , VerifierWitnessSecInfo } ;
12
13
use merlin:: Transcript ;
@@ -178,22 +179,28 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
178
179
179
180
// append input to variables to create a single vector z
180
181
let timer_tmp = Timer :: new ( "prove_z_mat_gen" ) ;
181
- let mut z_mat: Vec < Vec < Vec < Vec < S > > > > = Vec :: new ( ) ;
182
- for p in 0 ..num_instances {
183
- z_mat. push ( Vec :: new ( ) ) ;
184
- for q in 0 ..num_proofs[ p] {
185
- z_mat[ p] . push ( vec ! [ vec![ S :: field_zero( ) ; num_inputs[ p] ] ; num_witness_secs] ) ;
186
- for w in 0 ..witness_secs. len ( ) {
187
- let ws = witness_secs[ w] ;
188
- let p_w = if ws. w_mat . len ( ) == 1 { 0 } else { p } ;
189
- let q_w = if ws. w_mat [ p_w] . len ( ) == 1 { 0 } else { q } ;
190
- // Only append the first num_inputs_entries of w_mat[p][q]
191
- for i in 0 ..min ( ws. num_inputs [ p_w] , num_inputs[ p] ) {
192
- z_mat[ p] [ q] [ w] [ i] = ws. w_mat [ p_w] [ q_w] [ i] ;
182
+ let z_mat_rev = {
183
+ let mut z_mat: Vec < Vec < Vec < Vec < S > > > > = Vec :: new ( ) ;
184
+ for p in 0 ..num_instances {
185
+ z_mat. push ( vec ! [ vec![ vec![ S :: field_zero( ) ; num_inputs[ p] ] ; num_witness_secs] ; num_proofs[ p] ] ) ;
186
+ let q_step = max_num_proofs / num_proofs[ p] ;
187
+ for q in 0 ..num_proofs[ p] {
188
+ let q_rev = rev_bits ( q, max_num_proofs) / q_step;
189
+ for w in 0 ..witness_secs. len ( ) {
190
+ let ws = witness_secs[ w] ;
191
+ let p_w = if ws. w_mat . len ( ) == 1 { 0 } else { p } ;
192
+ let q_w = if ws. w_mat [ p_w] . len ( ) == 1 { 0 } else { q } ;
193
+ let y_step = max_num_inputs / num_inputs[ p] ;
194
+ // Only append the first num_inputs_entries of w_mat[p][q]
195
+ for i in 0 ..min ( ws. num_inputs [ p_w] , num_inputs[ p] ) {
196
+ let y_rev = rev_bits ( i, max_num_inputs) / y_step;
197
+ z_mat[ p] [ q_rev] [ w] [ y_rev] = ws. w_mat [ p_w] [ q_w] [ i] ;
198
+ }
193
199
}
194
200
}
195
201
}
196
- }
202
+ z_mat
203
+ } ;
197
204
timer_tmp. stop ( ) ;
198
205
199
206
// derive the verifier's challenge \tau
@@ -221,7 +228,7 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
221
228
max_num_inputs,
222
229
num_cons,
223
230
block_num_cons. clone ( ) ,
224
- & z_mat ,
231
+ & z_mat_rev ,
225
232
) ;
226
233
timer_tmp. stop ( ) ;
227
234
@@ -252,7 +259,7 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
252
259
timer_tmp. stop ( ) ;
253
260
timer_sc_proof_phase1. stop ( ) ;
254
261
255
- let ( tau_claim , Az_claim , Bz_claim , Cz_claim ) = (
262
+ let ( _tau_claim , Az_claim , Bz_claim , Cz_claim ) = (
256
263
& ( poly_tau_p[ 0 ] * poly_tau_q[ 0 ] * poly_tau_x[ 0 ] ) ,
257
264
& poly_Az. index ( 0 , 0 , 0 , 0 ) ,
258
265
& poly_Bz. index ( 0 , 0 , 0 , 0 ) ,
@@ -320,8 +327,8 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
320
327
321
328
let timer_tmp = Timer :: new ( "prove_z_gen" ) ;
322
329
// Construct a p * q * len(z) matrix Z and bound it to r_q
323
- let mut Z_poly = DensePolynomialPqx :: new_rev (
324
- & z_mat ,
330
+ let mut Z_poly = DensePolynomialPqx :: new (
331
+ z_mat_rev ,
325
332
num_proofs. clone ( ) ,
326
333
max_num_proofs,
327
334
num_inputs. clone ( ) ,
@@ -586,7 +593,7 @@ impl<S: SpartanExtensionField + Send + Sync> R1CSProof<S> {
586
593
S :: append_field_to_transcript ( b"Cz_claim" , transcript, Cz_claim ) ;
587
594
588
595
// debug_zk
589
- // assert_eq!(taus_bound_rx * (Az_claim * Bz_claim - Cz_claim), claim_post_phase_1);
596
+ assert_eq ! ( taus_bound_rx * ( Az_claim * Bz_claim - Cz_claim ) , claim_post_phase_1) ;
590
597
591
598
// derive three public challenges and then derive a joint claim
592
599
let r_A: S = transcript. challenge_scalar ( b"challenge_Az" ) ;
0 commit comments