Skip to content

Commit

Permalink
Simplify ring construction by hiding domain size
Browse files Browse the repository at this point in the history
  • Loading branch information
davxy committed Jul 2, 2024
1 parent ccdb004 commit 79d05ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions src/ring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,19 @@ where
CurveConfig<S>: SWCurveConfig + Clone,
AffinePoint<S>: IntoSW<CurveConfig<S>>,
{
pub fn from_seed(domain_size: usize, seed: [u8; 32]) -> Self {
/// Construct a new ring context suitable to manage the given ring size.
pub fn from_seed(ring_size: usize, seed: [u8; 32]) -> Self {
use ark_std::rand::SeedableRng;
let mut rng = rand_chacha::ChaCha20Rng::from_seed(seed);
Self::new_random(domain_size, &mut rng)
Self::new_random(ring_size, &mut rng)
}

pub fn new_random<R: ark_std::rand::RngCore>(domain_size: usize, rng: &mut R) -> Self {
/// 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);
let piop_params = make_piop_params::<S>(domain_size);
Self {
Expand All @@ -172,11 +176,8 @@ where
}
}

pub fn domain_size(&self) -> usize {
self.domain_size
}

pub fn keyset_max_size(&self) -> usize {
/// The max ring size this context is able to manage.
pub fn max_ring_size(&self) -> usize {
self.piop_params.keyset_part_size
}

Expand Down
7 changes: 3 additions & 4 deletions src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,17 @@ where
use ring::{Prover, RingContext, Verifier};

let rng = &mut ark_std::test_rng();
let domain_size = 1024;
let ring_ctx = RingContext::<S>::new_random(domain_size, rng);
let ring_ctx = RingContext::<S>::new_random(512, rng);

let secret = Secret::<S>::from_seed(TEST_SEED);
let public = secret.public();
let input = Input::from(random_val(Some(rng)));
let output = secret.output(input);

let keyset_size = ring_ctx.piop_params.keyset_part_size;
let ring_size = ring_ctx.max_ring_size();

let prover_idx = 3;
let mut pks = random_vec::<AffinePoint<S>>(keyset_size, Some(rng));
let mut pks = random_vec::<AffinePoint<S>>(ring_size, Some(rng));
pks[prover_idx] = public.0;

let prover_key = ring_ctx.prover_key(&pks);
Expand Down

0 comments on commit 79d05ff

Please sign in to comment.