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
use crate::utilities::uint::{UInt, UInt128, UInt16, UInt32, UInt64, UInt8};
use snarkvm_fields::{Field, PrimeField};
use snarkvm_r1cs::{errors::SynthesisError, ConstraintSystem};
pub trait Add<F: Field, Rhs = Self>
where
Self: std::marker::Sized,
{
type ErrorType;
fn add<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Self, Self::ErrorType>;
}
macro_rules! add_uint_impl {
($($gadget: ident),*) => ($(
impl<F: Field + PrimeField> Add<F> for $gadget {
type ErrorType = SynthesisError;
fn add<CS: ConstraintSystem<F>>(
&self,
cs: CS,
other: &Self
) -> Result<Self, Self::ErrorType> {
<$gadget as UInt>::addmany(cs, &[self.clone(), other.clone()])
}
}
)*)
}
add_uint_impl!(UInt8, UInt16, UInt32, UInt64, UInt128);