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:
Kobi Gurkan
2020-04-19 02:03:33 +03:00
committed by GitHub
parent c486e15f0e
commit 5cc094be6b
22 changed files with 474 additions and 19 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,