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