ark-curves-cherry-picked/ed_on_cp6_782/src/constraints/mod.rs
ed_on_cp6_782/src/constraints/mod.rsRaw
1#![allow(unreachable_pub)]
2//! This module implements the R1CS equivalent of `ark_ed_on_cp6_782`.
3//!
4//! It implements field variables for `crate::Fq`,
5//! and group variables for `crate::Projective`.
6//!
7//! The field underlying these constraints is `crate::Fq`.
8//!
9//! # Examples
10//!
11//! One can perform standard algebraic operations on `FqVar`:
12//!
13//! ```
14//! # fn main() -> Result<(), ark_relations::r1cs::SynthesisError> {
15//! use ark_std::UniformRand;
16//! use ark_relations::r1cs::*;
17//! use ark_r1cs_std::prelude::*;
18//! use ark_ed_on_cp6_782::{*, constraints::*};
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 = ark_std::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(ark_relations::ns!(cs, "generate_a"), || Ok(a_native))?;
31//! let b = FqVar::new_witness(ark_relations::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(ark_relations::ns!(cs, "a_as_constant"), a_native)?;
36//! let b_const = FqVar::new_constant(ark_relations::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<(), ark_relations::r1cs::SynthesisError> {
64//! # use ark_std::UniformRand;
65//! # use ark_relations::r1cs::*;
66//! # use ark_r1cs_std::prelude::*;
67//! # use ark_ed_on_cp6_782::{*, constraints::*};
68//!
69//! # let cs = ConstraintSystem::<Fq>::new_ref();
70//! # let mut rng = ark_std::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(ark_relations::ns!(cs, "a"), || Ok(a_native))?;
78//! let b = EdwardsVar::new_witness(ark_relations::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(ark_relations::ns!(cs, "a_as_constant"), a_native)?;
83//! let b_const = EdwardsVar::new_constant(ark_relations::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::*;