Add ToConstraintFieldGadget (#278)

This commit is contained in:
Weikeng Chen
2020-09-14 21:56:51 -07:00
committed by GitHub
parent 40ce981801
commit c21d0b2796
7 changed files with 115 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
use algebra::{BitIteratorBE, Field};
use algebra::{BitIteratorBE, Field, PrimeField};
use crate::{prelude::*, Assignment, Vec};
use crate::{fields::fp::FpVar, prelude::*, Assignment, ToConstraintFieldGadget, Vec};
use core::borrow::Borrow;
use r1cs_core::{lc, ConstraintSystemRef, LinearCombination, Namespace, SynthesisError, Variable};
@@ -597,6 +597,14 @@ impl<F: Field> ToBytesGadget<F> for Boolean<F> {
}
}
impl<F: PrimeField> ToConstraintFieldGadget<F> for Boolean<F> {
#[tracing::instrument(target = "r1cs")]
fn to_constraint_field(&self) -> Result<Vec<FpVar<F>>, SynthesisError> {
let var = From::from(self.clone());
Ok(vec![var])
}
}
impl<F: Field> CondSelectGadget<F> for Boolean<F> {
#[tracing::instrument(target = "r1cs")]
fn conditionally_select(