Skip to content

Commit d59d55e

Browse files
committed
[Not compiling] Worked on bpplus
1 parent d738b47 commit d59d55e

1 file changed

Lines changed: 54 additions & 36 deletions

File tree

src/inner_product_argument.rs

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ pub struct InnerProductProof {
3535
}
3636

3737
pub struct WeightedInnerProductProof {
38-
B_c: G1Projective,
39-
B_d: G1Projective,
38+
G: Vec<G1Affine>,
39+
H: Vec<G1Affine>,
40+
g: G1Projective,
41+
h: G1Projective,
4042

4143
vec_c_L: Vec<G1Projective>,
4244
vec_c_R: Vec<G1Projective>,
@@ -156,7 +158,7 @@ impl InnerProductProof {
156158
// Create slices backed by their respective vectors. This lets us reslice as we compress the lengths of the
157159
// vectors in the main loop below.
158160
let mut slice_G = &mut crs_G_vec[..];
159-
let mut slice_G_prime = &mut crs_G_prime_vec[..];
161+
let mut slice_H = &mut crs_G_prime_vec[..];
160162
let mut slice_c = &mut vec_c[..];
161163
let mut slice_d = &mut vec_d[..];
162164

@@ -166,12 +168,12 @@ impl InnerProductProof {
166168
let (c_L, c_R) = slice_c.split_at_mut(n);
167169
let (d_L, d_R) = slice_d.split_at_mut(n);
168170
let (G_L, G_R) = slice_G.split_at_mut(n);
169-
let (G_prime_L, G_prime_R) = slice_G_prime.split_at_mut(n);
171+
let (H_L, H_R) = slice_H.split_at_mut(n);
170172

171173
let L_C = msm(G_R, c_L) + H.mul(inner_product(c_L, d_R));
172-
let L_D = msm(G_prime_L, d_R);
174+
let L_D = msm(H_L, d_R);
173175
let R_C = msm(G_L, c_R) + H.mul(inner_product(c_R, d_L));
174-
let R_D = msm(G_prime_R, d_L);
176+
let R_D = msm(H_R, d_L);
175177

176178
// Append elements to the proof
177179
vec_L_C.push(L_C);
@@ -188,14 +190,14 @@ impl InnerProductProof {
188190
c_L[i] += gamma_inv * c_R[i];
189191
d_L[i] += gamma * d_R[i];
190192
G_L[i] = (G_L[i] + G_R[i].mul(gamma)).into_affine();
191-
G_prime_L[i] = (G_prime_L[i] + G_prime_R[i].mul(gamma_inv)).into_affine();
193+
H_L[i] = (H_L[i] + H_R[i].mul(gamma_inv)).into_affine();
192194
}
193195

194196
// Save the rescaled vector for splitting in the next loop
195197
slice_c = c_L;
196198
slice_d = d_L;
197199
slice_G = G_L;
198-
slice_G_prime = G_prime_L;
200+
slice_H = H_L;
199201
}
200202

201203
InnerProductProof {
@@ -389,46 +391,55 @@ impl WeightedInnerProductProof {
389391

390392
mut vec_c: Vec<Fr>,
391393
mut vec_d: Vec<Fr>,
392-
394+
y: Fr,
395+
alpha: Fr,
396+
393397
transcript: &mut Transcript,
394398
rng: &mut T,
395-
) -> InnerProductProof {
399+
) -> WeightedInnerProductProof {
396400
let mut n = vec_c.len();
397401
let lg_n = ark_std::log2(n) as usize;
398402
assert_eq!(vec_d.len(), n);
399403
assert_eq!(crs_G_vec.len(), n);
400404
assert_eq!(crs_H_vec.len(), n);
401405
assert!(n.is_power_of_two());
402406

407+
// Compute powers of y
408+
let y_inv = y.inverse().unwrap();
409+
403410
let mut vec_c_L = Vec::with_capacity(lg_n);
404411
let mut vec_c_R = Vec::with_capacity(lg_n);
405412
let mut vec_d_L = Vec::with_capacity(lg_n);
406413
let mut vec_d_R = Vec::with_capacity(lg_n);
407414

408415
// Step 1
416+
/*
417+
We don't need blinders as bp+ is zk
409418
let (vec_r_c, vec_r_d) = generate_ipa_blinders(rng, &vec_c, &vec_d);
410419
411420
let B_c = msm(&crs_G_vec, &vec_r_c);
412-
let B_d = msm(&crs_H_vec, &vec_r_d);
421+
let B_d = msm(&crs_H_vec, &vec_r_d); */
413422

414-
transcript.append_list(b"ipa_step1", &[&P, &D]);
423+
transcript.append(b"ipa_step1", &P);
415424
transcript.append(b"ipa_step1", &z);
416-
transcript.append_list(b"ipa_step1", &[&B_c, &B_d]);
425+
transcript.append_list(b"ipa_step1", &[&crs_G_vec, &crs_H_vec]);
426+
427+
/* Not needed for bp+
417428
let alpha = transcript.get_and_append_challenge(b"ipa_alpha");
418-
let beta = transcript.get_and_append_challenge(b"ipa_beta");
429+
let beta = transcript.get_and_append_challenge(b"ipa_beta"); */
419430

420-
// Rewrite vectors c and d
421-
for i in 0..n {
431+
// Rewrite vectors c and d (NOT NEEDED FOR BP+)
432+
/* for i in 0..n {
422433
vec_c[i] = vec_r_c[i] + alpha * vec_c[i];
423434
vec_d[i] = vec_r_d[i] + alpha * vec_d[i];
424435
}
425-
let H = crs_H.mul(beta);
436+
let H = crs_H.mul(beta); */
426437

427438
// Step 2
428439
// Create slices backed by their respective vectors. This lets us reslice as we compress the lengths of the
429440
// vectors in the main loop below.
430441
let mut slice_G = &mut crs_G_vec[..];
431-
let mut slice_G_prime = &mut crs_H_vec[..];
442+
let mut slice_H = &mut crs_H_vec[..];
432443
let mut slice_c = &mut vec_c[..];
433444
let mut slice_d = &mut vec_d[..];
434445

@@ -438,20 +449,27 @@ impl WeightedInnerProductProof {
438449
let (c_L, c_R) = slice_c.split_at_mut(n);
439450
let (d_L, d_R) = slice_d.split_at_mut(n);
440451
let (G_L, G_R) = slice_G.split_at_mut(n);
441-
let (G_prime_L, G_prime_R) = slice_G_prime.split_at_mut(n);
452+
let (H_L, H_R) = slice_H.split_at_mut(n);
442453

443-
let L_C = msm(G_R, c_L) + H.mul(inner_product(c_L, d_R));
444-
let L_D = msm(G_prime_L, d_R);
454+
/* let L_C = msm(G_R, c_L) + H.mul(inner_product(c_L, d_R));
455+
let L_D = msm(H_L, d_R);
445456
let R_C = msm(G_L, c_R) + H.mul(inner_product(c_R, d_L));
446-
let R_D = msm(G_prime_R, d_L);
457+
let R_D = msm(H_R, d_L); */
458+
let c_LL: & [ark_ff::Fp<ark_ff::MontBackend<ark_bls12_381::FrConfig, 4>, 4>] = c_L;
459+
let c_RR: & [ark_ff::Fp<ark_ff::MontBackend<ark_bls12_381::FrConfig, 4>, 4>] = c_R;
460+
let d_LL: & [ark_ff::Fp<ark_ff::MontBackend<ark_bls12_381::FrConfig, 4>, 4>] = d_L;
461+
let d_RR: & [ark_ff::Fp<ark_ff::MontBackend<ark_bls12_381::FrConfig, 4>, 4>] = d_R;
462+
463+
// First compute z_L
464+
let z_L = weighted_inner_product(c_L, d_R, y.clone());
447465

448466
// Append elements to the proof
449-
vec_c_L.push(L_C);
450-
vec_d_L.push(L_D);
451-
vec_c_R.push(R_C);
452-
vec_d_R.push(R_D);
467+
vec_c_L.push(c_LL);
468+
vec_d_L.push(d_LL);
469+
vec_c_R.push(c_RR);
470+
vec_d_R.push(d_RR);
453471

454-
transcript.append_list(b"ipa_loop", &[&L_C, &L_D, &R_C, &R_D]);
472+
transcript.append_list(b"ipa_loop", &[&c_LL, &d_LL, &c_RR, &d_RR]);
455473
let gamma = transcript.get_and_append_challenge(b"ipa_gamma");
456474
let gamma_inv = gamma.inverse().expect("gamma must have an inverse");
457475

@@ -460,23 +478,23 @@ impl WeightedInnerProductProof {
460478
c_L[i] += gamma_inv * c_R[i];
461479
d_L[i] += gamma * d_R[i];
462480
G_L[i] = (G_L[i] + G_R[i].mul(gamma)).into_affine();
463-
G_prime_L[i] = (G_prime_L[i] + G_prime_R[i].mul(gamma_inv)).into_affine();
481+
H_L[i] = (H_L[i] + H_R[i].mul(gamma_inv)).into_affine();
464482
}
465483

466484
// Save the rescaled vector for splitting in the next loop
467485
slice_c = c_L;
468486
slice_d = d_L;
469487
slice_G = G_L;
470-
slice_G_prime = G_prime_L;
488+
slice_H = H_L;
471489
}
472490

473-
InnerProductProof {
474-
B_c,
475-
B_d,
476-
vec_L_C: vec_c_L,
477-
vec_R_C: vec_c_R,
478-
vec_L_D: vec_d_L,
479-
vec_R_D: vec_d_R,
491+
WeightedInnerProductProof {
492+
G: crs_G_vec,
493+
H: crs_H_vec,
494+
vec_c_L: vec_c_L,
495+
vec_c_R: vec_c_R,
496+
vec_d_L: vec_d_L,
497+
vec_d_R: vec_d_R,
480498
c_final: slice_c[0],
481499
d_final: slice_d[0],
482500
}

0 commit comments

Comments
 (0)