Skip to content

Commit

Permalink
feat: add ratio_check_is_correct test & more documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Boyuan Feng committed Jul 29, 2022
1 parent dc58951 commit 4e85bab
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
27 changes: 27 additions & 0 deletions manta-trusted-setup/src/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,30 @@ pub trait PairingEngineExt: PairingEngine {
}

impl<E> PairingEngineExt for E where E: PairingEngine {}

#[cfg(test)]
mod test {
use crate::{pairing::PairingEngineExt, util::Sample};
use ark_bls12_381::{Bls12_381, Fr, G1Affine, G2Affine};
use ark_ec::{AffineCurve, ProjectiveCurve};
use manta_crypto::rand::OsRng;

/// Tests if the ratio check is correct.
#[test]
fn ratio_check_is_correct() {
let mut rng = OsRng;
let g1 = G1Affine::gen(&mut rng);
let g2 = G2Affine::gen(&mut rng);
let scalar = Fr::gen(&mut rng);
assert!(Bls12_381::same(
(g1, g2.mul(scalar).into_affine()),
(g1.mul(scalar).into_affine(), g2)
)
.is_some());
assert!(!Bls12_381::same(
(g1, g2.mul(scalar).into_affine()),
(g1.mul(Fr::gen(&mut rng)).into_affine(), g2)
)
.is_some())
}
}
17 changes: 12 additions & 5 deletions manta-trusted-setup/src/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ where
fn hash(&self, challenge: &C, ratio: (&P::G1, &P::G1)) -> P::G2;
}

/// Prepared Ratio Proof Type
pub type PreparedRatioProof<P> = (
/// Prepared Ratio Type
///
/// # Note
///
/// Expected format is `((g1, r * g1), (r * g2, g2))` given curve points
/// [`g1`](Pairing::G1Prepared), [`g2`](Pairing::G2Prepared) and a scalar [`r`](Pairing::Scalar).
pub type PreparedRatio<P> = (
(<P as Pairing>::G1Prepared, <P as Pairing>::G1Prepared),
(<P as Pairing>::G2Prepared, <P as Pairing>::G2Prepared),
);
Expand All @@ -44,10 +49,12 @@ pub struct RatioProof<P>
where
P: Pairing + ?Sized,
{
/// Ratio in G1
/// Ratio in G1 of the form `(g1, r * g1)` given a curve point [`g1`](Pairing::G1) and
/// a scalar [`r`](Pairing::Scalar)
pub ratio: (P::G1, P::G1),

/// Matching Point in G2
/// Matching Point in G2 of the form [`r * g2`](Pairing::G2) given a challenge point
/// [`g2`](Pairing::G2) and a scalar [`r`](Pairing::Scalar)
pub matching_point: P::G2,
}

Expand Down Expand Up @@ -103,7 +110,7 @@ where
/// Verifies that `self` is a valid ratio proof-of-knowledge, returning the ratio of the
/// underlying scalar.
#[inline]
pub fn verify<H, C>(self, hasher: &H, challenge: &C) -> Option<PreparedRatioProof<P>>
pub fn verify<H, C>(self, hasher: &H, challenge: &C) -> Option<PreparedRatio<P>>
where
H: HashToGroup<P, C>,
{
Expand Down
1 change: 1 addition & 0 deletions workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ serde = { version = "1.0.140", features = ["alloc", "derive", "serde_derive", "s
standback = { version = "0.2.17", default-features = false, features = ["std"] }
subtle = { version = "2.4.1", default-features = false, features = ["i128"] }
syn = { version = "1.0.98", features = ["clone-impls", "derive", "extra-traits", "fold", "full", "parsing", "printing", "proc-macro", "quote", "visit", "visit-mut"] }

### END HAKARI SECTION

0 comments on commit 4e85bab

Please sign in to comment.