Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pure_poseidon2.cpp
Go to the documentation of this file.
1
#include "
barretenberg/vm2/simulation/standalone/pure_poseidon2.hpp
"
2
3
#include "
barretenberg/crypto/poseidon2/poseidon2.hpp
"
4
#include "
barretenberg/vm2/simulation/interfaces/memory.hpp
"
5
6
namespace
bb::avm2::simulation
{
7
8
using
Poseidon2Hash
=
crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>
;
9
using
Poseidon2Perm
=
crypto::Poseidon2Permutation<crypto::Poseidon2Bn254ScalarFieldParams>
;
10
11
std::array<FF, 4>
PurePoseidon2::permutation
(
const
std::array<FF, 4>& input)
12
{
13
return
Poseidon2Perm::permutation
(input);
14
}
15
16
FF
PurePoseidon2::hash
(
const
std::vector<FF>& input)
17
{
18
return
Poseidon2Hash::hash
(input);
19
}
20
21
void
PurePoseidon2::permutation
(
MemoryInterface
&
memory
,
MemoryAddress
src_address
,
MemoryAddress
dst_address
)
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
AVM_HIGHEST_MEM_ADDRESS
#define AVM_HIGHEST_MEM_ADDRESS
Definition
aztec_constants.hpp:45
bb::avm2::memory
Definition
memory.hpp:36
bb::avm2::simulation::MemoryInterface
Definition
memory.hpp:10
bb::avm2::simulation::PurePoseidon2::hash
FF hash(const std::vector< FF > &input) override
Definition
pure_poseidon2.cpp:16
bb::avm2::simulation::PurePoseidon2::permutation
std::array< FF, 4 > permutation(const std::array< FF, 4 > &input) override
Definition
pure_poseidon2.cpp:11
bb::crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams >
bb::crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams >::hash
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
bb::crypto::Poseidon2Permutation
Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323.
Definition
poseidon2_permutation.hpp:23
bb::crypto::Poseidon2Permutation::permutation
static constexpr State permutation(const State &input)
Native form of Poseidon2 permutation from https://eprint.iacr.org/2023/323.
Definition
poseidon2_permutation.hpp:131
SStoreMutationOptions::src_address
@ src_address
CalldataCopyMutationOptions::dst_address
@ dst_address
poseidon2.hpp
bb::avm2::simulation
Definition
address_derivation_event.hpp:6
bb::avm2::ValueTag::FF
@ FF
bb::avm2::MemoryAddress
uint32_t MemoryAddress
Definition
memory_types.hpp:11
bb::avm2::FF
AvmFlavorSettings::FF FF
Definition
field.hpp:10
pure_poseidon2.hpp
memory.hpp
bb::avm2::simulation::Poseidon2Exception
Definition
poseidon2.hpp:14
src
barretenberg
vm2
simulation
standalone
pure_poseidon2.cpp
Generated by
1.9.8