Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing some trait bound #105

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plonk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rand_chacha = { version = "0.3.1" }
sha3 = "^0.10"
espresso-systems-common = { git = "https://github.com/espressosystems/espresso-systems-common", branch = "main" }
hashbrown = "0.12.3"
dyn-clone = "^1.0"

[dependencies.ark-poly-commit]
git = "https://github.com/arkworks-rs/poly-commit/"
Expand Down
2 changes: 1 addition & 1 deletion plonk/examples/proof_of_exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn proof_of_exponent_circuit<EmbedCurve, PairingCurve>(
X: TEAffine<EmbedCurve>,
) -> Result<PlonkCircuit<EmbedCurve::BaseField>, PlonkError>
where
EmbedCurve: TEModelParameters + Clone,
EmbedCurve: TEModelParameters,
<EmbedCurve as ModelParameters>::BaseField: PrimeField,
PairingCurve: PairingEngine,
{
Expand Down
12 changes: 3 additions & 9 deletions plonk/src/circuit/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ use ark_ff::{BigInteger, FftField, PrimeField};
use ark_poly::{
domain::Radix2EvaluationDomain, univariate::DensePolynomial, EvaluationDomain, UVPolynomial,
};
use ark_std::{
boxed::Box,
cmp::max,
collections::{HashMap, HashSet},
format,
string::ToString,
vec,
vec::Vec,
};
use ark_std::{boxed::Box, cmp::max, format, string::ToString, vec, vec::Vec};
use hashbrown::{HashMap, HashSet};
#[cfg(feature = "parallel")]
use rayon::prelude::*;

/// The wire type identifier for range gates.
Expand Down
2 changes: 1 addition & 1 deletion plonk/src/circuit/customized/ecc/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use ark_ff::{BigInteger256, BigInteger384, BigInteger768, PrimeField};
impl<F, P> From<&SWAffine<P>> for Point<F>
where
F: PrimeField + SWToTEConParam,
P: SWParam<BaseField = F> + Clone,
P: SWParam<BaseField = F>,
{
fn from(p: &SWAffine<P>) -> Self {
// this function is only correct for BLS12-377
Expand Down
12 changes: 6 additions & 6 deletions plonk/src/circuit/customized/ecc/glv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ where
{
/// Perform GLV multiplication in circuit (which costs a few less
/// constraints).
pub fn glv_mul<P: TEModelParameters<BaseField = F> + Clone>(
pub fn glv_mul<P: TEModelParameters<BaseField = F>>(
&mut self,
scalar: Variable,
base: &PointVariable,
Expand All @@ -111,7 +111,7 @@ fn multi_scalar_mul_circuit<F, P>(
) -> Result<PointVariable, PlonkError>
where
F: PrimeField,
P: TEModelParameters<BaseField = F> + Clone,
P: TEModelParameters<BaseField = F>,
{
let endo_base_neg = circuit.inverse_point(endo_base)?;
let endo_base =
Expand All @@ -129,7 +129,7 @@ where
fn endomorphism<F, P>(base: &Point<F>) -> Point<F>
where
F: PrimeField,
P: TEModelParameters<BaseField = F> + Clone,
P: TEModelParameters<BaseField = F>,
{
let x = base.get_x();
let y = base.get_y();
Expand All @@ -154,7 +154,7 @@ fn endomorphism_circuit<F, P>(
) -> Result<PointVariable, PlonkError>
where
F: PrimeField,
P: TEModelParameters<BaseField = F> + Clone,
P: TEModelParameters<BaseField = F>,
{
let base = circuit.point_witness(point_var)?;
let endo_point = endomorphism::<_, P>(&base);
Expand Down Expand Up @@ -269,7 +269,7 @@ fn scalar_decomposition_gate<F, P, S>(
) -> Result<(Variable, Variable, BoolVar), PlonkError>
where
F: PrimeField,
P: TEModelParameters<BaseField = F, ScalarField = S> + Clone,
P: TEModelParameters<BaseField = F, ScalarField = S>,
S: PrimeField,
{
// the order of scalar field
Expand Down Expand Up @@ -588,7 +588,7 @@ mod tests {
fn test_glv_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();

Expand Down
58 changes: 29 additions & 29 deletions plonk/src/circuit/customized/ecc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct Point<F: PrimeField>(F, F);
impl<F, P> From<GroupAffine<P>> for Point<F>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
fn from(p: GroupAffine<P>) -> Self {
if p.is_zero() {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<F: PrimeField> Point<F> {
impl<F, P> From<GroupProjective<P>> for Point<F>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
fn from(p: GroupProjective<P>) -> Self {
let affine_repr = p.into_affine();
Expand All @@ -98,7 +98,7 @@ where
impl<F, P> From<Point<F>> for GroupAffine<P>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
fn from(p: Point<F>) -> Self {
Self::new(p.0, p.1)
Expand All @@ -108,7 +108,7 @@ where
impl<F, P> From<Point<F>> for GroupProjective<P>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
fn from(p: Point<F>) -> Self {
let affine_point: GroupAffine<P> = p.into();
Expand Down Expand Up @@ -178,7 +178,7 @@ where
/// parameters.
/// A bad PointVariable would be returned if (b0, b1) are not boolean
/// variables, that would ultimately failed to build a correct circuit.
fn quaternary_point_select<P: Parameters<BaseField = F> + Clone>(
fn quaternary_point_select<P: Parameters<BaseField = F>>(
&mut self,
b0: BoolVar,
b1: BoolVar,
Expand Down Expand Up @@ -318,7 +318,7 @@ where
/// Return error if input variables are invalid
pub fn is_neutral_point<P>(&mut self, point_var: &PointVariable) -> Result<BoolVar, PlonkError>
where
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
self.check_point_var_bound(point_var)?;

Expand All @@ -339,7 +339,7 @@ where
/// scalar field
///
/// Returns error if input variables are invalid
pub fn on_curve_gate<P: Parameters<BaseField = F> + Clone>(
pub fn on_curve_gate<P: Parameters<BaseField = F>>(
&mut self,
point_var: &PointVariable,
) -> Result<(), PlonkError> {
Expand All @@ -361,7 +361,7 @@ where
/// Currently only supports GroupAffine::<P> addition.
///
/// Returns error if the input variables are invalid.
fn ecc_add_gate<P: Parameters<BaseField = F> + Clone>(
fn ecc_add_gate<P: Parameters<BaseField = F>>(
&mut self,
point_a: &PointVariable,
point_b: &PointVariable,
Expand Down Expand Up @@ -397,7 +397,7 @@ where
/// Currently only supports GroupAffine::<P> addition.
///
/// Returns error if inputs are invalid
pub fn ecc_add<P: Parameters<BaseField = F> + Clone>(
pub fn ecc_add<P: Parameters<BaseField = F>>(
&mut self,
point_a: &PointVariable,
point_b: &PointVariable,
Expand All @@ -420,7 +420,7 @@ where

/// Obtain the fixed-based scalar multiplication result of `scalar` * `Base`
/// Currently only supports GroupAffine::<P> scalar multiplication.
pub fn fixed_base_scalar_mul<P: Parameters<BaseField = F> + Clone>(
pub fn fixed_base_scalar_mul<P: Parameters<BaseField = F>>(
&mut self,
scalar: Variable,
base: &GroupAffine<P>,
Expand Down Expand Up @@ -469,7 +469,7 @@ where
/// multiplication. both `scalar` and `base` are variables.
/// Currently only supports GroupAffine::<P>.
/// If the parameter is bandersnatch, we will use GLV multiplication.
pub fn variable_base_scalar_mul<P: Parameters<BaseField = F> + Clone>(
pub fn variable_base_scalar_mul<P: Parameters<BaseField = F>>(
&mut self,
scalar: Variable,
base: &PointVariable,
Expand All @@ -495,7 +495,7 @@ where
/// multiplication. Both `scalar_bits_le` and `base` are variables,
/// where `scalar_bits_le` is the little-endian form of the scalar.
/// Currently only supports GroupAffine::<P>.
pub fn variable_base_binary_scalar_mul<P: Parameters<BaseField = F> + Clone>(
pub fn variable_base_binary_scalar_mul<P: Parameters<BaseField = F>>(
&mut self,
scalar_bits_le: &[BoolVar],
base: &PointVariable,
Expand Down Expand Up @@ -628,7 +628,7 @@ mod test {
fn test_is_neutral_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField + ?Sized,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let p1 = circuit.create_point_variable(Point(F::zero(), F::one()))?;
Expand Down Expand Up @@ -656,7 +656,7 @@ mod test {
fn build_is_neutral_circuit<F, P>(point: Point<F>) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let p = circuit.create_point_variable(point)?;
Expand Down Expand Up @@ -759,7 +759,7 @@ mod test {
fn build_on_curve_gate_circuit<F, P>(point: Point<F>) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let p = circuit.create_point_variable(point)?;
Expand All @@ -780,7 +780,7 @@ mod test {
fn test_curve_point_addition_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let p1 = GroupAffine::<P>::rand(&mut rng);
Expand Down Expand Up @@ -821,7 +821,7 @@ mod test {
) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let p1_var = circuit.create_point_variable(p1)?;
Expand All @@ -843,7 +843,7 @@ mod test {
fn test_quaternary_point_select_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let p1 = GroupAffine::<P>::rand(&mut rng);
Expand Down Expand Up @@ -905,7 +905,7 @@ mod test {
fn build_quaternary_select_gate<F, P>(b0: bool, b1: bool) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let b0_var = circuit.create_boolean_variable(b0)?;
Expand Down Expand Up @@ -938,7 +938,7 @@ mod test {
fn test_point_equal_gate_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let p = GroupAffine::<P>::rand(&mut rng);
Expand Down Expand Up @@ -988,7 +988,7 @@ mod test {
fn test_is_equal_point_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let p1 = GroupAffine::<P>::rand(&mut rng);
Expand Down Expand Up @@ -1048,12 +1048,12 @@ mod test {
fn test_compute_fixed_bases_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
fn check_base_list<F, P>(bases: &[GroupAffine<P>])
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
bases
.windows(2)
Expand Down Expand Up @@ -1104,7 +1104,7 @@ mod test {
fn test_fixed_based_scalar_mul_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
Expand Down Expand Up @@ -1136,7 +1136,7 @@ mod test {
fn build_fixed_based_scalar_mul_circuit<F, P>(scalar: F) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
Expand All @@ -1158,7 +1158,7 @@ mod test {
fn test_binary_point_vars_select_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let p0 = GroupAffine::<P>::rand(&mut rng);
Expand Down Expand Up @@ -1207,7 +1207,7 @@ mod test {
) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let b_var = circuit.create_boolean_variable(b)?;
Expand All @@ -1229,7 +1229,7 @@ mod test {
fn test_variable_base_scalar_mul_helper<F, P>() -> Result<(), PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut rng = ark_std::test_rng();
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
Expand Down Expand Up @@ -1280,7 +1280,7 @@ mod test {
) -> Result<PlonkCircuit<F>, PlonkError>
where
F: PrimeField,
P: Parameters<BaseField = F> + Clone,
P: Parameters<BaseField = F>,
{
let mut circuit: PlonkCircuit<F> = PlonkCircuit::new_turbo_plonk();
let scalar_var = circuit.create_variable(scalar)?;
Expand Down
Loading