Files
ark-r1cs-std/r1cs-std/src/select.rs
2019-08-14 13:13:33 +03:00

37 lines
811 B
Rust

use crate::prelude::*;
use r1cs_core::{ConstraintSystem, SynthesisError};
use algebra::Field;
/// If condition is `true`, return `first`; else, select `second`.
pub trait CondSelectGadget<ConstraintF: Field>
where
Self: Sized,
{
fn conditionally_select<CS: ConstraintSystem<ConstraintF>>(
cs: CS,
cond: &Boolean,
first: &Self,
second: &Self,
) -> Result<Self, SynthesisError>;
fn cost() -> usize;
}
/// Uses two bits to perform a lookup into a table
pub trait TwoBitLookupGadget<ConstraintF: Field>
where
Self: Sized,
{
type TableConstant;
fn two_bit_lookup<CS: ConstraintSystem<ConstraintF>>(
cs: CS,
bits: &[Boolean],
constants: &[Self::TableConstant],
) -> Result<Self, SynthesisError>;
fn cost() -> usize;
}