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