Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pure_poseidon2.cpp
Go to the documentation of this file.
2
5
6namespace bb::avm2::simulation {
7
10
11std::array<FF, 4> PurePoseidon2::permutation(const std::array<FF, 4>& input)
12{
13 return Poseidon2Perm::permutation(input);
14}
15
16FF PurePoseidon2::hash(const std::vector<FF>& input)
17{
18 return Poseidon2Hash::hash(input);
19}
20
22{
23 uint64_t max_read_address = static_cast<uint64_t>(src_address) + 3;
24 if (max_read_address > AVM_HIGHEST_MEM_ADDRESS) {
25 throw Poseidon2Exception("Read address out of range");
26 }
27 uint64_t max_write_address = static_cast<uint64_t>(dst_address) + 3;
28 if (max_write_address > AVM_HIGHEST_MEM_ADDRESS) {
29 throw Poseidon2Exception("Write address out of range");
30 }
31
32 std::array<FF, 4> input = { 0, 0, 0, 0 };
33
34 // Read 4 elements from memory starting at src_address
35 for (uint32_t i = 0; i < 4; i++) {
36 const auto& item = memory.get(src_address + i);
37 if (item.get_tag() != MemoryTag::FF) {
38 throw Poseidon2Exception("An input tag is not FF");
39 }
40 input[i] = item.as_ff();
41 }
42
43 const std::array<FF, 4> output = Poseidon2Perm::permutation(input);
44 for (uint32_t i = 0; i < 4; i++) {
45 memory.set(dst_address + i, MemoryValue::from<FF>(output[i]));
46 }
47}
48
49} // namespace bb::avm2::simulation
#define AVM_HIGHEST_MEM_ADDRESS
FF hash(const std::vector< FF > &input) override
std::array< FF, 4 > permutation(const std::array< FF, 4 > &input) override
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323.
static constexpr State permutation(const State &input)
Native form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
uint32_t MemoryAddress
AvmFlavorSettings::FF FF
Definition field.hpp:10