Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed Jul 10, 2024
1 parent 1f56876 commit 8c4fcca
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
31 changes: 18 additions & 13 deletions src/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,12 @@ mod test {

#[test]
fn pedersen_proof_2_pk() {
let mut rng = rand::thread_rng();
let pp = get_parameters();
let msg_1 = Scalar::rand(&mut rand::thread_rng());
let msg_1 = Scalar::rand(&mut rng);
let (cm_1, o_1) = Commitment::commit(&msg_1);
assert!(cm_1.verify(&msg_1, &o_1).is_ok());
let msg_2 = Scalar::rand(&mut rand::thread_rng());
let msg_2 = Scalar::rand(&mut rng);
let (cm_2, o_2) = Commitment::commit(&msg_2);
assert!(cm_2.verify(&msg_2, &o_2).is_ok());

Expand All @@ -710,12 +711,13 @@ mod test {

#[test]
fn multi_pedersen() {
let mut rng = rand::thread_rng();
let l = 10;
let pp = MultiBasePublicParameters::new(l);

let value_0 = Scalar::rand(&mut rand::thread_rng());
let value_0 = Scalar::rand(&mut rng);
for idx in 0..l {
let value_i = Scalar::rand(&mut rand::thread_rng());
let value_i = Scalar::rand(&mut rng);
let (cm, o) = Commitment::index_commit(&value_0, idx, &value_i, &pp);
assert!(cm
.verify_index_commit(&value_0, idx, &value_i, &o, &pp)
Expand All @@ -725,15 +727,16 @@ mod test {

#[test]
fn multi_pedersen_proof() {
let msg = Scalar::rand(&mut rand::thread_rng());
let mut rng = rand::thread_rng();
let msg = Scalar::rand(&mut rng);
let (commitment, opening) = Commitment::commit(&msg);

let l = 10;
let pp = MultiBasePublicParameters::new(l);

let value_0 = Scalar::rand(&mut rand::thread_rng());
let value_0 = Scalar::rand(&mut rng);
for idx in 0..l {
let value_i = Scalar::rand(&mut rand::thread_rng());
let value_i = Scalar::rand(&mut rng);
let (cm, o) = Commitment::index_commit(&value_0, idx, &value_i, &pp);
assert!(cm
.verify_index_commit(&value_0, idx, &value_i, &o, &pp)
Expand All @@ -749,13 +752,14 @@ mod test {

#[test]
fn multi_index_pedersen() {
let mut rng = rand::thread_rng();
let l = 10;
let pp = MultiBasePublicParameters::new(l);

let value_0 = Scalar::rand(&mut rand::thread_rng());
let value_0 = Scalar::rand(&mut rng);
let values = [
(2usize, Scalar::rand(&mut rand::thread_rng())),
(7usize, Scalar::rand(&mut rand::thread_rng())),
(2usize, Scalar::rand(&mut rng)),
(7usize, Scalar::rand(&mut rng)),
];
let (cm, o) = Commitment::multi_index_commit(&value_0, values.iter().copied(), &pp);
assert!(cm
Expand All @@ -765,13 +769,14 @@ mod test {

#[test]
fn multi_index_pedersen_proof() {
let mut rng = rand::thread_rng();
let l = 10;
let pp = MultiBasePublicParameters::new(l);

let value_0 = Scalar::rand(&mut rand::thread_rng());
let value_0 = Scalar::rand(&mut rng);
let values = [
(2usize, Scalar::rand(&mut rand::thread_rng())),
(7usize, Scalar::rand(&mut rand::thread_rng())),
(2usize, Scalar::rand(&mut rng)),
(7usize, Scalar::rand(&mut rng)),
];
let (cm, o) = Commitment::multi_index_commit(&value_0, values.iter().copied(), &pp);
assert!(cm
Expand Down
38 changes: 18 additions & 20 deletions src/s3id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
atact::{self, AtACTError, Token},
bls381_helpers::{
gs::{CProof, CRS, PPE},
hash_with_domain_separation, pairing_product, Scalar, G1G2,
hash_with_domain_separation, pairing_product, Gt, Scalar, G1G2,
},
pedersen::{
self, get_parameters, Commitment, MultiBasePublicParameters, Opening, ProofMultiIndex,
Expand Down Expand Up @@ -213,6 +213,21 @@ pub struct Proof {
gs_pi_1: CProof,
}

fn setup_ppe(target: Gt) -> PPE {
let pp2 = get_parameters();

let a_consts = vec![pp2.g.0.into()];
let b_consts = vec![pp2.g.1.into()];
let gamma = vec![vec![Scalar::zero()]];

PPE {
a_consts,
b_consts,
gamma,
target,
}
}

pub fn appcred(
attributes: &[Scalar],
signatures: &[Signature],
Expand Down Expand Up @@ -249,20 +264,12 @@ pub fn appcred(
let g1_1_vars = vec![zeta.0 .0.into()];
let g2_2_vars = vec![zeta.0 .1.into()];

let a_consts = vec![pp2.g.0.into()];
let b_consts = vec![pp2.g.1.into()];
let gamma = vec![vec![Scalar::zero()]];
let target = pairing_product(&[(&zeta.0, &pp2.g), (&pp2.g, &zeta.0)]);

// this is limitation of the GS implementation, we can only do one equation
// where both variables in G1 and G2 are used; hence we prove the product of
// these two equations to understand the performance characteristics
let equ_1 = PPE {
a_consts,
b_consts,
gamma,
target,
};
let equ_1 = setup_ppe(target);
let gs_pi_1 = equ_1.commit_and_prove(&g1_1_vars, &g2_2_vars, &pp.crs, &mut rng);

let pi = tau.proof_multi_index_commit(
Expand Down Expand Up @@ -303,20 +310,11 @@ pub fn verifycred(
.sum();
let pk = &pp.atact_pp.pk;
let tau = &cred.tau;
let pp2 = get_parameters();
let check = h + &tau.0;

let a_consts = vec![pp2.g.0.into()];
let b_consts = vec![pp2.g.1.into()];
let gamma = vec![vec![Scalar::zero()]];
let target = pairing_product(&[(&check, &pk.0), (&pk.0, &check)]);

let equ_1 = PPE {
a_consts,
b_consts,
gamma,
target,
};
let equ_1 = setup_ppe(target);
if equ_1.verify(&pi.gs_pi_1, &pp.crs) {
Ok(())
} else {
Expand Down

0 comments on commit 8c4fcca

Please sign in to comment.