Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
poseidon2.test.cpp
Go to the documentation of this file.
1
#include "
poseidon2.hpp
"
2
#include "
barretenberg/crypto/poseidon2/poseidon2_params.hpp
"
3
#include "
barretenberg/ecc/curves/bn254/bn254.hpp
"
4
#include <gtest/gtest.h>
5
6
using namespace
bb
;
7
8
namespace
{
9
auto
&
engine
=
numeric::get_debug_randomness
();
10
}
11
12
TEST
(
Poseidon2
, HashBasicTests)
13
{
14
15
fr
a
=
fr::random_element
(&
engine
);
16
fr
b
=
fr::random_element
(&
engine
);
17
fr
c =
fr::random_element
(&
engine
);
18
fr
d =
fr::random_element
(&
engine
);
19
20
std::vector<fr> input1{
a
,
b
, c, d };
21
std::vector<fr> input2{ d, c,
b
,
a
};
22
23
auto
r0 =
crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash
(input1);
24
auto
r1 =
crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash
(input1);
25
auto
r2 =
crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash
(input2);
26
27
EXPECT_EQ(r0, r1);
28
EXPECT_NE(r0, r2);
29
}
30
31
// N.B. these hardcoded values were extracted from the algorithm being tested. These are NOT independent test vectors!
32
// TODO(@zac-williamson #3132): find independent test vectors we can compare against! (very hard to find given
33
// flexibility of Poseidon's parametrisation)
34
TEST
(
Poseidon2
, HashConsistencyCheck)
35
{
36
fr
a
(std::string(
"9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"
));
37
fr
b
(std::string(
"9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"
));
38
fr
c(std::string(
"0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"
));
39
fr
d(std::string(
"0x9a807b615c4d3e2fa0b1c2d3e4f56789fedcba9876543210abcdef0123456789"
));
40
41
std::vector<fr> input{
a
,
b
, c, d };
42
auto
result =
crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>::hash
(input);
43
44
fr
expected(std::string(
"0x2f43a0f83b51a6f5fc839dea0ecec74947637802a579fa9841930a25a0bcec11"
));
45
46
EXPECT_EQ(result, expected);
47
}
bb::crypto::Poseidon2
Definition
poseidon2.hpp:15
a
FF a
Definition
field_gt.test.cpp:51
b
FF b
Definition
field_gt.test.cpp:52
bn254.hpp
engine
numeric::RNG & engine
Definition
eccvm_transcript.test.cpp:282
Poseidon2
ContentAddressedIndexedTree< StoreType, Poseidon2HashPolicy > Poseidon2
Definition
indexed_tree.bench.cpp:20
bb::numeric::get_debug_randomness
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition
engine.cpp:190
bb
Entry point for Barretenberg command-line interface.
Definition
acir_format_getters.cpp:6
bb::TEST
TEST(MegaCircuitBuilder, CopyConstructor)
Definition
mega_circuit_builder.test.cpp:14
poseidon2_params.hpp
bb::field< Bn254FrParams >
bb::field< Bn254FrParams >::random_element
static field random_element(numeric::RNG *engine=nullptr) noexcept
Definition
field_impl.hpp:665
poseidon2.hpp
src
barretenberg
crypto
poseidon2
poseidon2.test.cpp
Generated by
1.9.8