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