Skip to content

Commit 327ceaa

Browse files
committed
[Not compiling] Began making the verifier
1 parent dc3e2f0 commit 327ceaa

File tree

1 file changed

+53
-18
lines changed

1 file changed

+53
-18
lines changed

src/inner_product_argument.rs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl WeightedInnerProductProof {
709709
Ok((challenges, challenges_inv, vec_s, vec_inv_s))
710710
}
711711

712-
/* /// Verify an inner product proof
712+
/// Verify an inner product proof
713713
///
714714
/// # Arguments
715715
///
@@ -724,27 +724,32 @@ impl WeightedInnerProductProof {
724724
pub fn verify<T: RngCore>(
725725
&self,
726726
crs_G_vec: &Vec<G1Affine>,
727+
hi_tag: &Vec<G1Affine>,
728+
crs_G: &G1Projective,
727729
crs_H: &G1Projective,
728730

729-
C: G1Projective, // no need for mut
730-
D: G1Projective,
731+
P: G1Projective, // no need for mut
731732
z: Fr,
732733
vec_u: Vec<Fr>,
734+
y: Fr,
733735

734736
transcript: &mut Transcript,
735737
msm_accumulator: &mut MsmAccumulator,
736738

737739
rng: &mut T,
738740
) -> Result<(), ProofError> {
739-
let n = crs_G_vec.len();
741+
let G = crs_G_vec;
742+
let H = hi_tag;
743+
let n = G.len();
744+
745+
assert_eq!(H.len(), n);
740746
assert!(n.is_power_of_two());
741747

742748
// Step 1:
743-
transcript.append_list(b"ipa_step1", &[&C, &D]);
749+
transcript.append(b"ipa_step1", &P);
744750
transcript.append(b"ipa_step1", &z);
745-
transcript.append_list(b"ipa_step1", &[&self.B_c, &self.B_d]);
746-
let alpha = transcript.get_and_append_challenge(b"ipa_alpha");
747-
let beta = transcript.get_and_append_challenge(b"ipa_beta");
751+
/* let alpha = transcript.get_and_append_challenge(b"ipa_alpha");
752+
let beta = transcript.get_and_append_challenge(b"ipa_beta");*/
748753

749754
// Step 2
750755
let (vec_gamma, vec_gamma_inv, vec_s, vec_inv_s) =
@@ -808,7 +813,7 @@ impl WeightedInnerProductProof {
808813
c_final: Fr::deserialize_compressed(&mut r)?,
809814
d_final: Fr::deserialize_compressed(&mut r)?,
810815
})
811-
}*/
816+
}
812817
}
813818

814819

@@ -922,7 +927,7 @@ mod tests {
922927
// There is actually a relationship between crs_G_vec and crs_G_prime_vec because of the grandproduct optimization
923928
// We generate a `vec_u` which has the discrete logs of every crs_G_prime element with respect to crs_G
924929
let vec_u = generate_blinders(&mut rng, n);
925-
let crs_G_prime_vec: Vec<G1Affine> = crs_G_vec
930+
let crs_H_vec: Vec<G1Affine> = crs_G_vec
926931
.iter()
927932
.zip(&vec_u)
928933
.map(|(G_i, u_i)| G_i.mul(*u_i).into_affine())
@@ -936,16 +941,44 @@ mod tests {
936941

937942
let z = inner_product(&vec_c, &vec_d);
938943

939-
// Create commitments
940-
let P = msm(&crs_G_prime_vec, &vec_c);
941-
942944
let y_scalar = Fr::rand(&mut rng);
945+
let y_inv = y_scalar.inverse().unwrap();
946+
let powers_y = iterate(y_scalar.clone(), |i| i.clone() * y_scalar)
947+
.take(n)
948+
.collect::<Vec<Fr>>();
949+
let powers_y_inv = iterate(y_inv.clone(), |i| i.clone() * y_inv.clone())
950+
.take(n)
951+
.collect::<Vec<Fr>>();
943952

944953
let alpha = Fr::rand(&mut rng);
945954

955+
let hi_tag = (0..n)
956+
.map(|i| crs_H_vec[i] * powers_y_inv[i])
957+
.collect::<Vec<G1Projective>>();
958+
959+
// P = <a * G> + <b_L * H_R> + c * g + alpha*h
960+
let g_z: G1Projective = crs_G * z; // Todo: Implement
961+
let h_alpha: G1Projective = crs_H * alpha;
962+
let gz_halpha: G1Projective = g_z + h_alpha;
963+
let c_G: G1Projective = (0..n)
964+
.map(|i| {
965+
crs_G_vec[i] * vec_c[i]
966+
})
967+
.fold(gz_halpha, |acc, x| {
968+
acc + x
969+
});
970+
971+
let P = (0..n)
972+
.map(|i| {
973+
hi_tag[i] * vec_d[i]
974+
})
975+
.fold(c_G, |acc, x| {
976+
acc + x
977+
});
978+
946979
let proof = WeightedInnerProductProof::new(
947980
crs_G_vec.clone(),
948-
crs_G_prime_vec.clone(),
981+
crs_H_vec.clone(),
949982
&crs_H,
950983
&crs_G,
951984
P.clone(),
@@ -962,19 +995,21 @@ mod tests {
962995
let mut transcript_verifier = merlin::Transcript::new(b"IPA");
963996
let mut msm_accumulator = MsmAccumulator::new();
964997

965-
/*assert!(proof
998+
assert!(proof
966999
.verify(
9671000
&crs_G_vec,
1001+
&hi_tag.iter().map(|i| i.into_affine()).collect(),
1002+
&crs_G,
9681003
&crs_H,
969-
B,
970-
C,
1004+
P,
9711005
z,
9721006
vec_u.clone(),
1007+
y_scalar,
9731008
&mut transcript_verifier,
9741009
&mut msm_accumulator,
9751010
&mut rng,
9761011
)
977-
.is_ok());*/
1012+
.is_ok());
9781013

9791014
assert!(msm_accumulator.verify().is_ok());
9801015

0 commit comments

Comments
 (0)