mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-09 23:41:33 +01:00
Add ToConstraintField impls for some primitives
This commit is contained in:
@@ -16,13 +16,15 @@ use r1cs_std::{groups::GroupGadget, uint8::UInt8};
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct PedersenCommitmentCompressorGadget<
|
||||
pub struct PedersenCommitmentCompressorGadget<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: PedersenCommitmentGadget<G, ConstraintF, GG>,
|
||||
|
||||
@@ -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<G: Group, W: PedersenWindow> CommitmentScheme for PedersenCommitment<G, W>
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -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::*;
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,12 @@ where
|
||||
_f: PhantomData<ConstraintF>,
|
||||
}
|
||||
|
||||
impl<P, CRHGadget, ConstraintF> MerklePathVerifierGadget<P, CRHGadget, ConstraintF>
|
||||
impl<P, CRHGadget, ConstraintF> MerklePathVerifierGadget<P, CRHGadget, ConstraintF>
|
||||
where
|
||||
P: MHTParameters,
|
||||
ConstraintF: Field,
|
||||
CRHGadget: FixedLengthCRHGadget<P::H, ConstraintF>,
|
||||
{
|
||||
|
||||
pub fn check_membership<CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
parameters: &CRHGadget::ParametersGadget,
|
||||
|
||||
@@ -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<bool> {
|
||||
}
|
||||
bits
|
||||
}
|
||||
|
||||
impl<ConstraintF: Field, G: Group + ToConstraintField<ConstraintF>, D: Digest> ToConstraintField<ConstraintF>
|
||||
for SchnorrSigParameters<G, D>
|
||||
{
|
||||
#[inline]
|
||||
fn to_field_elements(&self) -> Result<Vec<ConstraintF>, Error> {
|
||||
self.generator.to_field_elements()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user