Skip to content

Commit 7e6d234

Browse files
authored
Make PedersenCompressorGadget a TwoToOneCRHGadget (#43)
1 parent 6e739b0 commit 7e6d234

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/crh/injective_map/constraints.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use core::{fmt::Debug, marker::PhantomData};
22

33
use crate::crh::{
4+
constraints,
45
injective_map::{InjectiveMap, PedersenCRHCompressor, TECompressor},
56
pedersen::{constraints as ped_constraints, Window},
6-
CRHGadget,
77
};
88

99
use ark_ec::{
@@ -72,7 +72,7 @@ where
7272
_crh: ped_constraints::CRHGadget<C, GG, W>,
7373
}
7474

75-
impl<C, I, GG, IG, W> CRHGadget<PedersenCRHCompressor<C, I, W>, ConstraintF<C>>
75+
impl<C, I, GG, IG, W> constraints::CRHGadget<PedersenCRHCompressor<C, I, W>, ConstraintF<C>>
7676
for PedersenCRHCompressorGadget<C, I, W, GG, IG>
7777
where
7878
C: ProjectiveCurve,
@@ -94,3 +94,30 @@ where
9494
IG::evaluate(&result)
9595
}
9696
}
97+
98+
impl<C, I, GG, IG, W> constraints::TwoToOneCRHGadget<PedersenCRHCompressor<C, I, W>, ConstraintF<C>>
99+
for PedersenCRHCompressorGadget<C, I, W, GG, IG>
100+
where
101+
C: ProjectiveCurve,
102+
I: InjectiveMap<C>,
103+
GG: CurveVar<C, ConstraintF<C>>,
104+
for<'a> &'a GG: GroupOpsBounds<'a, C, GG>,
105+
IG: InjectiveMapGadget<C, I, GG>,
106+
W: Window,
107+
{
108+
type OutputVar = IG::OutputVar;
109+
type ParametersVar = ped_constraints::CRHParametersVar<C, GG>;
110+
111+
#[tracing::instrument(target = "r1cs", skip(parameters))]
112+
fn evaluate(
113+
parameters: &Self::ParametersVar,
114+
left_input: &[UInt8<ConstraintF<C>>],
115+
right_input: &[UInt8<ConstraintF<C>>],
116+
) -> Result<Self::OutputVar, SynthesisError> {
117+
// assume equality of left and right length
118+
assert_eq!(left_input.len(), right_input.len());
119+
let result =
120+
ped_constraints::CRHGadget::<C, GG, W>::evaluate(parameters, left_input, right_input)?;
121+
IG::evaluate(&result)
122+
}
123+
}

0 commit comments

Comments
 (0)