Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ffiterm.test.cpp
Go to the documentation of this file.
1#include <unordered_map>
2
4#include "term.hpp"
5
6#include <gtest/gtest.h>
7
8using namespace smt_terms;
9
10TEST(FFITerm, addition)
11{
14 bb::fr c = a + b;
15 Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
16
17 STerm x = FFIVar("x", &s);
18 STerm y = FFIVar("y", &s);
19 STerm z = x + y;
20
21 z == c;
22 x == a;
23 ASSERT_TRUE(s.check());
24
25 bb::fr yvals = string_to_fr(s[y], /*base=*/10);
26 ASSERT_EQ(b, yvals);
27}
28
29TEST(FFITerm, subtraction)
30{
33 bb::fr c = a - b;
34 Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
35
36 STerm x = FFIVar("x", &s);
37 STerm y = FFIVar("y", &s);
38 STerm z = x - y;
39
40 z == c;
41 x == a;
42 ASSERT_TRUE(s.check());
43
44 bb::fr yvals = string_to_fr(s[y], /*base=*/10);
45 ASSERT_EQ(b, yvals);
46}
47
48TEST(FFITerm, multiplication)
49{
52 bb::fr c = a * b;
53 Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
54
55 STerm x = FFIVar("x", &s);
56 STerm y = FFIVar("y", &s);
57 STerm z = x * y;
58
59 z == c;
60 x == a;
61 ASSERT_TRUE(s.check());
62
63 bb::fr yvals = string_to_fr(s[y], /*base=*/10);
64 ASSERT_EQ(b, yvals);
65}
66
67TEST(FFITerm, division)
68{
71 bb::fr c = a / b;
72 Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
73
74 STerm x = FFIVar("x", &s);
75 STerm y = FFIVar("y", &s);
76 STerm z = x / y;
77
78 z == c;
79 x == a;
80 ASSERT_TRUE(s.check());
81
82 bb::fr yvals = string_to_fr(s[y], /*base=*/10);
83 ASSERT_EQ(b, yvals);
84}
85
86// This test aims to check for the absence of unintended
87// behavior. If an unsupported operator is called, an info message appears in stderr
88// and the value is supposed to remain unchanged.
89TEST(FFITerm, unsupported_operations)
90{
91 Solver s("30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001");
92
93 STerm x = FFIVar("x", &s);
94 STerm y = FFIVar("y", &s);
95
96 STerm z = x ^ y;
97 ASSERT_EQ(z.term, x.term);
98 z = x & y;
99 ASSERT_EQ(z.term, x.term);
100 z = x | y;
101 ASSERT_EQ(z.term, x.term);
102 z = x >> 10;
103 ASSERT_EQ(z.term, x.term);
104 z = x << 10;
105 ASSERT_EQ(z.term, x.term);
106 z = x.rotr(10);
107 ASSERT_EQ(z.term, x.term);
108 z = x.rotl(10);
109 ASSERT_EQ(z.term, x.term);
110
111 cvc5::Term before_term = x.term;
112 x ^= y;
113 ASSERT_EQ(x.term, before_term);
114 x &= y;
115 ASSERT_EQ(x.term, before_term);
116 x |= y;
117 ASSERT_EQ(x.term, before_term);
118 x >>= 10;
119 ASSERT_EQ(x.term, before_term);
120 x <<= 10;
121 ASSERT_EQ(x.term, before_term);
122}
Class for the solver.
Definition solver.hpp:80
Symbolic term element class.
Definition term.hpp:114
STerm rotl(const uint32_t &n) const
Definition term.cpp:450
STerm rotr(const uint32_t &n) const
Definition term.cpp:439
cvc5::Term term
Definition term.hpp:121
FF a
FF b
TEST(FFITerm, addition)
STerm FFIVar(const std::string &name, Solver *slv)
Definition term.cpp:585
bb::fr string_to_fr(const std::string &number, int base, bool is_signed, size_t step)
Converts a string of an arbitrary base to fr. Note: there should be no prefix.
Definition smt_util.cpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept