arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/crypto-primitives/src/commitment/injective_map/constraints.rs
crypto-primitives/src/commitment/injective_map/constraints.rsRaw
 1use crate::commitment::{
 2    injective_map::{InjectiveMap, PedersenCommCompressor},
 3    pedersen::{
 4        constraints::{CommGadget, ParametersVar, RandomnessVar},
 5        Window,
 6    },
 7};
 8
 9pub use crate::crh::injective_map::constraints::InjectiveMapGadget;
10use algebra_core::{Field, PrimeField, ProjectiveCurve};
11use r1cs_core::SynthesisError;
12use r1cs_std::{
13    groups::{CurveVar, GroupOpsBounds},
14    uint8::UInt8,
15};
16
17use core::marker::PhantomData;
18
19type ConstraintF<C> = <<C as ProjectiveCurve>::BaseField as Field>::BasePrimeField;
20
21pub struct CommitmentCompressorGadget<C, I, W, GG, IG>
22where
23    C: ProjectiveCurve,
24    I: InjectiveMap<C>,
25    W: Window,
26    GG: CurveVar<C, ConstraintF<C>>,
27    IG: InjectiveMapGadget<C, I, GG>,
28    for<'a> &'a GG: GroupOpsBounds<'a, C, GG>,
29{
30    _compressor: PhantomData<I>,
31    _compressor_gadget: PhantomData<IG>,
32    _comm: PhantomData<CommGadget<C, GG, W>>,
33}
34
35impl<C, I, GG, IG, W>
36    crate::commitment::CommitmentGadget<PedersenCommCompressor<C, I, W>, ConstraintF<C>>
37    for CommitmentCompressorGadget<C, I, W, GG, IG>
38where
39    C: ProjectiveCurve,
40    I: InjectiveMap<C>,
41    GG: CurveVar<C, ConstraintF<C>>,
42    ConstraintF<C>: PrimeField,
43    IG: InjectiveMapGadget<C, I, GG>,
44    W: Window,
45    for<'a> &'a GG: GroupOpsBounds<'a, C, GG>,
46{
47    type OutputVar = IG::OutputVar;
48    type ParametersVar = ParametersVar<C, GG>;
49    type RandomnessVar = RandomnessVar<ConstraintF<C>>;
50
51    fn commit(
52        parameters: &Self::ParametersVar,
53        input: &[UInt8<ConstraintF<C>>],
54        r: &Self::RandomnessVar,
55    ) -> Result<Self::OutputVar, SynthesisError> {
56        let result = CommGadget::<C, GG, W>::commit(parameters, input, r)?;
57        IG::evaluate(&result)
58    }
59}