Skip to content

Commit

Permalink
Misc nitpicks (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy authored Aug 19, 2024
1 parent 8cef209 commit 0175c3c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ secp256r1 = [
ed25519 = [ "ark-ed25519" ]
bandersnatch = [ "ark-ed-on-bls12-381-bandersnatch" ]
ring = [
"bandersnatch",
"ring-proof",
"ark-bls12-381/curve",
]
Expand Down
1 change: 1 addition & 0 deletions src/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::ietf::IetfSuite;
use crate::*;

pub trait PedersenSuite: IetfSuite {
/// Blinding base.
const BLINDING_BASE: AffinePoint<Self>;

/// Pedersen blinding factor.
Expand Down
27 changes: 16 additions & 11 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ pub trait RingSuite: PedersenSuite {
/// Pairing type.
type Pairing: ark_ec::pairing::Pairing<ScalarField = BaseField<Self>>;

/// Complement point.
const COMPLEMENT_POINT: AffinePoint<Self>;
/// Accumulator base.
///
/// In order for the ring-proof backend to work correctly, this is required to be
/// in the prime order subgroup.
const ACCUMULATOR_BASE: AffinePoint<Self>;
}

/// Polinomial Commitment Scheme (KZG)
Expand Down Expand Up @@ -189,7 +192,7 @@ where
let piop_params = PiopParams::<S>::setup(
ring_proof::Domain::new(domain_size, true),
S::BLINDING_BASE.into_sw(),
S::COMPLEMENT_POINT.into_sw(),
S::ACCUMULATOR_BASE.into_sw(),
);

Ok(Self {
Expand Down Expand Up @@ -313,6 +316,7 @@ pub(crate) mod testing {

pub const TEST_RING_SIZE: usize = 8;

#[allow(unused)]
pub fn prove_verify<S: RingSuite>()
where
BaseField<S>: ark_ff::PrimeField,
Expand Down Expand Up @@ -343,34 +347,35 @@ pub(crate) mod testing {
assert!(result.is_ok());
}

pub fn check_complement_point<S: RingSuite>()
/// Check that complement point is not in the prime subgroup.
///
/// This is a requirement for the correct working of ring-proof backend.
#[allow(unused)]
pub fn check_accumulator_base<S: RingSuite>()
where
BaseField<S>: ark_ff::PrimeField,
CurveConfig<S>: ark_ec::short_weierstrass::SWCurveConfig + Clone,
AffinePoint<S>: utils::te_sw_map::SWMapping<CurveConfig<S>>,
{
use utils::te_sw_map::SWMapping;
let pt = S::COMPLEMENT_POINT.into_sw();
let pt = S::ACCUMULATOR_BASE.into_sw();
assert!(pt.is_on_curve());
assert!(!pt.is_in_correct_subgroup_assuming_on_curve());
}

#[macro_export]
macro_rules! ring_suite_tests {
($suite:ident, true) => {
#[cfg(feature = "ring")]
($suite:ident) => {
#[test]
fn ring_prove_verify() {
$crate::ring::testing::prove_verify::<$suite>()
}

#[cfg(feature = "ring")]
#[test]
fn check_complement_point() {
$crate::ring::testing::check_complement_point::<$suite>()
fn check_accumulator_base() {
$crate::ring::testing::check_accumulator_base::<$suite>()
}
};
($suite:ident, false) => {};
}

pub trait RingSuiteExt: RingSuite
Expand Down
18 changes: 13 additions & 5 deletions src/suites/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub mod weierstrass {
/// A point on the curve not belonging to the prime order subgroup.
///
/// Found using `ring_proof::find_complement_point::<Self::Config>()` function.
const COMPLEMENT_POINT: AffinePoint = {
const ACCUMULATOR_BASE: AffinePoint = {
const X: BaseField = MontFp!("0");
const Y: BaseField = MontFp!(
"11982629110561008531870698410380659621661946968466267969586599013782997959645"
Expand All @@ -113,8 +113,11 @@ pub mod weierstrass {
#[cfg(feature = "ring")]
pub use ring_defs::*;

#[cfg(all(test, feature = "ring"))]
ring_suite_tests!(BandersnatchSha512Tai);

#[cfg(test)]
suite_tests!(BandersnatchSha512Tai, true);
suite_tests!(BandersnatchSha512Tai);
}

pub mod edwards {
Expand Down Expand Up @@ -143,7 +146,7 @@ pub mod edwards {
}

impl PedersenSuite for BandersnatchSha512Ell2 {
/// Found mapping the `BLINDING_BASE` of `weierstrass` module using the `utils::map_sw_to_te`
/// Found mapping `BLINDING_BASE` of `weierstrass` module using the `utils::map_sw_to_te`
const BLINDING_BASE: AffinePoint = {
const X: BaseField = MontFp!(
"14576224270591906826192118712803723445031237947873156025406837473427562701854"
Expand Down Expand Up @@ -190,7 +193,7 @@ pub mod edwards {
/// A point on the curve not belonging to the prime order subgroup.
///
/// Found mapping the `COMPLEMENT_POINT` of `weierstrass` module using the `utils::map_sw_to_te`
const COMPLEMENT_POINT: AffinePoint = {
const ACCUMULATOR_BASE: AffinePoint = {
const X: BaseField = MontFp!(
"3955725774225903122339172568337849452553276548604445833196164961773358506589"
);
Expand All @@ -204,8 +207,11 @@ pub mod edwards {
#[cfg(feature = "ring")]
pub use ring_defs::*;

#[cfg(all(test, feature = "ring"))]
ring_suite_tests!(BandersnatchSha512Ell2);

#[cfg(test)]
suite_tests!(BandersnatchSha512Ell2, true);
suite_tests!(BandersnatchSha512Ell2);

#[test]
fn elligator2_hash_to_curve() {
Expand Down Expand Up @@ -242,6 +248,8 @@ mod tests {

let sw_point = map_te_to_sw::<BandersnatchConfig>(&te_point).unwrap();
assert!(sw_point.is_on_curve());

assert_eq!(org_point, sw_point);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn random_val<T: UniformRand>(rng: Option<&mut dyn RngCore>) -> T {

#[macro_export]
macro_rules! suite_tests {
($suite:ident, $build_ring:ident) => {
($suite:ident, $build_ring:expr) => {
suite_tests!($suite);
ring_suite_tests!($suite, $build_ring);
};
Expand Down

0 comments on commit 0175c3c

Please sign in to comment.