Skip to content

Commit

Permalink
refactor: get random g1 vec method on PublicParameters for pub use in…
Browse files Browse the repository at this point in the history
… sxt-db

fmt

revert function name change

rand impl for public parameters

refactor
  • Loading branch information
Dustin-Ray committed Oct 3, 2024
1 parent 22e06ae commit 0ffe3df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion crates/proof-of-sql/src/proof_primitive/dory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type GT = ark_ec::pairing::PairingOutput<ark_bls12_381::Bls12_381>;
mod rand_util;
#[cfg(test)]
use rand_util::rand_F_tensors;
#[cfg(any(test, feature = "test"))]
#[cfg(test)]
use rand_util::rand_G_vecs;
#[cfg(any(test, feature = "test"))]
pub use rand_util::test_rng;
Expand Down
23 changes: 16 additions & 7 deletions crates/proof-of-sql/src/proof_primitive/dory/public_parameters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use super::{G1Affine, G2Affine};
use alloc::vec::Vec;
use ark_ff::UniformRand;
use ark_std::rand::{CryptoRng, Rng};
use core::iter;

/// The public parameters for the Dory protocol. See section 5 of https://eprint.iacr.org/2020/1274.pdf for details.
///
/// Note: even though H_1 and H_2 are marked as blue, they are still needed.
Expand All @@ -21,14 +25,19 @@ pub struct PublicParameters {
}

impl PublicParameters {
/// Generate cryptographically secure random public parameters.
pub fn crypto_rand<R: CryptoRng + Rng + ?Sized>(max_nu: usize, rng: &mut R) -> Self {
Self::rand_impl(max_nu, rng)
}
#[cfg(any(test, feature = "test"))]
/// Generate random public parameters for testing purposes.
pub fn rand<R>(max_nu: usize, rng: &mut R) -> Self
where
R: ark_std::rand::Rng + ?Sized,
{
use ark_std::UniformRand;
let (Gamma_1, Gamma_2) = super::rand_G_vecs(max_nu, rng);
/// Generate random public parameters.
pub fn rand<R: Rng + ?Sized>(max_nu: usize, rng: &mut R) -> Self {
Self::rand_impl(max_nu, rng)
}
fn rand_impl<R: Rng + ?Sized>(max_nu: usize, rng: &mut R) -> Self {
let (Gamma_1, Gamma_2) = iter::repeat_with(|| (G1Affine::rand(rng), G2Affine::rand(rng)))
.take(1 << max_nu)
.unzip();
let (H_1, H_2) = (G1Affine::rand(rng), G2Affine::rand(rng));
let Gamma_2_fin = G2Affine::rand(rng);

Expand Down
1 change: 1 addition & 0 deletions crates/proof-of-sql/src/proof_primitive/dory/rand_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn test_seed_rng(seed: [u8; 32]) -> impl Rng {
StdRng::from_seed(seed)
}

#[allow(dead_code)]
/// Creates two vectors of random G1 and G2 elements with length 2^nu.
pub fn rand_G_vecs<R>(nu: usize, rng: &mut R) -> (Vec<G1Affine>, Vec<G2Affine>)
where
Expand Down

0 comments on commit 0ffe3df

Please sign in to comment.