diff --git a/src/ring.rs b/src/ring.rs index d523181..15bc398 100644 --- a/src/ring.rs +++ b/src/ring.rs @@ -91,11 +91,14 @@ const fn piop_domain_size_from_pcs_domain_size(pcs_domain_size: usize) -> usize } /// Ring suite. -pub trait RingSuite: PedersenSuite -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, +/// +/// This trait provides the cryptographic primitives needed for ring VRF signatures. +/// All required bounds are expressed directly on the associated type for better ergonomics. +pub trait RingSuite: + PedersenSuite< + Affine: AffineRepr + + TEMapping<::Config>, +> { /// Pairing type. type Pairing: ark_ec::pairing::Pairing>; @@ -156,12 +159,7 @@ pub type RingBareProof = ring_proof::RingProof, Pcs>; /// - `pedersen_proof`: Key commitment and VRF correctness proof /// - `ring_proof`: Membership proof binding the commitment to the ring #[derive(Clone, CanonicalSerialize, CanonicalDeserialize)] -pub struct Proof -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, -{ +pub struct Proof { pub pedersen_proof: PedersenProof, pub ring_proof: RingBareProof, } @@ -170,12 +168,7 @@ where /// /// Implementors can create anonymous proofs that a VRF output /// is correctly derived using a secret key from a ring of public keys. -pub trait Prover -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, -{ +pub trait Prover { /// Generate a proof for the given input/output and additional data. /// /// Creates a zero-knowledge proof that: @@ -199,12 +192,7 @@ where /// /// Implementors can verify anonymous proofs that a VRF output /// was derived using a secret key from a ring of public keys. -pub trait Verifier -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, -{ +pub trait Verifier { /// Verify a proof for the given input/output and additional data. /// /// Verifies that: @@ -228,12 +216,7 @@ where ) -> Result<(), Error>; } -impl Prover for Secret -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, -{ +impl Prover for Secret { fn prove( &self, input: Input, @@ -252,12 +235,7 @@ where } } -impl Verifier for Public -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig, - AffinePoint: TEMapping>, -{ +impl Verifier for Public { fn verify( input: Input, output: Output, @@ -281,24 +259,14 @@ where /// - `pcs`: Polynomial Commitment Scheme parameters (KZG setup) /// - `piop`: Polynomial Interactive Oracle Proof parameters #[derive(Clone)] -pub struct RingProofParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +pub struct RingProofParams { /// PCS parameters. pub pcs: PcsParams, /// PIOP parameters. pub piop: PiopParams, } -pub(crate) fn piop_params(domain_size: usize) -> PiopParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +pub(crate) fn piop_params(domain_size: usize) -> PiopParams { PiopParams::::setup( ring_proof::Domain::new(domain_size, true), S::BLINDING_BASE.into_te(), @@ -307,12 +275,7 @@ where ) } -impl RingProofParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl RingProofParams { /// Construct deterministic ring proof params for the given ring size. /// /// Creates parameters using a deterministic `ChaCha20Rng` seeded with `seed`. @@ -463,12 +426,7 @@ where } } -impl CanonicalSerialize for RingProofParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl CanonicalSerialize for RingProofParams { fn serialize_with_mode( &self, mut writer: W, @@ -482,12 +440,7 @@ where } } -impl CanonicalDeserialize for RingProofParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl CanonicalDeserialize for RingProofParams { fn deserialize_with_mode( mut reader: R, compress: ark_serialize::Compress, @@ -506,12 +459,7 @@ where } } -impl ark_serialize::Valid for RingProofParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl ark_serialize::Valid for RingProofParams { fn check(&self) -> Result<(), ark_serialize::SerializationError> { self.pcs.check() } @@ -522,11 +470,7 @@ where /// Basically the SRS in Lagrangian form. /// Can be constructed via the `PcsParams::ck_with_lagrangian()` method. #[derive(Clone, CanonicalSerialize, CanonicalDeserialize)] -pub struct RingBuilderPcsParams(pub Vec>) -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>; +pub struct RingBuilderPcsParams(pub Vec>); // Under construction ring commitment. type PartialRingCommitment = @@ -539,12 +483,7 @@ type RawVerifierKey = as ring_proof::pcs::PcsParams>::RVK; /// Allows constructing a verifier key by adding public keys in batches, /// which is useful for large rings or memory-constrained environments. #[derive(Clone, CanonicalSerialize, CanonicalDeserialize)] -pub struct RingVerifierKeyBuilder -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +pub struct RingVerifierKeyBuilder { partial: PartialRingCommitment, raw_vk: RawVerifierKey, } @@ -555,33 +494,20 @@ pub type G2Affine = <::Pairing as Pairing>::G2Affine; /// Trait for accessing Structured Reference String entries in Lagrangian basis. /// /// Provides access to precomputed SRS elements needed for efficient ring operations. -pub trait SrsLookup -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +pub trait SrsLookup { fn lookup(&self, range: Range) -> Option>>; } impl SrsLookup for F where F: Fn(Range) -> Option>>, - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, { fn lookup(&self, range: Range) -> Option>> { self(range) } } -impl SrsLookup for &RingBuilderPcsParams -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl SrsLookup for &RingBuilderPcsParams { fn lookup(&self, range: Range) -> Option>> { if range.end > self.0.len() { return None; @@ -590,12 +516,7 @@ where } } -impl RingVerifierKeyBuilder -where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, -{ +impl RingVerifierKeyBuilder { /// Create a new empty ring verifier key builder. /// /// * `params` - Ring proof parameters @@ -740,12 +661,7 @@ pub(crate) mod testing { } #[allow(unused)] - pub fn prove_verify() - where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, - { + pub fn prove_verify() { let rng = &mut ark_std::test_rng(); let params = RingProofParams::::from_rand(TEST_RING_SIZE, rng); @@ -781,9 +697,7 @@ pub(crate) mod testing { #[allow(unused)] pub fn padding_check() where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping> + CheckPoint, + AffinePoint: CheckPoint, { // Check that point has been computed using the magic spell. assert_eq!(S::PADDING, S::data_to_point(PADDING_SEED).unwrap()); @@ -795,9 +709,7 @@ pub(crate) mod testing { #[allow(unused)] pub fn accumulator_base_check() where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping> + FindAccumulatorBase + CheckPoint, + AffinePoint: FindAccumulatorBase + CheckPoint, { // Check that point has been computed using the magic spell. assert_eq!( @@ -812,12 +724,7 @@ pub(crate) mod testing { } #[allow(unused)] - pub fn verifier_key_builder() - where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, - { + pub fn verifier_key_builder() { use crate::testing::{random_val, random_vec}; let rng = &mut ark_std::test_rng(); @@ -893,12 +800,7 @@ pub(crate) mod testing { }; } - pub trait RingSuiteExt: RingSuite + crate::testing::SuiteExt - where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, - { + pub trait RingSuiteExt: RingSuite + crate::testing::SuiteExt { const SRS_FILE: &str; fn params() -> &'static RingProofParams; @@ -927,24 +829,14 @@ pub(crate) mod testing { } } - pub struct TestVector - where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, - { + pub struct TestVector { pub pedersen: pedersen::testing::TestVector, pub ring_pks: [AffinePoint; TEST_RING_SIZE], pub ring_pks_com: RingCommitment, pub ring_proof: RingBareProof, } - impl core::fmt::Debug for TestVector - where - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, - { + impl core::fmt::Debug for TestVector { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { f.debug_struct("TestVector") .field("pedersen", &self.pedersen) @@ -956,9 +848,6 @@ pub(crate) mod testing { impl common::TestVectorTrait for TestVector where S: RingSuiteExt + std::fmt::Debug + 'static, - BaseField: ark_ff::PrimeField, - CurveConfig: TECurveConfig + Clone, - AffinePoint: TEMapping>, { fn name() -> String { S::suite_name() + "_ring" diff --git a/src/utils/te_sw_map.rs b/src/utils/te_sw_map.rs index ea6d517..d7ed59f 100644 --- a/src/utils/te_sw_map.rs +++ b/src/utils/te_sw_map.rs @@ -4,9 +4,9 @@ //! allowing operations to be performed in the most convenient form for a given task. use ark_ec::{ + CurveConfig, short_weierstrass::{Affine as SWAffine, SWCurveConfig}, twisted_edwards::{Affine as TEAffine, MontCurveConfig, TECurveConfig}, - CurveConfig, }; use ark_ff::{Field, One}; use ark_std::borrow::Cow;