add ToBitsGadget to GroupType

This commit is contained in:
collin 2020-06-01 18:14:23 -07:00
parent 887e374e28
commit e5ee1cfe4d
2 changed files with 15 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use snarkos_models::gadgets::utilities::alloc::AllocGadget;
use snarkos_models::gadgets::utilities::boolean::Boolean;
use snarkos_models::gadgets::utilities::eq::{ConditionalEqGadget, EqGadget};
use snarkos_models::gadgets::utilities::select::CondSelectGadget;
use snarkos_models::gadgets::utilities::ToBitsGadget;
use std::borrow::Borrow;
use std::ops::Sub;
use std::str::FromStr;
@ -264,3 +265,15 @@ impl CondSelectGadget<Fq> for EdwardsGroupType {
2 * <EdwardsBlsGadget as CondSelectGadget<Fq>>::cost()
}
}
impl ToBitsGadget<Fq> for EdwardsGroupType {
fn to_bits<CS: ConstraintSystem<Fq>>(&self, mut cs: CS) -> Result<Vec<Boolean>, SynthesisError> {
let self_gadget = self.allocated(&mut cs)?;
self_gadget.to_bits(cs)
}
fn to_bits_strict<CS: ConstraintSystem<Fq>>(&self, mut cs: CS) -> Result<Vec<Boolean>, SynthesisError> {
let self_gadget = self.allocated(&mut cs)?;
self_gadget.to_bits_strict(cs)
}
}

View File

@ -5,6 +5,7 @@ use snarkos_models::gadgets::utilities::alloc::AllocGadget;
use snarkos_models::gadgets::utilities::eq::{ConditionalEqGadget, EqGadget};
use snarkos_models::gadgets::utilities::select::CondSelectGadget;
use std::fmt::Debug;
use snarkos_models::gadgets::utilities::ToBitsGadget;
pub mod edwards_bls12;
@ -16,6 +17,7 @@ pub trait GroupType<F: Field>:
+ ConditionalEqGadget<F>
+ AllocGadget<String, F>
+ CondSelectGadget<F>
+ ToBitsGadget<F>
{
fn constant(string: String) -> Result<Self, GroupError>;