Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relation_manual.test.cpp
Go to the documentation of this file.
1
#include "
barretenberg/flavor/flavor.hpp
"
2
#include "
barretenberg/relations/poseidon2_external_relation.hpp
"
3
#include "
barretenberg/relations/poseidon2_internal_relation.hpp
"
4
#include "
barretenberg/relations/relation_parameters.hpp
"
5
#include <gtest/gtest.h>
6
7
using namespace
bb
;
8
9
using
FF
=
fr
;
10
11
class
RelationManual
:
public
testing::Test {};
12
13
TEST_F
(
RelationManual
, Poseidon2ExternalRelationZeros)
14
{
15
using
Accumulator = std::array<FF, 4>;
16
using
Relation
=
bb::Poseidon2ExternalRelation<FF>
;
17
18
Accumulator acc{ 0, 0, 0, 0 };
19
struct
AllPoseidonValues {
20
FF
q_poseidon2_external;
21
FF
w_l;
22
FF
w_r;
23
FF
w_o;
24
FF
w_4;
25
FF
w_l_shift;
26
FF
w_r_shift;
27
FF
w_o_shift;
28
FF
w_4_shift;
29
FF
q_l;
30
FF
q_r;
31
FF
q_o;
32
FF
q_4;
33
};
34
AllPoseidonValues all_poseidon_values{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
35
36
const
auto
parameters =
RelationParameters<FF>::get_random
();
37
Relation::accumulate(acc, all_poseidon_values, parameters, 1);
38
EXPECT_EQ(acc[0], 0);
39
EXPECT_EQ(acc[1], 0);
40
EXPECT_EQ(acc[2], 0);
41
EXPECT_EQ(acc[3], 0);
42
}
43
44
TEST_F
(
RelationManual
, Poseidon2ExternalRelationRandom)
45
{
46
using
Accumulator = std::array<FF, 4>;
47
using
Relation
=
bb::Poseidon2ExternalRelation<FF>
;
48
49
Accumulator acc{ 0, 0, 0, 0 };
50
struct
AllPoseidonValues {
51
FF
q_poseidon2_external;
52
FF
w_l;
53
FF
w_r;
54
FF
w_o;
55
FF
w_4;
56
FF
q_l;
57
FF
q_r;
58
FF
q_o;
59
FF
q_4;
60
FF
w_l_shift;
61
FF
w_r_shift;
62
FF
w_o_shift;
63
FF
w_4_shift;
64
};
65
/*
66
* v1 = w_1 + q_1 = 5 + 6 = 11
67
* v2 = w_2 + q_2 = 4 + 9 = 13
68
* v3 = w_3 + q_3 = 1 + 8 = 9
69
* v4 = w_4 + q_4 = 7 + 3 = 10
70
* u1 = v1^5 = 11^5 = 161051
71
* u2 = v2^5 = 13^5 = 371293
72
* u3 = v3^5 = 9^5 = 59049
73
* u4 = v4^5 = 10^5 = 100000
74
* matrix mul with calculator:
75
* 1 3763355
76
* 2 3031011
77
* 3 2270175
78
* 4 1368540
79
*/
80
AllPoseidonValues all_poseidon_values{ 1, 5, 4, 1, 7, 6, 9, 8, 3, 3763355, 3031011, 2270175, 1368540 };
81
82
const
auto
parameters =
RelationParameters<FF>::get_random
();
83
Relation::accumulate(acc, all_poseidon_values, parameters, 1);
84
EXPECT_EQ(acc[0], 0);
85
EXPECT_EQ(acc[1], 0);
86
EXPECT_EQ(acc[2], 0);
87
EXPECT_EQ(acc[3], 0);
88
}
89
90
TEST_F
(
RelationManual
, Poseidon2InternalRelationZeros)
91
{
92
using
Accumulator = std::array<FF, 4>;
93
using
Relation
=
bb::Poseidon2InternalRelation<FF>
;
94
95
Accumulator acc{ 0, 0, 0, 0 };
96
struct
AllPoseidonValues {
97
FF
q_poseidon2_internal;
98
FF
w_l;
99
FF
w_r;
100
FF
w_o;
101
FF
w_4;
102
FF
w_l_shift;
103
FF
w_r_shift;
104
FF
w_o_shift;
105
FF
w_4_shift;
106
FF
q_l;
107
FF
q_r;
108
FF
q_o;
109
FF
q_4;
110
};
111
AllPoseidonValues all_poseidon_values{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
112
113
const
auto
parameters =
RelationParameters<FF>::get_random
();
114
Relation::accumulate(acc, all_poseidon_values, parameters, 1);
115
EXPECT_EQ(acc[0], 0);
116
EXPECT_EQ(acc[1], 0);
117
EXPECT_EQ(acc[2], 0);
118
EXPECT_EQ(acc[3], 0);
119
}
120
121
TEST_F
(
RelationManual
, Poseidon2InternalRelationRandom)
122
{
123
using
Accumulator = std::array<FF, 4>;
124
using
Relation
=
bb::Poseidon2InternalRelation<FF>
;
125
126
Accumulator acc{ 0, 0, 0, 0 };
127
struct
AllPoseidonValues {
128
FF
q_poseidon2_internal;
129
FF
w_l;
130
FF
w_r;
131
FF
w_o;
132
FF
w_4;
133
FF
q_l;
134
135
FF
w_l_shift;
136
FF
w_r_shift;
137
FF
w_o_shift;
138
FF
w_4_shift;
139
};
140
/*
141
* u1 = (w_1 + q_1)^5 = (1 + 5)^5 = 7776
142
* sum = u1 + w_2 + w_3 + w_4 = 7776 + 2 + 3 + 4 = 7785
143
* matrix mul with calculator:
144
* 1 0x122d9ce41e83c533318954d77a4ebc40eb729f6543ebd5f2e4ecb175ced3bc74
145
* 2 0x185028b6d489be7c029367a14616776b33bf2eada9bb370950d6719f68b5067f
146
* 3 0x00fce289a96b3f4a18562d0ef0ab76ca165e613222aa0c24501377003c5622a8
147
* 4 0x27e7677799fda1694819803f459b76d2fb1c45fdf0773375c72d61e8efb92893
148
*/
149
AllPoseidonValues all_poseidon_values{
150
1,
151
1,
152
2,
153
3,
154
4,
155
5,
156
FF
(std::string(
"0x122d9ce41e83c533318954d77a4ebc40eb729f6543ebd5f2e4ecb175ced3bc74"
)),
157
FF
(std::string(
"0x185028b6d489be7c029367a14616776b33bf2eada9bb370950d6719f68b5067f"
)),
158
FF
(std::string(
"0x00fce289a96b3f4a18562d0ef0ab76ca165e613222aa0c24501377003c5622a8"
)),
159
FF
(std::string(
"0x27e7677799fda1694819803f459b76d2fb1c45fdf0773375c72d61e8efb92893"
))
160
};
161
const
auto
parameters =
RelationParameters<FF>::get_random
();
162
Relation::accumulate(acc, all_poseidon_values, parameters, 1);
163
EXPECT_EQ(acc[0], 0);
164
EXPECT_EQ(acc[1], 0);
165
EXPECT_EQ(acc[2], 0);
166
EXPECT_EQ(acc[3], 0);
167
}
RelationManual
Definition
relation_manual.test.cpp:11
bb::Relation
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Definition
relation_types.hpp:153
flavor.hpp
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
bb
Entry point for Barretenberg command-line interface.
Definition
acir_format_getters.cpp:6
bb::TEST_F
TEST_F(IPATest, ChallengesAreZero)
Definition
ipa.test.cpp:123
bb::FF
typename Flavor::FF FF
Definition
protogalaxy.bench.cpp:16
bb::fr
field< Bn254FrParams > fr
Definition
fr.hpp:174
poseidon2_external_relation.hpp
poseidon2_internal_relation.hpp
relation_parameters.hpp
bb::RelationParameters::get_random
static RelationParameters get_random()
Definition
relation_parameters.hpp:58
src
barretenberg
relations
relation_manual.test.cpp
Generated by
1.9.8