Skip to content

Commit

Permalink
Provide a RingContext constructor from SRS params
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 4, 2024
1 parent 79d05ff commit d127934
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ where
pub domain_size: usize,
}

const RING_DOMAIN_OVERHEAD: usize = 257;

impl<S: RingSuite> RingContext<S>
where
BaseField<S>: ark_ff::PrimeField,
Expand All @@ -164,16 +166,26 @@ where
/// Construct a new random ring context suitable for the given ring size.
pub fn new_random<R: ark_std::rand::RngCore>(ring_size: usize, rng: &mut R) -> Self {
use fflonk::pcs::PCS;
const RING_DOMAIN_OVERHEAD: usize = 257;

let domain_size = 1 << ark_std::log2(ring_size + RING_DOMAIN_OVERHEAD);
let pcs_params = Pcs::<S>::setup(3 * domain_size, rng);
Self::from_srs(pcs_params, ring_size).expect("PCS params is correct")
}

pub fn from_srs(mut pcs_params: PcsParams<S>, ring_size: usize) -> Result<Self, ()> {
let domain_size = 1 << ark_std::log2(ring_size + RING_DOMAIN_OVERHEAD);
if pcs_params.powers_in_g1.len() < 3 * domain_size + 1 || pcs_params.powers_in_g2.len() < 2
{
return Err(());
}
// 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);
Self {
Ok(Self {
pcs_params,
piop_params,
domain_size,
}
})
}

/// The max ring size this context is able to manage.
Expand Down Expand Up @@ -291,7 +303,7 @@ impl<C: utils::ark_next::MapConfig> IntoSW<C> for ark_ec::twisted_edwards::Affin
}
}

fn make_piop_params<S: RingSuite>(domain_size: usize) -> PiopParams<S>
pub(crate) fn make_piop_params<S: RingSuite>(domain_size: usize) -> PiopParams<S>
where
BaseField<S>: ark_ff::PrimeField,
CurveConfig<S>: SWCurveConfig,
Expand Down
2 changes: 2 additions & 0 deletions src/suites/bandersnatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub mod weierstrass {
use super::*;
use crate::ring as ring_suite;

pub type PcsParams = ring_suite::PcsParams<BandersnatchSha512Tai>;
pub type RingContext = ring_suite::RingContext<BandersnatchSha512Tai>;
pub type VerifierKey = ring_suite::VerifierKey<BandersnatchSha512Tai>;
pub type RingProver = ring_suite::RingProver<BandersnatchSha512Tai>;
Expand Down Expand Up @@ -176,6 +177,7 @@ pub mod edwards {
use super::*;
use crate::ring as ring_suite;

pub type PcsParams = ring_suite::PcsParams<BandersnatchSha512Ell2>;
pub type RingContext = ring_suite::RingContext<BandersnatchSha512Ell2>;
pub type VerifierKey = ring_suite::VerifierKey<BandersnatchSha512Ell2>;
pub type RingProver = ring_suite::RingProver<BandersnatchSha512Ell2>;
Expand Down

0 comments on commit d127934

Please sign in to comment.