arnaucube
arnaucube/ark-r1cs-stdPublic Self-hosted repository
ark-r1cs-std/r1cs-std/src/instantiated/ed_on_cp6_782/mod.rs
r1cs-std/src/instantiated/ed_on_cp6_782/mod.rsRaw
  1#![allow(unreachable_pub)]
  2//! This module implements the R1CS equivalent of `algebra::ed_on_cp6_782`.
  3//!
  4//! It implements field variables for `algebra::ed_on_cp6_782::Fq`,
  5//! and group variables for `algebra::ed_on_cp6_782::GroupProjective`.
  6//!
  7//! The field underlying these constraints is `algebra::ed_on_cp6_782::Fq`.
  8//!
  9//! # Examples
 10//!
 11//! One can perform standard algebraic operations on `FqVar`:
 12//!
 13//! ```
 14//! # fn main() -> Result<(), r1cs_core::SynthesisError> {
 15//! use algebra::{UniformRand, ed_on_cp6_782::*};
 16//! use r1cs_core::*;
 17//! use r1cs_std::prelude::*;
 18//! use r1cs_std::ed_on_cp6_782::*;
 19//!
 20//! let cs = ConstraintSystem::<Fq>::new_ref();
 21//! // This rng is just for test purposes; do not use it
 22//! // in real applications.
 23//! let mut rng = algebra::test_rng();
 24//!
 25//! // Generate some random `Fq` elements.
 26//! let a_native = Fq::rand(&mut rng);
 27//! let b_native = Fq::rand(&mut rng);
 28//!
 29//! // Allocate `a_native` and `b_native` as witness variables in `cs`.
 30//! let a = FqVar::new_witness(r1cs_core::ns!(cs, "generate_a"), || Ok(a_native))?;
 31//! let b = FqVar::new_witness(r1cs_core::ns!(cs, "generate_b"), || Ok(b_native))?;
 32//!
 33//! // Allocate `a_native` and `b_native` as constants in `cs`. This does not add any
 34//! // constraints or variables.
 35//! let a_const = FqVar::new_constant(r1cs_core::ns!(cs, "a_as_constant"), a_native)?;
 36//! let b_const = FqVar::new_constant(r1cs_core::ns!(cs, "b_as_constant"), b_native)?;
 37//!
 38//! let one = FqVar::one();
 39//! let zero = FqVar::zero();
 40//!
 41//! // Sanity check one + one = two
 42//! let two = &one + &one + &zero;
 43//! two.enforce_equal(&one.double()?)?;
 44//!
 45//! assert!(cs.is_satisfied()?);
 46//!
 47//! // Check that the value of &a + &b is correct.
 48//! assert_eq!((&a + &b).value()?, a_native + &b_native);
 49//!
 50//! // Check that the value of &a * &b is correct.
 51//! assert_eq!((&a * &b).value()?, a_native * &b_native);
 52//!
 53//! // Check that operations on variables and constants are equivalent.
 54//! (&a + &b).enforce_equal(&(&a_const + &b_const))?;
 55//! assert!(cs.is_satisfied()?);
 56//! # Ok(())
 57//! # }
 58//! ```
 59//!
 60//! One can also perform standard algebraic operations on `EdwardsVar`:
 61//!
 62//! ```
 63//! # fn main() -> Result<(), r1cs_core::SynthesisError> {
 64//! # use algebra::{UniformRand, ed_on_cp6_782::*};
 65//! # use r1cs_core::*;
 66//! # use r1cs_std::prelude::*;
 67//! # use r1cs_std::ed_on_cp6_782::*;
 68//!
 69//! # let cs = ConstraintSystem::<Fq>::new_ref();
 70//! # let mut rng = algebra::test_rng();
 71//!
 72//! // Generate some random `Edwards` elements.
 73//! let a_native = EdwardsProjective::rand(&mut rng);
 74//! let b_native = EdwardsProjective::rand(&mut rng);
 75//!
 76//! // Allocate `a_native` and `b_native` as witness variables in `cs`.
 77//! let a = EdwardsVar::new_witness(r1cs_core::ns!(cs, "a"), || Ok(a_native))?;
 78//! let b = EdwardsVar::new_witness(r1cs_core::ns!(cs, "b"), || Ok(b_native))?;
 79//!
 80//! // Allocate `a_native` and `b_native` as constants in `cs`. This does not add any
 81//! // constraints or variables.
 82//! let a_const = EdwardsVar::new_constant(r1cs_core::ns!(cs, "a_as_constant"), a_native)?;
 83//! let b_const = EdwardsVar::new_constant(r1cs_core::ns!(cs, "b_as_constant"), b_native)?;
 84//!
 85//! // This returns the identity of `Edwards`.
 86//! let zero = EdwardsVar::zero();
 87//!
 88//! // Sanity check one + one = two
 89//! let two_a = &a + &a + &zero;
 90//! two_a.enforce_equal(&a.double()?)?;
 91//!
 92//! assert!(cs.is_satisfied()?);
 93//!
 94//! // Check that the value of &a + &b is correct.
 95//! assert_eq!((&a + &b).value()?, a_native + &b_native);
 96//!
 97//! // Check that operations on variables and constants are equivalent.
 98//! (&a + &b).enforce_equal(&(&a_const + &b_const))?;
 99//! assert!(cs.is_satisfied()?);
100//! # Ok(())
101//! # }
102//! ```
103
104mod curves;
105mod fields;
106
107pub use curves::*;
108pub use fields::*;