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

Move to actual Group trait #249

Closed
wants to merge 6 commits into from
Closed
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
6 changes: 2 additions & 4 deletions benches/compressed-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
use criterion::*;
use ff::PrimeField;
use group::Group;
use nova_snark::{
traits::{
circuit::{StepCircuit, TrivialCircuit},
Group,
},
traits::circuit::{StepCircuit, TrivialCircuit},
CompressedSNARK, PublicParams, RecursiveSNARK,
};
use std::time::Duration;
Expand Down
6 changes: 2 additions & 4 deletions benches/compute-digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use std::{marker::PhantomData, time::Duration};
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ff::PrimeField;
use group::Group;
use nova_snark::{
traits::{
circuit::{StepCircuit, TrivialCircuit},
Group,
},
traits::circuit::{StepCircuit, TrivialCircuit},
PublicParams,
};

Expand Down
6 changes: 2 additions & 4 deletions benches/recursive-snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use core::marker::PhantomData;
use criterion::*;
use ff::PrimeField;
use group::Group;
use nova_snark::{
traits::{
circuit::{StepCircuit, TrivialCircuit},
Group,
},
traits::circuit::{StepCircuit, TrivialCircuit},
PublicParams, RecursiveSNARK,
};
use std::time::Duration;
Expand Down
6 changes: 2 additions & 4 deletions benches/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ use bellpepper_core::{
use core::time::Duration;
use criterion::*;
use ff::{PrimeField, PrimeFieldBits};
use group::Group;
use nova_snark::{
traits::{
circuit::{StepCircuit, TrivialCircuit},
Group,
},
traits::circuit::{StepCircuit, TrivialCircuit},
PublicParams, RecursiveSNARK,
};
use sha2::{Digest, Sha256};
Expand Down
6 changes: 2 additions & 4 deletions examples/minroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ type G2 = pasta_curves::vesta::Point;
use bellpepper_core::{num::AllocatedNum, ConstraintSystem, SynthesisError};
use ff::PrimeField;
use flate2::{write::ZlibEncoder, Compression};
use group::Group;
use nova_snark::{
traits::{
circuit::{StepCircuit, TrivialCircuit},
Group,
},
traits::circuit::{StepCircuit, TrivialCircuit},
CompressedSNARK, PublicParams, RecursiveSNARK,
};
use num_bigint::BigUint;
Expand Down
2 changes: 1 addition & 1 deletion examples/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ff::{
derive::byteorder::{ByteOrder, LittleEndian},
Field, PrimeField, PrimeFieldBits,
};
use nova_snark::{gadgets::ecc::AllocatedPoint, traits::Group as NovaGroup};
use nova_snark::{gadgets::ecc::AllocatedPoint, traits::GroupExt as NovaGroup};
use num_bigint::BigUint;
use pasta_curves::{
arithmetic::CurveAffine,
Expand Down
4 changes: 2 additions & 2 deletions src/bellpepper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod tests {
shape_cs::ShapeCS,
solver::SatisfyingAssignment,
},
traits::Group,
traits::GroupExt,
};
use bellpepper_core::{num::AllocatedNum, ConstraintSystem};
use ff::PrimeField;
Expand All @@ -42,7 +42,7 @@ mod tests {

fn test_alloc_bit_with<G>()
where
G: Group,
G: GroupExt,
{
// First create the shape
let mut cs: ShapeCS<G> = ShapeCS::new();
Expand Down
10 changes: 5 additions & 5 deletions src/bellpepper/r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use super::{shape_cs::ShapeCS, solver::SatisfyingAssignment, test_shape_cs::Test
use crate::{
errors::NovaError,
r1cs::{R1CSInstance, R1CSShape, R1CSWitness, SparseMatrix, R1CS},
traits::Group,
traits::GroupExt,
CommitmentKey,
};
use bellpepper_core::{Index, LinearCombination};
use ff::PrimeField;

/// `NovaWitness` provide a method for acquiring an `R1CSInstance` and `R1CSWitness` from implementers.
pub trait NovaWitness<G: Group> {
pub trait NovaWitness<G: GroupExt> {
/// Return an instance and witness, given a shape and ck.
fn r1cs_instance_and_witness(
&self,
Expand All @@ -23,12 +23,12 @@ pub trait NovaWitness<G: Group> {
}

/// `NovaShape` provides methods for acquiring `R1CSShape` and `CommitmentKey` from implementers.
pub trait NovaShape<G: Group> {
pub trait NovaShape<G: GroupExt> {
/// Return an appropriate `R1CSShape` and `CommitmentKey` structs.
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>);
}

impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G> {
impl<G: GroupExt> NovaWitness<G> for SatisfyingAssignment<G> {
fn r1cs_instance_and_witness(
&self,
shape: &R1CSShape<G>,
Expand All @@ -47,7 +47,7 @@ impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G> {

macro_rules! impl_nova_shape {
( $name:ident) => {
impl<G: Group> NovaShape<G> for $name<G>
impl<G: GroupExt> NovaShape<G> for $name<G>
where
G::Scalar: PrimeField,
{
Expand Down
10 changes: 5 additions & 5 deletions src/bellpepper/shape_cs.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Support for generating R1CS shape using bellpepper.

use crate::traits::Group;
use crate::traits::GroupExt;
use bellpepper_core::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
use ff::PrimeField;

/// `ShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit.
pub struct ShapeCS<G: Group>
pub struct ShapeCS<G: GroupExt>
where
G::Scalar: PrimeField,
{
Expand All @@ -19,7 +19,7 @@ where
aux: usize,
}

impl<G: Group> ShapeCS<G> {
impl<G: GroupExt> ShapeCS<G> {
/// Create a new, default `ShapeCS`,
pub fn new() -> Self {
ShapeCS::default()
Expand All @@ -41,7 +41,7 @@ impl<G: Group> ShapeCS<G> {
}
}

impl<G: Group> Default for ShapeCS<G> {
impl<G: GroupExt> Default for ShapeCS<G> {
fn default() -> Self {
ShapeCS {
constraints: vec![],
Expand All @@ -51,7 +51,7 @@ impl<G: Group> Default for ShapeCS<G> {
}
}

impl<G: Group> ConstraintSystem<G::Scalar> for ShapeCS<G> {
impl<G: GroupExt> ConstraintSystem<G::Scalar> for ShapeCS<G> {
type Root = Self;

fn alloc<F, A, AR>(&mut self, _annotation: A, _f: F) -> Result<Variable, SynthesisError>
Expand Down
12 changes: 6 additions & 6 deletions src/bellpepper/solver.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! Support for generating R1CS witness using bellpepper.

use crate::traits::Group;
use crate::traits::GroupExt;
use ff::Field;

use bellpepper_core::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};

/// A `ConstraintSystem` which calculates witness values for a concrete instance of an R1CS circuit.
pub struct SatisfyingAssignment<G: Group> {
pub struct SatisfyingAssignment<G: GroupExt> {
// Assignments of variables
pub(crate) input_assignment: Vec<G::Scalar>,
pub(crate) aux_assignment: Vec<G::Scalar>,
}
use std::fmt;

impl<G: Group> fmt::Debug for SatisfyingAssignment<G> {
impl<G: GroupExt> fmt::Debug for SatisfyingAssignment<G> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt
.debug_struct("SatisfyingAssignment")
Expand All @@ -23,13 +23,13 @@ impl<G: Group> fmt::Debug for SatisfyingAssignment<G> {
}
}

impl<G: Group> PartialEq for SatisfyingAssignment<G> {
impl<G: GroupExt> PartialEq for SatisfyingAssignment<G> {
fn eq(&self, other: &SatisfyingAssignment<G>) -> bool {
self.input_assignment == other.input_assignment && self.aux_assignment == other.aux_assignment
}
}

impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G> {
impl<G: GroupExt> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G> {
type Root = Self;

fn new() -> Self {
Expand Down Expand Up @@ -143,7 +143,7 @@ impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G> {
}

#[allow(dead_code)]
impl<G: Group> SatisfyingAssignment<G> {
impl<G: GroupExt> SatisfyingAssignment<G> {
pub fn scalar_inputs(&self) -> Vec<G::Scalar> {
self.input_assignment.clone()
}
Expand Down
10 changes: 5 additions & 5 deletions src/bellpepper/test_shape_cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
collections::{BTreeMap, HashMap},
};

use crate::traits::Group;
use crate::traits::GroupExt;
use bellpepper_core::{ConstraintSystem, Index, LinearCombination, SynthesisError, Variable};
use core::fmt::Write;
use ff::{Field, PrimeField};
Expand Down Expand Up @@ -48,7 +48,7 @@ impl Ord for OrderedVariable {
}

/// `TestShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit.
pub struct TestShapeCS<G: Group>
pub struct TestShapeCS<G: GroupExt>
where
G::Scalar: PrimeField + Field,
{
Expand Down Expand Up @@ -91,7 +91,7 @@ fn proc_lc<Scalar: PrimeField>(
map
}

impl<G: Group> TestShapeCS<G>
impl<G: GroupExt> TestShapeCS<G>
where
G::Scalar: PrimeField,
{
Expand Down Expand Up @@ -216,7 +216,7 @@ where
}
}

impl<G: Group> Default for TestShapeCS<G>
impl<G: GroupExt> Default for TestShapeCS<G>
where
G::Scalar: PrimeField,
{
Expand All @@ -233,7 +233,7 @@ where
}
}

impl<G: Group> ConstraintSystem<G::Scalar> for TestShapeCS<G>
impl<G: GroupExt> ConstraintSystem<G::Scalar> for TestShapeCS<G>
where
G::Scalar: PrimeField,
{
Expand Down
Loading
Loading