arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/r1cs-std/src/select.rs
r1cs-std/src/select.rsRaw
 1use crate::prelude::*;
 2use r1cs_core::{ConstraintSystem, SynthesisError};
 3use algebra::Field;
 4
 5
 6/// If condition is `true`, return `first`; else, select `second`.
 7pub trait CondSelectGadget<ConstraintF: Field>
 8where
 9    Self: Sized,
10{
11    fn conditionally_select<CS: ConstraintSystem<ConstraintF>>(
12        cs: CS,
13        cond: &Boolean,
14        first: &Self,
15        second: &Self,
16    ) -> Result<Self, SynthesisError>;
17
18    fn cost() -> usize;
19}
20
21/// Uses two bits to perform a lookup into a table
22pub trait TwoBitLookupGadget<ConstraintF: Field>
23where
24    Self: Sized,
25{
26    type TableConstant;
27    fn two_bit_lookup<CS: ConstraintSystem<ConstraintF>>(
28        cs: CS,
29        bits: &[Boolean],
30        constants: &[Self::TableConstant],
31    ) -> Result<Self, SynthesisError>;
32
33    fn cost() -> usize;
34}
35
36