diff --git a/crypto-primitives/src/commitment/injective_map/constraints.rs b/crypto-primitives/src/commitment/injective_map/constraints.rs index b9dff14..53d9ff9 100644 --- a/crypto-primitives/src/commitment/injective_map/constraints.rs +++ b/crypto-primitives/src/commitment/injective_map/constraints.rs @@ -16,13 +16,15 @@ use r1cs_std::{groups::GroupGadget, uint8::UInt8}; use std::marker::PhantomData; -pub struct PedersenCommitmentCompressorGadget< +pub struct PedersenCommitmentCompressorGadget +where G: Group, I: InjectiveMap, ConstraintF: Field, GG: GroupGadget, IG: InjectiveMapGadget, -> { + +{ _compressor: PhantomData, _compressor_gadget: PhantomData, _crh: PedersenCommitmentGadget, diff --git a/crypto-primitives/src/commitment/pedersen/mod.rs b/crypto-primitives/src/commitment/pedersen/mod.rs index b1100fd..4f63973 100644 --- a/crypto-primitives/src/commitment/pedersen/mod.rs +++ b/crypto-primitives/src/commitment/pedersen/mod.rs @@ -1,10 +1,12 @@ use crate::Error; use algebra::UniformRand; +use algebra::{Field, ToConstraintField}; +use algebra::{bytes::ToBytes, groups::Group, BitIterator, FpParameters, PrimeField}; + use rand::Rng; use std::marker::PhantomData; use super::CommitmentScheme; -use algebra::{bytes::ToBytes, groups::Group, BitIterator, FpParameters, PrimeField}; use std::io::{Result as IoResult, Write}; pub use crate::crh::pedersen::PedersenWindow; @@ -121,3 +123,11 @@ impl CommitmentScheme for PedersenCommitment Ok(result) } } + + +impl> ToConstraintField for PedersenParameters { + #[inline] + fn to_field_elements(&self) -> Result, Error> { + Ok(Vec::new()) + } +} diff --git a/crypto-primitives/src/crh/injective_map/constraints.rs b/crypto-primitives/src/crh/injective_map/constraints.rs index d90167c..eb767dc 100644 --- a/crypto-primitives/src/crh/injective_map/constraints.rs +++ b/crypto-primitives/src/crh/injective_map/constraints.rs @@ -24,8 +24,7 @@ use r1cs_std::{ prelude::*, }; -pub trait InjectiveMapGadget, ConstraintF: Field, GG: GroupGadget> -{ +pub trait InjectiveMapGadget, ConstraintF: Field, GG: GroupGadget> { type OutputGadget: EqGadget + ToBytesGadget + CondSelectGadget @@ -75,13 +74,14 @@ where } } -pub struct PedersenCRHCompressorGadget< +pub struct PedersenCRHCompressorGadget +where G: Group, I: InjectiveMap, ConstraintF: Field, GG: GroupGadget, IG: InjectiveMapGadget, -> { +{ _compressor: PhantomData, _compressor_gadget: PhantomData, _crh: PedersenCRHGadget, diff --git a/crypto-primitives/src/crh/pedersen/constraints.rs b/crypto-primitives/src/crh/pedersen/constraints.rs index 2c781a6..98d3e3e 100644 --- a/crypto-primitives/src/crh/pedersen/constraints.rs +++ b/crypto-primitives/src/crh/pedersen/constraints.rs @@ -1,10 +1,9 @@ -use algebra::Field; use crate::crh::{ FixedLengthCRHGadget, pedersen::{PedersenCRH, PedersenParameters, PedersenWindow}, }; -use algebra::groups::Group; +use algebra::{Field, Group}; use r1cs_core::{ConstraintSystem, SynthesisError}; use r1cs_std::prelude::*; diff --git a/crypto-primitives/src/crh/pedersen/mod.rs b/crypto-primitives/src/crh/pedersen/mod.rs index 85931be..49a8f28 100644 --- a/crypto-primitives/src/crh/pedersen/mod.rs +++ b/crypto-primitives/src/crh/pedersen/mod.rs @@ -7,6 +7,7 @@ use std::{ }; use crate::crh::FixedLengthCRH; +use algebra::{Field, ToConstraintField}; use algebra::groups::Group; @@ -139,3 +140,11 @@ impl Debug for PedersenParameters { write!(f, "}}\n") } } + + +impl> ToConstraintField for PedersenParameters { + #[inline] + fn to_field_elements(&self) -> Result, Error> { + Ok(Vec::new()) + } +} diff --git a/crypto-primitives/src/mht/constraints.rs b/crypto-primitives/src/mht/constraints.rs index a23aa62..3d6a4ed 100644 --- a/crypto-primitives/src/mht/constraints.rs +++ b/crypto-primitives/src/mht/constraints.rs @@ -28,13 +28,12 @@ where _f: PhantomData, } -impl MerklePathVerifierGadget +impl MerklePathVerifierGadget where P: MHTParameters, ConstraintF: Field, CRHGadget: FixedLengthCRHGadget, { - pub fn check_membership>( cs: CS, parameters: &CRHGadget::ParametersGadget, diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index 8e50200..36a96e4 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -1,5 +1,6 @@ use crate::SignatureScheme; use algebra::{ + ToConstraintField, bytes::ToBytes, fields::{Field, PrimeField}, groups::Group, @@ -221,3 +222,12 @@ pub fn bytes_to_bits(bytes: &[u8]) -> Vec { } bits } + +impl, D: Digest> ToConstraintField + for SchnorrSigParameters +{ + #[inline] + fn to_field_elements(&self) -> Result, Error> { + self.generator.to_field_elements() + } +}