Updates for the assertion and pow function

This commit is contained in:
aniampio
2022-05-25 17:06:32 +01:00
parent e8bb96b7d0
commit e07974ad2b
4 changed files with 26 additions and 27 deletions
@@ -163,7 +163,7 @@ impl SpendProof {
.chain(std::iter::once(zkcm_phi1.to_bytes().as_ref()))
.chain(std::iter::once(zkcm_varphi0.to_bytes().as_ref()))
.chain(std::iter::once(zkcm_varphi1.to_bytes().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq1.to_compressed().as_ref()))
.chain(std::iter::once(zkcm_pg_eq1.to_compressed().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq2.to_compressed().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq3.to_compressed().as_ref()))
.chain(std::iter::once(zkcm_pg_eq4.to_compressed().as_ref()))
@@ -270,7 +270,7 @@ impl SpendProof {
.chain(std::iter::once(zkcm_phi1.to_bytes().as_ref()))
.chain(std::iter::once(zkcm_varphi0.to_bytes().as_ref()))
.chain(std::iter::once(zkcm_varphi1.to_bytes().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq1.to_compressed().as_ref()))
.chain(std::iter::once(zkcm_pg_eq1.to_compressed().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq2.to_compressed().as_ref()))
// .chain(std::iter::once(zkcm_pg_eq3.to_compressed().as_ref()))
.chain(std::iter::once(zkcm_pg_eq4.to_compressed().as_ref()))
@@ -391,12 +391,12 @@ mod tests {
let pg_eq3 = pg_rrprime_yy + pg_ssprime_gen2 + pg_varsigpr2_ww1 + pg_thetapr2_ww2 + pg_gen1_zz.neg();
let pg_eq4 = pg_rr_tt - pg_gen1_gen2;
// assert_eq!(pg_varsigpr1_delta + pg_psi0_delta * r_varsig1.neg(), pg_varsigpr2_gen2 + pg_psi0_gen2 * r_varsig2.neg());
// println!("--------------Check1---------------");
assert_eq!(pg_varsigpr1_delta + pg_psi0_delta * r_varsig1.neg(), pg_varsigpr2_gen2 + pg_psi0_gen2 * r_varsig2.neg());
println!("--------------Check1---------------");
assert_eq!(pg_thetapr1_delta + pg_psi0_delta * r_theta1.neg(), pg_thetapr2_gen2 + pg_psi0_gen2 * r_theta2.neg());
println!("--------------Check2---------------");
// assert_eq!(pg_thetapr1_delta + pg_psi0_delta * r_theta1.neg(), pg_thetapr2_gen2 + pg_psi0_gen2 * r_theta2.neg());
// println!("--------------Check2---------------");
//
// assert_eq!(pg_rrprime_yy + pg_psi0_yy * r_rr.neg() + pg_ssprime_gen2 + pg_psi0_gen2 * r_ss.neg() + pg_varsigpr2_ww1 + pg_psi0_ww1 * r_varsig2.neg()
// + pg_thetapr2_ww2 + pg_psi0_ww2 * r_theta2 - pg_gen1_zz, Gt::identity());
// println!("--------------Check2---------------");
@@ -203,7 +203,7 @@ impl WithdrawalReqProof {
) -> bool {
let grp = params.get_grp();
let g1 = grp.gen1();
let paramsU = params.get_params_u();
let params_u = params.get_params_u();
// recompute zk commitments for each instance
let zkcm_com = instance.com * self.challenge
@@ -211,7 +211,7 @@ impl WithdrawalReqProof {
+ self
.response_attributes
.iter()
.zip(paramsU.get_gammas().iter())
.zip(params_u.get_gammas().iter())
.map(|(m_i, gamma_i)| gamma_i * m_i)
.sum::<G1Projective>();
@@ -229,7 +229,7 @@ impl WithdrawalReqProof {
instance.pk_user.pk * self.challenge + g1 * self.response_attributes[0];
// covert to bytes
let gammas_bytes = paramsU
let gammas_bytes = params_u
.get_gammas()
.iter()
.map(|gamma| gamma.to_bytes())
@@ -1,3 +1,6 @@
use std::convert::TryFrom;
use std::net::ToSocketAddrs;
use bls12_381::{G1Affine, G1Projective, G2Affine, G2Prepared, G2Projective, pairing, Scalar};
use ff::Field;
use group::Curve;
@@ -85,22 +88,23 @@ impl Parameters {
let theta = eta * z;
let sigmas_u: Vec<G1Projective> = (1..=L)
.map(|i| sigma * (y * Scalar::from(i)))
.map(|i| sigma * (y.pow(&[i as u64, 0, 0, 0])))
.collect();
let thetas_u: Vec<G1Projective> = (1..=L)
.map(|i| theta * (y * Scalar::from(i)))
.map(|i| theta * (y.pow(&[i as u64, 0, 0, 0])))
.collect();
let deltas_a: Vec<G2Projective> = (0..=L - 1)
.map(|i| g2 * (y * Scalar::from(i)))
.map(|i| g2 * (y.pow(&[i as u64, 0, 0, 0])))
.collect();
let etas_u: Vec<G1Projective> = vec_a.iter().map(|x| g1 * x).collect();
let mut etas_a: Vec<G2Projective> = Default::default();
for l in 1..=L {
for k in 0..=l - 1 {
etas_a.push(g2 * (vec_a[l as usize - 1].neg() * (y * Scalar::from(k))));
etas_a.push(g2 * (vec_a[l as usize - 1].neg() * (y.pow(&[k as u64, 0, 0, 0]))));
}
}
@@ -115,16 +119,11 @@ impl Parameters {
let l = 10;
let vv = 20;
println!(".....Hello world.....");
let sl = sigmas_u.get(l).unwrap();
let tl = thetas_u.get(l - 1).unwrap();
let dv = deltas_a.get(vv - 1).unwrap();
let sv = sigmas_u.get(l + vv - 1).unwrap();
let g2 = grp.gen2();
assert_eq!(
pairing(&sl.to_affine(), &dv.to_affine()),
pairing(&sv.to_affine(), g2));
println!(".....Hello world2.....");
let tlv = thetas_u.get(l - 1 + vv - 1).unwrap();
assert_eq!(pairing(&tl.to_affine(), &dv.to_affine()), pairing(&tlv.to_affine(), g2));
println!("Hello world!!");
// Compute signature for each pair sigma, theta
let params_u = ParametersUser {
@@ -37,8 +37,8 @@ impl SPSSecretKey {
let r = grp.random_scalar();
let rr = grp.gen1() * r;
let ss: G1Projective = match messages_a {
Some(msgsA) => {
let prodS: Vec<G1Projective> = msgsA
Some(msgs_a) => {
let prodS: Vec<G1Projective> = msgs_a
.iter()
.zip(self.ws.iter())
.map(|(m_i, w_i)| m_i * w_i.neg())
@@ -48,8 +48,8 @@ impl SPSSecretKey {
None => grp.gen1() * (self.z() - r * self.y())
};
let tt = match messages_b {
Some(msgsB) => {
let prodT: Vec<G2Projective> = msgsB
Some(msgs_b) => {
let prodT: Vec<G2Projective> = msgs_b
.iter()
.zip(self.us.iter())
.map(|(m_i, u_i)| m_i * u_i.neg())