ark_r1cs_std/
lib.rs

1#![cfg_attr(not(feature = "std"), no_std)]
2//! This crate implements common "gadgets" that make
3//! programming rank-1 constraint systems easier.
4#![deny(
5    warnings,
6    unused,
7    future_incompatible,
8    nonstandard_style,
9    rust_2018_idioms
10)]
11#![allow(clippy::op_ref)]
12
13#[macro_use]
14extern crate ark_std;
15
16#[macro_use]
17extern crate ark_ff;
18
19#[macro_use]
20extern crate ark_relations;
21
22/// Some utility macros for making downstream impls easier.
23#[macro_use]
24pub mod macros;
25
26pub(crate) use ark_std::vec::Vec;
27
28#[doc(hidden)]
29pub mod r1cs_var;
30pub use r1cs_var::*;
31
32/// This module contains `Boolean`, an R1CS equivalent of the `bool` type.
33pub mod boolean;
34
35/// Finite field arithmetic.
36pub mod fields;
37
38/// Implementations of elliptic curve group arithmetic for popular curve models.
39pub mod groups;
40
41/// Gadgets for computing pairings in bilinear groups.
42pub mod pairing;
43
44/// Utilities for allocating new variables in a constraint system.
45pub mod alloc;
46
47/// Utilities for comparing  variables.
48pub mod cmp;
49
50/// Utilities for converting variables to other kinds of variables.
51pub mod convert;
52
53/// Utilities for checking equality of variables.
54pub mod eq;
55
56/// Definitions of polynomial variables over finite fields.
57pub mod poly;
58
59/// Contains traits for conditionally selecting a variable from a
60/// list of variables.
61pub mod select;
62
63#[cfg(test)]
64pub(crate) mod test_utils;
65
66/// This module contains `UInt8`, a R1CS equivalent of the `u8` type.
67pub mod uint8;
68/// This module contains a macro for generating `UIntN` types, which are R1CS
69/// equivalents of `N`-bit unsigned integers.
70#[macro_use]
71pub mod uint;
72
73pub mod uint16 {
74    pub type UInt16<F> = super::uint::UInt<16, u16, F>;
75}
76pub mod uint32 {
77    pub type UInt32<F> = super::uint::UInt<32, u32, F>;
78}
79pub mod uint64 {
80    pub type UInt64<F> = super::uint::UInt<64, u64, F>;
81}
82pub mod uint128 {
83    pub type UInt128<F> = super::uint::UInt<128, u128, F>;
84}
85
86#[allow(missing_docs)]
87pub mod prelude {
88    pub use crate::{
89        alloc::*,
90        boolean::Boolean,
91        convert::{ToBitsGadget, ToBytesGadget},
92        eq::*,
93        fields::{FieldOpsBounds, FieldVar},
94        groups::{CurveVar, GroupOpsBounds},
95        pairing::PairingVar,
96        select::*,
97        uint128::UInt128,
98        uint16::UInt16,
99        uint32::UInt32,
100        uint64::UInt64,
101        uint8::UInt8,
102        R1CSVar,
103    };
104}
105
106/// A utility trait to convert `Self` to `Result<T, SynthesisErrorA`.>
107pub trait Assignment<T> {
108    /// Converts `self` to `Result`.
109    fn get(self) -> Result<T, ark_relations::r1cs::SynthesisError>;
110}
111
112impl<T> Assignment<T> for Option<T> {
113    fn get(self) -> Result<T, ark_relations::r1cs::SynthesisError> {
114        self.ok_or(ark_relations::r1cs::SynthesisError::AssignmentMissing)
115    }
116}