mirror of
https://github.com/arnaucube/Nova.git
synced 2026-01-18 20:01:31 +01:00
refactor: streamline some traits and bounds (#207)
* refactor: Remove redundant PrimeField bound in various modules * refactor: Refactor main Group trait to use group::Group - the main Group trait now uses ::zkcrypto::group::Group - Refactored the usage of generic type associated 'Scalar' across multiple files and functions from 'G::Scalar' to fully qualified '<G as Group>::Scalar'. - No new features were added, functionality remained the same, changes were mostly aimed at improving type inference and handling. * Revert "refactor: Refactor main Group trait to use group::Group" This reverts commit 5ee05905886c74d32449ac7940839a9f8a4d1685.
This commit is contained in:
committed by
GitHub
parent
a62bccf206
commit
cdab40357a
@@ -28,10 +28,7 @@ pub trait NovaShape<G: Group> {
|
|||||||
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>);
|
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G>
|
impl<G: Group> NovaWitness<G> for SatisfyingAssignment<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
fn r1cs_instance_and_witness(
|
fn r1cs_instance_and_witness(
|
||||||
&self,
|
&self,
|
||||||
shape: &R1CSShape<G>,
|
shape: &R1CSShape<G>,
|
||||||
@@ -48,10 +45,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> NovaShape<G> for ShapeCS<G>
|
impl<G: Group> NovaShape<G> for ShapeCS<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>) {
|
fn r1cs_shape(&self) -> (R1CSShape<G>, CommitmentKey<G>) {
|
||||||
let mut A: Vec<(usize, usize, G::Scalar)> = Vec::new();
|
let mut A: Vec<(usize, usize, G::Scalar)> = Vec::new();
|
||||||
let mut B: Vec<(usize, usize, G::Scalar)> = Vec::new();
|
let mut B: Vec<(usize, usize, G::Scalar)> = Vec::new();
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ impl Ord for OrderedVariable {
|
|||||||
|
|
||||||
#[allow(clippy::upper_case_acronyms)]
|
#[allow(clippy::upper_case_acronyms)]
|
||||||
/// `ShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit.
|
/// `ShapeCS` is a `ConstraintSystem` for creating `R1CSShape`s for a circuit.
|
||||||
pub struct ShapeCS<G: Group>
|
pub struct ShapeCS<G: Group> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField + Field,
|
|
||||||
{
|
|
||||||
named_objects: HashMap<String, NamedObject>,
|
named_objects: HashMap<String, NamedObject>,
|
||||||
current_namespace: Vec<String>,
|
current_namespace: Vec<String>,
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
@@ -92,10 +89,7 @@ fn proc_lc<Scalar: PrimeField>(
|
|||||||
map
|
map
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> ShapeCS<G>
|
impl<G: Group> ShapeCS<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
/// Create a new, default `ShapeCS`,
|
/// Create a new, default `ShapeCS`,
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ShapeCS::default()
|
ShapeCS::default()
|
||||||
@@ -216,10 +210,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> Default for ShapeCS<G>
|
impl<G: Group> Default for ShapeCS<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
map.insert("ONE".into(), NamedObject::Var(ShapeCS::<G>::one()));
|
map.insert("ONE".into(), NamedObject::Var(ShapeCS::<G>::one()));
|
||||||
@@ -233,10 +224,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> ConstraintSystem<G::Scalar> for ShapeCS<G>
|
impl<G: Group> ConstraintSystem<G::Scalar> for ShapeCS<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
type Root = Self;
|
type Root = Self;
|
||||||
|
|
||||||
fn alloc<F, A, AR>(&mut self, annotation: A, _f: F) -> Result<Variable, SynthesisError>
|
fn alloc<F, A, AR>(&mut self, annotation: A, _f: F) -> Result<Variable, SynthesisError>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Support for generating R1CS witness using bellperson.
|
//! Support for generating R1CS witness using bellperson.
|
||||||
|
|
||||||
use crate::traits::Group;
|
use crate::traits::Group;
|
||||||
use ff::{Field, PrimeField};
|
use ff::Field;
|
||||||
|
|
||||||
use bellperson::{
|
use bellperson::{
|
||||||
multiexp::DensityTracker, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable,
|
multiexp::DensityTracker, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable,
|
||||||
@@ -9,10 +9,7 @@ use bellperson::{
|
|||||||
|
|
||||||
/// A `ConstraintSystem` which calculates witness values for a concrete instance of an R1CS circuit.
|
/// A `ConstraintSystem` which calculates witness values for a concrete instance of an R1CS circuit.
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct SatisfyingAssignment<G: Group>
|
pub struct SatisfyingAssignment<G: Group> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
// Density of queries
|
// Density of queries
|
||||||
a_aux_density: DensityTracker,
|
a_aux_density: DensityTracker,
|
||||||
b_input_density: DensityTracker,
|
b_input_density: DensityTracker,
|
||||||
@@ -29,10 +26,7 @@ where
|
|||||||
}
|
}
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
impl<G: Group> fmt::Debug for SatisfyingAssignment<G>
|
impl<G: Group> fmt::Debug for SatisfyingAssignment<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
fmt
|
fmt
|
||||||
.debug_struct("SatisfyingAssignment")
|
.debug_struct("SatisfyingAssignment")
|
||||||
@@ -69,10 +63,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G>
|
impl<G: Group> ConstraintSystem<G::Scalar> for SatisfyingAssignment<G> {
|
||||||
where
|
|
||||||
G::Scalar: PrimeField,
|
|
||||||
{
|
|
||||||
type Root = Self;
|
type Root = Self;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ pub trait Group:
|
|||||||
+ for<'de> Deserialize<'de>;
|
+ for<'de> Deserialize<'de>;
|
||||||
|
|
||||||
/// A type representing an element of the scalar field of the group
|
/// A type representing an element of the scalar field of the group
|
||||||
type Scalar: PrimeField
|
type Scalar: PrimeFieldBits
|
||||||
+ PrimeFieldBits
|
|
||||||
+ PrimeFieldExt
|
+ PrimeFieldExt
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
|
|||||||
Reference in New Issue
Block a user