mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-09 23:41:33 +01:00
Adds alloc_constant to AllocGadget (#189)
* adds alloc constant to AllocGadget * fmt * fmt * more alloc constant impls * fmt * even more impls * fixes type * fixes alloc_constant in gm17 * uses alloc_constant from field gadget in group gadgets * fmt * handle most comments
This commit is contained in:
@@ -48,6 +48,16 @@ impl<ConstraintF: PrimeField> CommitmentGadget<Blake2sCommitment, ConstraintF>
|
||||
}
|
||||
|
||||
impl<ConstraintF: Field> AllocGadget<(), ConstraintF> for Blake2sParametersGadget {
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<()>,
|
||||
{
|
||||
Self::alloc(cs, || Ok(val))
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(_: CS, _: F) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
@@ -69,6 +79,22 @@ impl<ConstraintF: Field> AllocGadget<(), ConstraintF> for Blake2sParametersGadge
|
||||
}
|
||||
|
||||
impl<ConstraintF: PrimeField> AllocGadget<[u8; 32], ConstraintF> for Blake2sRandomnessGadget {
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<[u8; 32]>,
|
||||
{
|
||||
let mut bytes = vec![];
|
||||
for (i, b) in val.borrow().iter().enumerate() {
|
||||
bytes.push(UInt8::alloc_constant(cs.ns(|| format!("value {}", i)), b)?)
|
||||
}
|
||||
|
||||
Ok(Blake2sRandomnessGadget(bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
|
||||
@@ -98,16 +98,14 @@ where
|
||||
W: PedersenWindow,
|
||||
ConstraintF: PrimeField,
|
||||
{
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
value_gen: F,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
T: Borrow<PedersenParameters<G>>,
|
||||
{
|
||||
let temp = value_gen()?;
|
||||
let parameters = temp.borrow().clone();
|
||||
let parameters = val.borrow().clone();
|
||||
|
||||
Ok(PedersenCommitmentGadgetParameters {
|
||||
params: parameters,
|
||||
@@ -117,6 +115,18 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
value_gen: F,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
T: Borrow<PedersenParameters<G>>,
|
||||
{
|
||||
let temp = value_gen()?;
|
||||
Self::alloc_constant(cs, temp)
|
||||
}
|
||||
|
||||
fn alloc_input<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
value_gen: F,
|
||||
@@ -142,6 +152,21 @@ where
|
||||
G: Group,
|
||||
ConstraintF: PrimeField,
|
||||
{
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<PedersenRandomness<G>>,
|
||||
{
|
||||
let mut result_bytes = vec![];
|
||||
for (i, byte) in to_bytes![val.borrow().0].unwrap().into_iter().enumerate() {
|
||||
let cur = UInt8::alloc_constant(cs.ns(|| format!("byte {}", i)), byte)?;
|
||||
result_bytes.push(cur);
|
||||
}
|
||||
Ok(PedersenRandomnessGadget(result_bytes))
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
value_gen: F,
|
||||
|
||||
@@ -89,8 +89,24 @@ impl<G: Group, W: PedersenWindow, ConstraintF: Field, GG: GroupGadget<G, Constra
|
||||
AllocGadget<BoweHopwoodPedersenParameters<G>, ConstraintF>
|
||||
for BoweHopwoodPedersenCRHGadgetParameters<G, W, ConstraintF, GG>
|
||||
{
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<BoweHopwoodPedersenParameters<G>>,
|
||||
{
|
||||
let params = val.borrow().clone();
|
||||
Ok(BoweHopwoodPedersenCRHGadgetParameters {
|
||||
params,
|
||||
_group_g: PhantomData,
|
||||
_engine: PhantomData,
|
||||
_window: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
value_gen: F,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
@@ -98,12 +114,7 @@ impl<G: Group, W: PedersenWindow, ConstraintF: Field, GG: GroupGadget<G, Constra
|
||||
T: Borrow<BoweHopwoodPedersenParameters<G>>,
|
||||
{
|
||||
let params = value_gen()?.borrow().clone();
|
||||
Ok(BoweHopwoodPedersenCRHGadgetParameters {
|
||||
params,
|
||||
_group_g: PhantomData,
|
||||
_engine: PhantomData,
|
||||
_window: PhantomData,
|
||||
})
|
||||
Self::alloc_constant(cs, params)
|
||||
}
|
||||
|
||||
fn alloc_input<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
|
||||
@@ -80,8 +80,24 @@ impl<G: Group, W: PedersenWindow, ConstraintF: Field, GG: GroupGadget<G, Constra
|
||||
AllocGadget<PedersenParameters<G>, ConstraintF>
|
||||
for PedersenCRHGadgetParameters<G, W, ConstraintF, GG>
|
||||
{
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<PedersenParameters<G>>,
|
||||
{
|
||||
let params = val.borrow().clone();
|
||||
Ok(PedersenCRHGadgetParameters {
|
||||
params,
|
||||
_group_g: PhantomData,
|
||||
_engine: PhantomData,
|
||||
_window: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
value_gen: F,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
@@ -89,12 +105,7 @@ impl<G: Group, W: PedersenWindow, ConstraintF: Field, GG: GroupGadget<G, Constra
|
||||
T: Borrow<PedersenParameters<G>>,
|
||||
{
|
||||
let params = value_gen()?.borrow().clone();
|
||||
Ok(PedersenCRHGadgetParameters {
|
||||
params,
|
||||
_group_g: PhantomData,
|
||||
_engine: PhantomData,
|
||||
_window: PhantomData,
|
||||
})
|
||||
Self::alloc_constant(cs, params)
|
||||
}
|
||||
|
||||
fn alloc_input<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
|
||||
@@ -128,6 +128,28 @@ where
|
||||
HGadget: FixedLengthCRHGadget<P::H, ConstraintF>,
|
||||
ConstraintF: Field,
|
||||
{
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<MerkleTreePath<P>>,
|
||||
{
|
||||
let mut path = Vec::new();
|
||||
for (i, &(ref l, ref r)) in val.borrow().path.iter().enumerate() {
|
||||
let l_hash = HGadget::OutputGadget::alloc_constant(
|
||||
&mut cs.ns(|| format!("l_child_{}", i)),
|
||||
l.clone(),
|
||||
)?;
|
||||
let r_hash = HGadget::OutputGadget::alloc_constant(
|
||||
&mut cs.ns(|| format!("r_child_{}", i)),
|
||||
r.clone(),
|
||||
)?;
|
||||
path.push((l_hash, r_hash));
|
||||
}
|
||||
Ok(MerkleTreePathGadget { path })
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: F,
|
||||
|
||||
@@ -202,6 +202,54 @@ where
|
||||
ConstraintF: Field,
|
||||
P: PairingGadget<PairingE, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<VerifyingKey<PairingE>>,
|
||||
{
|
||||
let VerifyingKey {
|
||||
h_g2,
|
||||
g_alpha_g1,
|
||||
h_beta_g2,
|
||||
g_gamma_g1,
|
||||
h_gamma_g2,
|
||||
query,
|
||||
} = val.borrow().clone();
|
||||
let h_g2 = P::G2Gadget::alloc_constant(cs.ns(|| "h_g2"), h_g2.into_projective())?;
|
||||
let g_alpha_g1 =
|
||||
P::G1Gadget::alloc_constant(cs.ns(|| "g_alpha"), g_alpha_g1.into_projective())?;
|
||||
let h_beta_g2 =
|
||||
P::G2Gadget::alloc_constant(cs.ns(|| "h_beta"), h_beta_g2.into_projective())?;
|
||||
let g_gamma_g1 =
|
||||
P::G1Gadget::alloc_constant(cs.ns(|| "g_gamma_g1"), g_gamma_g1.into_projective())?;
|
||||
let h_gamma_g2 =
|
||||
P::G2Gadget::alloc_constant(cs.ns(|| "h_gamma_g2"), h_gamma_g2.into_projective())?;
|
||||
|
||||
let query = query
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, query_i)| {
|
||||
P::G1Gadget::alloc_constant(
|
||||
cs.ns(|| format!("query_{}", i)),
|
||||
query_i.into_projective(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.collect::<Result<_, _>>()?;
|
||||
Ok(Self {
|
||||
h_g2,
|
||||
g_alpha_g1,
|
||||
h_beta_g2,
|
||||
g_gamma_g1,
|
||||
h_gamma_g2,
|
||||
query,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
@@ -312,6 +360,21 @@ where
|
||||
ConstraintF: Field,
|
||||
P: PairingGadget<PairingE, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Proof<PairingE>>,
|
||||
{
|
||||
let Proof { a, b, c } = val.borrow().clone();
|
||||
let a = P::G1Gadget::alloc_constant(cs.ns(|| "a"), a.into_projective())?;
|
||||
let b = P::G2Gadget::alloc_constant(cs.ns(|| "b"), b.into_projective())?;
|
||||
let c = P::G1Gadget::alloc_constant(cs.ns(|| "c"), c.into_projective())?;
|
||||
Ok(Self { a, b, c })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -173,6 +173,50 @@ where
|
||||
ConstraintF: Field,
|
||||
P: PairingGadget<PairingE, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<VerifyingKey<PairingE>>,
|
||||
{
|
||||
let VerifyingKey {
|
||||
alpha_g1,
|
||||
beta_g2,
|
||||
gamma_g2,
|
||||
delta_g2,
|
||||
gamma_abc_g1,
|
||||
} = val.borrow().clone();
|
||||
let alpha_g1 =
|
||||
P::G1Gadget::alloc_constant(cs.ns(|| "alpha_g1"), alpha_g1.into_projective())?;
|
||||
let beta_g2 = P::G2Gadget::alloc_constant(cs.ns(|| "beta_g2"), beta_g2.into_projective())?;
|
||||
let gamma_g2 =
|
||||
P::G2Gadget::alloc_constant(cs.ns(|| "gamma_g2"), gamma_g2.into_projective())?;
|
||||
let delta_g2 =
|
||||
P::G2Gadget::alloc_constant(cs.ns(|| "delta_g2"), delta_g2.into_projective())?;
|
||||
|
||||
let gamma_abc_g1 = gamma_abc_g1
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(i, gamma_abc_i)| {
|
||||
P::G1Gadget::alloc_constant(
|
||||
cs.ns(|| format!("gamma_abc_{}", i)),
|
||||
gamma_abc_i.into_projective(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.collect::<Result<_, _>>()?;
|
||||
Ok(Self {
|
||||
alpha_g1,
|
||||
beta_g2,
|
||||
gamma_g2,
|
||||
delta_g2,
|
||||
gamma_abc_g1,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
@@ -276,6 +320,21 @@ where
|
||||
ConstraintF: Field,
|
||||
P: PairingGadget<PairingE, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Proof<PairingE>>,
|
||||
{
|
||||
let Proof { a, b, c } = val.borrow().clone();
|
||||
let a = P::G1Gadget::alloc_constant(cs.ns(|| "a"), a.into_projective())?;
|
||||
let b = P::G2Gadget::alloc_constant(cs.ns(|| "b"), b.into_projective())?;
|
||||
let c = P::G1Gadget::alloc_constant(cs.ns(|| "c"), c.into_projective())?;
|
||||
Ok(Self { a, b, c })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -450,6 +450,22 @@ impl<ConstraintF: PrimeField> ToBytesGadget<ConstraintF> for Blake2sOutputGadget
|
||||
}
|
||||
|
||||
impl<ConstraintF: PrimeField> AllocGadget<[u8; 32], ConstraintF> for Blake2sOutputGadget {
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<[u8; 32]>,
|
||||
{
|
||||
let mut bytes = vec![];
|
||||
for (i, b) in val.borrow().iter().enumerate() {
|
||||
bytes.push(UInt8::alloc_constant(cs.ns(|| format!("value {}", i)), b)?)
|
||||
}
|
||||
|
||||
Ok(Blake2sOutputGadget(bytes))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
|
||||
@@ -96,6 +96,21 @@ where
|
||||
GG: GroupGadget<G, ConstraintF>,
|
||||
D: Digest,
|
||||
{
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<SchnorrSigParameters<G, D>>,
|
||||
{
|
||||
let generator = GG::alloc_constant(cs, val.borrow().generator)?;
|
||||
Ok(Self {
|
||||
generator,
|
||||
_engine: PhantomData,
|
||||
_group: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(cs: CS, f: F) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
@@ -133,6 +148,21 @@ where
|
||||
ConstraintF: Field,
|
||||
GG: GroupGadget<G, ConstraintF>,
|
||||
{
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
val: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<SchnorrPublicKey<G>>,
|
||||
{
|
||||
let pub_key = GG::alloc_constant(cs, val.borrow())?;
|
||||
Ok(Self {
|
||||
pub_key,
|
||||
_engine: PhantomData,
|
||||
_group: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(cs: CS, f: F) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
|
||||
@@ -8,6 +8,13 @@ where
|
||||
Self: Sized,
|
||||
V: ?Sized,
|
||||
{
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<V>;
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(cs: CS, f: F) -> Result<Self, SynthesisError>
|
||||
where
|
||||
F: FnOnce() -> Result<T, SynthesisError>,
|
||||
@@ -47,6 +54,21 @@ where
|
||||
impl<I, ConstraintF: Field, A: AllocGadget<I, ConstraintF>> AllocGadget<[I], ConstraintF>
|
||||
for Vec<A>
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<[I]>,
|
||||
{
|
||||
let mut vec = Vec::new();
|
||||
for (i, value) in t.borrow().iter().enumerate() {
|
||||
vec.push(A::alloc_constant(cs.ns(|| format!("value_{}", i)), value)?);
|
||||
}
|
||||
Ok(vec)
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
f: F,
|
||||
|
||||
@@ -235,6 +235,16 @@ impl PartialEq for AllocatedBit {
|
||||
impl Eq for AllocatedBit {}
|
||||
|
||||
impl<ConstraintF: Field> AllocGadget<bool, ConstraintF> for AllocatedBit {
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
_t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<bool>,
|
||||
{
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: F,
|
||||
@@ -715,6 +725,16 @@ impl From<AllocatedBit> for Boolean {
|
||||
}
|
||||
|
||||
impl<ConstraintF: Field> AllocGadget<bool, ConstraintF> for Boolean {
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<bool>,
|
||||
{
|
||||
Ok(Boolean::constant(*t.borrow()))
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
cs: CS,
|
||||
value_gen: F,
|
||||
|
||||
@@ -277,6 +277,16 @@ impl UInt64 {
|
||||
}
|
||||
|
||||
impl<ConstraintF: Field> AllocGadget<u64, ConstraintF> for UInt64 {
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<u64>,
|
||||
{
|
||||
Ok(UInt64::constant(*t.borrow()))
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: F,
|
||||
|
||||
@@ -214,6 +214,16 @@ impl<ConstraintF: Field> ConditionalEqGadget<ConstraintF> for UInt8 {
|
||||
impl<ConstraintF: Field> EqGadget<ConstraintF> for UInt8 {}
|
||||
|
||||
impl<ConstraintF: Field> AllocGadget<u8, ConstraintF> for UInt8 {
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
_cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<u8>,
|
||||
{
|
||||
Ok(UInt8::constant(*t.borrow()))
|
||||
}
|
||||
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: F,
|
||||
|
||||
@@ -584,6 +584,18 @@ impl<F: PrimeField> Clone for FpGadget<F> {
|
||||
}
|
||||
|
||||
impl<F: PrimeField> AllocGadget<F, F> for FpGadget<F> {
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<F>>(_cs: CS, t: T) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<F>,
|
||||
{
|
||||
let value = t.borrow().clone();
|
||||
Ok(Self {
|
||||
value: Some(value),
|
||||
variable: LinearCombination::from((value, CS::one())).into(),
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<F>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -834,6 +834,17 @@ where
|
||||
P: Fp12Parameters,
|
||||
<P::Fp6Params as Fp6Parameters>::Fp2Params: Fp2Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp12<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -611,6 +611,17 @@ impl<P: Fp2Parameters<Fp = ConstraintF>, ConstraintF: PrimeField>
|
||||
impl<P: Fp2Parameters<Fp = ConstraintF>, ConstraintF: PrimeField> AllocGadget<Fp2<P>, ConstraintF>
|
||||
for Fp2Gadget<P, ConstraintF>
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp2<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -867,6 +867,17 @@ impl<P: Fp3Parameters<Fp = ConstraintF>, ConstraintF: PrimeField + SquareRootFie
|
||||
impl<P: Fp3Parameters<Fp = ConstraintF>, ConstraintF: PrimeField + SquareRootField>
|
||||
AllocGadget<Fp3<P>, ConstraintF> for Fp3Gadget<P, ConstraintF>
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp3<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -673,6 +673,17 @@ where
|
||||
P: Fp4Parameters,
|
||||
P::Fp2Params: Fp2Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp4<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -664,6 +664,17 @@ where
|
||||
P: Fp6Parameters,
|
||||
P::Fp3Params: Fp3Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp6<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -964,6 +964,17 @@ where
|
||||
P: Fp6Parameters,
|
||||
P::Fp2Params: Fp2Parameters<Fp = ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<Fp6<P>>,
|
||||
{
|
||||
Self::zero(cs.ns(|| "zero"))?.add_constant(cs.ns(|| "add constant"), t.borrow())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<F, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -437,6 +437,24 @@ where
|
||||
ConstraintF: PrimeField,
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<SWProjective<P>>,
|
||||
{
|
||||
let p = t.borrow().into_affine();
|
||||
Ok(Self {
|
||||
x: F::alloc_constant(cs.ns(|| "x"), &p.x)?,
|
||||
y: F::alloc_constant(cs.ns(|| "y"), &p.y)?,
|
||||
infinity: Boolean::constant(p.infinity),
|
||||
_params: PhantomData,
|
||||
_engine: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
|
||||
@@ -492,6 +492,23 @@ mod affine_impl {
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
Self: GroupGadget<TEAffine<P>, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<TEAffine<P>>,
|
||||
{
|
||||
let p = t.borrow();
|
||||
Ok(Self {
|
||||
x: F::alloc_constant(cs.ns(|| "x"), &p.x)?,
|
||||
y: F::alloc_constant(cs.ns(|| "y"), &p.y)?,
|
||||
_params: PhantomData,
|
||||
_engine: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: FN,
|
||||
@@ -1089,6 +1106,23 @@ mod projective_impl {
|
||||
F: FieldGadget<P::BaseField, ConstraintF>,
|
||||
Self: GroupGadget<TEProjective<P>, ConstraintF>,
|
||||
{
|
||||
#[inline]
|
||||
fn alloc_constant<T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
t: T,
|
||||
) -> Result<Self, SynthesisError>
|
||||
where
|
||||
T: Borrow<TEProjective<P>>,
|
||||
{
|
||||
let p = t.borrow().into_affine();
|
||||
Ok(Self {
|
||||
x: F::alloc_constant(cs.ns(|| "x"), &p.x)?,
|
||||
y: F::alloc_constant(cs.ns(|| "y"), &p.y)?,
|
||||
_params: PhantomData,
|
||||
_engine: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn alloc<FN, T, CS: ConstraintSystem<ConstraintF>>(
|
||||
mut cs: CS,
|
||||
value_gen: FN,
|
||||
|
||||
Reference in New Issue
Block a user