ark-r1cs-std/r1cs-std/src/select.rs
r1cs-std/src/select.rsRaw
1use crate::prelude::*;
2use algebra::Field;
3use r1cs_core::SynthesisError;
4
5/// If condition is `true`, return `true_value`; else, select `false_value`.
6pub trait CondSelectGadget<ConstraintF: Field>
7where
8 Self: Sized,
9{
10 fn conditionally_select(
11 cond: &Boolean<ConstraintF>,
12 true_value: &Self,
13 false_value: &Self,
14 ) -> Result<Self, SynthesisError>;
15}
16
17/// Uses two bits to perform a lookup into a table
18pub trait TwoBitLookupGadget<ConstraintF: Field>
19where
20 Self: Sized,
21{
22 type TableConstant;
23 fn two_bit_lookup(
24 bits: &[Boolean<ConstraintF>],
25 constants: &[Self::TableConstant],
26 ) -> Result<Self, SynthesisError>;
27}
28
29/// Uses three bits to perform a lookup into a table, where the last bit
30/// performs negation
31pub trait ThreeBitCondNegLookupGadget<ConstraintF: Field>
32where
33 Self: Sized,
34{
35 type TableConstant;
36 fn three_bit_cond_neg_lookup(
37 bits: &[Boolean<ConstraintF>],
38 b0b1: &Boolean<ConstraintF>,
39 constants: &[Self::TableConstant],
40 ) -> Result<Self, SynthesisError>;
41}