Add ToConstraintField impls for some primitives

This commit is contained in:
Pratyush Mishra
2019-10-11 16:38:00 -07:00
parent 1b6f681cdb
commit cb2ff3b412
7 changed files with 40 additions and 11 deletions

View File

@@ -24,8 +24,7 @@ use r1cs_std::{
prelude::*,
};
pub trait InjectiveMapGadget<G: Group, I: InjectiveMap<G>, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>>
{
pub trait InjectiveMapGadget<G: Group, I: InjectiveMap<G>, ConstraintF: Field, GG: GroupGadget<G, ConstraintF>> {
type OutputGadget: EqGadget<ConstraintF>
+ ToBytesGadget<ConstraintF>
+ CondSelectGadget<ConstraintF>
@@ -75,13 +74,14 @@ where
}
}
pub struct PedersenCRHCompressorGadget<
pub struct PedersenCRHCompressorGadget<G, I, ConstraintF, GG, IG>
where
G: Group,
I: InjectiveMap<G>,
ConstraintF: Field,
GG: GroupGadget<G, ConstraintF>,
IG: InjectiveMapGadget<G, I, ConstraintF, GG>,
> {
{
_compressor: PhantomData<I>,
_compressor_gadget: PhantomData<IG>,
_crh: PedersenCRHGadget<G, ConstraintF, GG>,

View File

@@ -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::*;

View File

@@ -7,6 +7,7 @@ use std::{
};
use crate::crh::FixedLengthCRH;
use algebra::{Field, ToConstraintField};
use algebra::groups::Group;
@@ -139,3 +140,11 @@ impl<G: Group> Debug for PedersenParameters<G> {
write!(f, "}}\n")
}
}
impl<ConstraintF: Field, G: Group + ToConstraintField<ConstraintF>> ToConstraintField<ConstraintF> for PedersenParameters<G> {
#[inline]
fn to_field_elements(&self) -> Result<Vec<ConstraintF>, Error> {
Ok(Vec::new())
}
}