1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(
warnings,
unused,
future_incompatible,
nonstandard_style,
rust_2018_idioms
)]
#![allow(clippy::op_ref)]
#[macro_use]
extern crate ark_std;
#[macro_use]
extern crate ark_ff;
#[macro_use]
extern crate ark_relations;
#[doc(hidden)]
#[macro_use]
extern crate derivative;
#[macro_use]
pub mod macros;
pub(crate) use ark_std::vec::Vec;
use ark_ff::Field;
pub mod bits;
pub use self::bits::*;
pub mod fields;
pub mod groups;
pub mod pairing;
pub mod alloc;
pub mod eq;
pub mod poly;
pub mod select;
#[allow(missing_docs)]
pub mod prelude {
pub use crate::{
alloc::*,
bits::{boolean::Boolean, uint32::UInt32, uint8::UInt8, ToBitsGadget, ToBytesGadget},
eq::*,
fields::{FieldOpsBounds, FieldVar},
groups::{CurveVar, GroupOpsBounds},
pairing::PairingVar,
select::*,
R1CSVar,
};
}
pub trait R1CSVar<F: Field> {
type Value: core::fmt::Debug + Eq + Clone;
fn cs(&self) -> ark_relations::r1cs::ConstraintSystemRef<F>;
fn is_constant(&self) -> bool {
self.cs().is_none()
}
fn value(&self) -> Result<Self::Value, ark_relations::r1cs::SynthesisError>;
}
impl<F: Field, T: R1CSVar<F>> R1CSVar<F> for [T] {
type Value = Vec<T::Value>;
fn cs(&self) -> ark_relations::r1cs::ConstraintSystemRef<F> {
let mut result = ark_relations::r1cs::ConstraintSystemRef::None;
for var in self {
result = var.cs().or(result);
}
result
}
fn value(&self) -> Result<Self::Value, ark_relations::r1cs::SynthesisError> {
let mut result = Vec::new();
for var in self {
result.push(var.value()?);
}
Ok(result)
}
}
impl<'a, F: Field, T: 'a + R1CSVar<F>> R1CSVar<F> for &'a T {
type Value = T::Value;
fn cs(&self) -> ark_relations::r1cs::ConstraintSystemRef<F> {
(*self).cs()
}
fn value(&self) -> Result<Self::Value, ark_relations::r1cs::SynthesisError> {
(*self).value()
}
}
pub trait Assignment<T> {
fn get(self) -> Result<T, ark_relations::r1cs::SynthesisError>;
}
impl<T> Assignment<T> for Option<T> {
fn get(self) -> Result<T, ark_relations::r1cs::SynthesisError> {
self.ok_or(ark_relations::r1cs::SynthesisError::AssignmentMissing)
}
}
pub trait ToConstraintFieldGadget<ConstraintF: ark_ff::PrimeField> {
fn to_constraint_field(
&self,
) -> Result<Vec<crate::fields::fp::FpVar<ConstraintF>>, ark_relations::r1cs::SynthesisError>;
}