#![cfg_attr(not(feature = "std"), no_std)] #![deny(unused_import_braces, unused_qualifications, trivial_casts)] #![deny(trivial_numeric_casts, variant_size_differences, unreachable_pub)] #![deny(non_shorthand_field_patterns, unused_attributes, unused_imports)] #![deny(unused_extern_crates, renamed_and_removed_lints, unused_allocation)] #![deny(unused_comparisons, bare_trait_objects, const_err, unused_must_use)] #![deny(unused_mut, unused_unsafe, private_in_public, unsafe_code)] #![forbid(unsafe_code)] #[cfg(all(test, not(feature = "std")))] #[macro_use] extern crate std; #[cfg(not(feature = "std"))] extern crate alloc as ralloc; #[macro_use] extern crate algebra; #[macro_use] extern crate derivative; #[macro_use] pub mod macros; #[cfg(not(feature = "std"))] use ralloc::vec::Vec; #[cfg(feature = "std")] use std::vec::Vec; use algebra::prelude::Field; pub mod bits; pub use self::bits::*; pub mod fields; pub mod groups; mod instantiated; #[cfg(feature = "bls12_377")] pub use instantiated::bls12_377; #[cfg(feature = "ed_on_bn254")] pub use instantiated::ed_on_bn254; #[cfg(feature = "ed_on_bls12_377")] pub use instantiated::ed_on_bls12_377; #[cfg(feature = "ed_on_mnt4_298")] pub use instantiated::ed_on_mnt4_298; #[cfg(feature = "ed_on_mnt4_753")] pub use instantiated::ed_on_mnt4_753; #[cfg(feature = "ed_on_cp6_782")] pub use instantiated::ed_on_cp6_782; #[cfg(feature = "ed_on_bw6_761")] pub use instantiated::ed_on_bw6_761; #[cfg(feature = "ed_on_bls12_381")] pub use instantiated::ed_on_bls12_381; #[cfg(feature = "mnt4_298")] pub use instantiated::mnt4_298; #[cfg(feature = "mnt4_753")] pub use instantiated::mnt4_753; #[cfg(feature = "mnt6_298")] pub use instantiated::mnt6_298; #[cfg(feature = "mnt6_753")] pub use instantiated::mnt6_753; pub mod pairing; pub mod alloc; pub mod eq; pub mod select; pub mod prelude { pub use crate::{ alloc::*, bits::{boolean::Boolean, uint32::UInt32, uint8::UInt8, ToBitsGadget, ToBytesGadget}, eq::*, fields::{FieldOpsBounds, FieldVar}, groups::{CurveVar, GroupOpsBounds}, instantiated::*, pairing::PairingVar, select::*, R1CSVar, }; } pub trait R1CSVar { type Value: core::fmt::Debug + Eq + Clone; /// Returns the underlying `ConstraintSystemRef`. fn cs(&self) -> Option>; /// Returns `true` if `self` is a circuit-generation-time constant. fn is_constant(&self) -> bool { self.cs() .map_or(true, |cs| cs == r1cs_core::ConstraintSystemRef::None) } /// Returns the value that is assigned to `self` in the underlying /// `ConstraintSystem`. fn value(&self) -> Result; } impl> R1CSVar for [T] { type Value = Vec; fn cs(&self) -> Option> { let mut result = None; for var in self { result = var.cs().or(result); } result } fn value(&self) -> Result { let mut result = Vec::new(); for var in self { result.push(var.value()?); } Ok(result) } } impl<'a, F: Field, T: 'a + R1CSVar> R1CSVar for &'a T { type Value = T::Value; fn cs(&self) -> Option> { (*self).cs() } fn value(&self) -> Result { (*self).value() } } pub trait Assignment { fn get(self) -> Result; } impl Assignment for Option { fn get(self) -> Result { self.ok_or(r1cs_core::SynthesisError::AssignmentMissing) } }