Skip to content

Commit

Permalink
♻️ Move out most of PubUniformRand
Browse files Browse the repository at this point in the history
  • Loading branch information
taskooh committed Oct 24, 2023
1 parent 362ddda commit b76ebc2
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 26 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"./Cargo.toml",
"./mpc-algebra/Cargo.toml",
"./mpc-net/Cargo.toml",
"./mpc-trait/Cargo.toml",
"./arkworks/marlin/Cargo.toml",
"./arkworks/poly-commit/Cargo.toml"
]
Expand Down
1 change: 0 additions & 1 deletion arkworks/algebra/ff/src/fields/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ macro_rules! impl_prime_field_standard_sample {
}
}
}
impl<P: $params> crate::PubUniformRand for $field<P> {}
};
}

Expand Down
3 changes: 1 addition & 2 deletions arkworks/algebra/ff/src/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
biginteger::BigInteger,
bytes::{FromBytes, ToBytes},
fields::utils::k_adicity,
PubUniformRand, UniformRand,
UniformRand,
};
use ark_serialize::{
CanonicalDeserialize, CanonicalDeserializeWithFlags, CanonicalSerialize,
Expand Down Expand Up @@ -88,7 +88,6 @@ pub trait Field:
+ Ord
+ Neg<Output = Self>
+ UniformRand
+ PubUniformRand
+ Zeroize
+ Sized
+ Hash
Expand Down
4 changes: 1 addition & 3 deletions arkworks/algebra/ff/src/fields/models/cubic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ark_std::rand::{
use crate::{
bytes::{FromBytes, ToBytes},
fields::{Field, PrimeField},
PubUniformRand, ToConstraintField, UniformRand,
ToConstraintField, UniformRand,
};

pub trait CubicExtParameters: 'static + Send + Sync {
Expand Down Expand Up @@ -455,8 +455,6 @@ impl<P: CubicExtParameters> Distribution<CubicExtField<P>> for Standard {
}
}

impl<P: CubicExtParameters> PubUniformRand for CubicExtField<P> {}

impl<'a, P: CubicExtParameters> Add<&'a CubicExtField<P>> for CubicExtField<P> {
type Output = Self;

Expand Down
4 changes: 1 addition & 3 deletions arkworks/algebra/ff/src/fields/models/quadratic_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use ark_std::rand::{
use crate::{
bytes::{FromBytes, ToBytes},
fields::{Field, LegendreSymbol, PrimeField, SquareRootField},
PubUniformRand, ToConstraintField, UniformRand,
ToConstraintField, UniformRand,
};

/// Defines a Quadratic extension field from a quadratic non-residue.
Expand Down Expand Up @@ -566,8 +566,6 @@ impl<P: QuadExtParameters> Distribution<QuadExtField<P>> for Standard {
}
}

impl<P: QuadExtParameters> PubUniformRand for QuadExtField<P> {}

impl<'a, P: QuadExtParameters> Add<&'a QuadExtField<P>> for QuadExtField<P> {
type Output = Self;

Expand Down
4 changes: 2 additions & 2 deletions arkworks/algebra/ff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use self::fields::*;
#[cfg(test)]
mod test_field;

pub use ark_std::{PubUniformRand, UniformRand};
pub use ark_std::UniformRand;

mod to_field_vec;
pub use to_field_vec::ToConstraintField;
Expand All @@ -41,7 +41,7 @@ pub mod prelude {

pub use crate::fields::{Field, FpParameters, PrimeField, SquareRootField};

pub use ark_std::{PubUniformRand, UniformRand};
pub use ark_std::UniformRand;

pub use num_traits::{One, Zero};
}
Expand Down
8 changes: 4 additions & 4 deletions arkworks/marlin/src/ahp/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl<F: PrimeField> AHPForR1CS<F> {
.ok_or(SynthesisError::PolynomialDegreeTooLarge)?;

let alpha = domain_h.sample_element_outside_domain(rng, true);
let eta_a = F::pub_rand(rng);
let eta_b = F::pub_rand(rng);
let eta_c = F::pub_rand(rng);
let eta_a = F::rand(rng);
let eta_b = F::rand(rng);
let eta_c = F::rand(rng);

let msg = VerifierFirstMsg {
alpha,
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<F: PrimeField> AHPForR1CS<F> {
mut state: VerifierState<F>,
rng: &mut R,
) -> VerifierState<F> {
state.gamma = Some(F::pub_rand(rng));
state.gamma = Some(F::rand(rng));
state
}

Expand Down
2 changes: 0 additions & 2 deletions arkworks/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ rayon = { version = "1", optional = true }
colored = { version = "2", optional = true }
num-traits = { version = "0.2", default-features = false }

mpc-trait = {path = "../../mpc-trait" }

[features]
default = [ "std" ]
std = []
Expand Down
7 changes: 0 additions & 7 deletions arkworks/std/src/rand_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ use rand::{
Rng,
};

use mpc_trait::MpcWire;
pub use rand;

pub trait UniformRand: Sized {
fn rand<R: Rng + ?Sized>(rng: &mut R) -> Self;
}

pub trait PubUniformRand: Sized + MpcWire + UniformRand {
fn pub_rand<R: Rng + ?Sized>(rng: &mut R) -> Self {
<Self as UniformRand>::rand(rng)
}
}

impl<T> UniformRand for T
where
Standard: Distribution<T>,
Expand Down
18 changes: 18 additions & 0 deletions mpc-algebra/src/fields.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use ark_ff::{CubicExtField, CubicExtParameters, QuadExtField, QuadExtParameters};
use ark_ff::{
Fp256, Fp256Parameters, Fp320, Fp320Parameters, Fp384, Fp384Parameters, Fp448, Fp448Parameters,
Fp64, Fp64Parameters, Fp768, Fp768Parameters, Fp832, Fp832Parameters,
};
use mpc_trait::PubUniformRand;

use crate::impl_Fp_mpc;
impl<P: QuadExtParameters> PubUniformRand for QuadExtField<P> {}
impl<P: CubicExtParameters> PubUniformRand for CubicExtField<P> {}

impl_Fp_mpc!(Fp64, Fp64Parameters);
impl_Fp_mpc!(Fp256, Fp256Parameters);
impl_Fp_mpc!(Fp320, Fp320Parameters);
impl_Fp_mpc!(Fp384, Fp384Parameters);
impl_Fp_mpc!(Fp448, Fp448Parameters);
impl_Fp_mpc!(Fp768, Fp768Parameters);
impl_Fp_mpc!(Fp832, Fp832Parameters);
3 changes: 3 additions & 0 deletions mpc-algebra/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// #![feature(associated_type_defaults)]

pub mod reveal;
mod fields;
#[macro_use]
pub mod macros;
pub use reveal::*;
pub mod share;
pub use share::*;
Expand Down
6 changes: 6 additions & 0 deletions mpc-algebra/src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[macro_export]
macro_rules! impl_Fp_mpc {
($Fp:ident, $FpParameters:ident) => {
impl<P: $FpParameters> crate::PubUniformRand for $Fp<P> {}
}
}
2 changes: 1 addition & 1 deletion mpc-algebra/src/wire/field.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use derivative::Derivative;
use mpc_trait::MpcWire;
use mpc_trait::{MpcWire, PubUniformRand};
use num_bigint::BigUint;
use rand::Rng;
use std::fmt::{self, Debug, Display};
Expand Down
2 changes: 1 addition & 1 deletion mpc-algebra/src/wire/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ark_serialize::{
CanonicalSerializeWithFlags,
};
use ark_serialize::{Flags, SerializationError};
use mpc_trait::MpcWire;
use mpc_trait::{MpcWire, PubUniformRand};

use crate::share::group::GroupShare;
use crate::Reveal;
Expand Down
1 change: 1 addition & 0 deletions mpc-trait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ark-std = { path = "../arkworks/std", version = "0.3.0", features = ["std", "print-trace"] }
3 changes: 3 additions & 0 deletions mpc-trait/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod pub_rand;
pub use pub_rand::*;

use std::borrow::Cow;

pub trait MpcWire: Clone {
Expand Down
9 changes: 9 additions & 0 deletions mpc-trait/src/pub_rand.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::MpcWire;
use ark_std::rand::Rng;
pub use ark_std::UniformRand;

pub trait PubUniformRand: Sized + MpcWire + UniformRand {
fn pub_rand<R: Rng + ?Sized>(rng: &mut R) -> Self {
<Self as UniformRand>::rand(rng)
}
}

0 comments on commit b76ebc2

Please sign in to comment.