Skip to content

Commit

Permalink
Cleanup ring context constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 10, 2024
1 parent 5be98cc commit 2941337
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub trait Suite: Copy + Clone {
/// # Panics
///
/// This function panics if `Hasher` output is less than 64 bytes.
#[inline(always)]
fn nonce(sk: &ScalarField<Self>, pt: Input<Self>) -> ScalarField<Self> {
utils::nonce_rfc_8032::<Self>(sk, &pt.0)
}
Expand All @@ -122,20 +123,23 @@ pub trait Suite: Copy + Clone {
///
/// This implementation extends the RFC procedure to allow adding
/// some optional additional data too the hashing procedure.
#[inline(always)]
fn challenge(pts: &[&AffinePoint<Self>], ad: &[u8]) -> ScalarField<Self> {
utils::challenge_rfc_9381::<Self>(pts, ad)
}

/// Hash data to a curve point.
///
/// By default uses "try and increment" method described by RFC 9381.
#[inline(always)]
fn data_to_point(data: &[u8]) -> Option<AffinePoint<Self>> {
utils::hash_to_curve_tai_rfc_9381::<Self>(data)
}

/// Map the point to a hash value using `Self::Hasher`.
///
/// By default uses the algorithm described by RFC 9381.
#[inline(always)]
fn point_to_hash(pt: &AffinePoint<Self>) -> HashOutput<Self> {
utils::point_to_hash_rfc_9381::<Self>(pt)
}
Expand Down
29 changes: 9 additions & 20 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,13 @@ where
// Keep only the required powers of tau.
pcs_params.powers_in_g1.truncate(3 * domain_size + 1);
pcs_params.powers_in_g2.truncate(2);
let piop_params = make_piop_params::<S>(domain_size);

let piop_params = PiopParams::<S>::setup(
ring_proof::Domain::new(domain_size, true),
S::BLINDING_BASE.into_sw(),
S::COMPLEMENT_POINT.into_sw(),
);

Ok(Self {
pcs_params,
piop_params,
Expand Down Expand Up @@ -266,11 +272,8 @@ where
validate,
)?;
let domain_size = (pcs_params.powers_in_g1.len() - 1) / 3;
let piop_params = make_piop_params::<S>(domain_size);
Ok(RingContext {
piop_params,
pcs_params,
})
Self::from_srs(domain_size, pcs_params)
.map_err(|_| ark_serialize::SerializationError::InvalidData)
}
}

Expand All @@ -284,17 +287,3 @@ where
self.pcs_params.check()
}
}

pub(crate) fn make_piop_params<S: RingSuite>(domain_size: usize) -> PiopParams<S>
where
BaseField<S>: ark_ff::PrimeField,
CurveConfig<S>: SWCurveConfig,
AffinePoint<S>: SWMapping<CurveConfig<S>>,
{
let domain = ring_proof::Domain::new(domain_size, true);
PiopParams::<S>::setup(
domain,
S::BLINDING_BASE.into_sw(),
S::COMPLEMENT_POINT.into_sw(),
)
}

0 comments on commit 2941337

Please sign in to comment.