add ToBytesGadget to GroupType

This commit is contained in:
collin 2020-06-01 18:16:21 -07:00
parent e5ee1cfe4d
commit 8ab5108558
2 changed files with 17 additions and 3 deletions

View File

@ -12,10 +12,11 @@ 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 snarkos_models::gadgets::utilities::{ToBitsGadget, ToBytesGadget};
use std::borrow::Borrow;
use std::ops::Sub;
use std::str::FromStr;
use snarkos_models::gadgets::utilities::uint8::UInt8;
#[derive(Clone, Debug)]
pub enum EdwardsGroupType {
@ -276,4 +277,16 @@ impl ToBitsGadget<Fq> for EdwardsGroupType {
let self_gadget = self.allocated(&mut cs)?;
self_gadget.to_bits_strict(cs)
}
}
}
impl ToBytesGadget<Fq> for EdwardsGroupType {
fn to_bytes<CS: ConstraintSystem<Fq>>(&self, mut cs: CS) -> Result<Vec<UInt8>, SynthesisError> {
let self_gadget = self.allocated(&mut cs)?;
self_gadget.to_bytes(cs)
}
fn to_bytes_strict<CS: ConstraintSystem<Fq>>(&self, mut cs: CS) -> Result<Vec<UInt8>, SynthesisError> {
let self_gadget = self.allocated(&mut cs)?;
self_gadget.to_bytes_strict(cs)
}
}

View File

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