Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pure_keccakf1600.cpp
Go to the documentation of this file.
1
#include "
barretenberg/vm2/simulation/standalone/pure_keccakf1600.hpp
"
2
3
#include "
barretenberg/common/log.hpp
"
4
#include "
barretenberg/crypto/keccak/keccak.hpp
"
5
#include "
barretenberg/vm2/common/aztec_constants.hpp
"
6
#include "
barretenberg/vm2/simulation/events/keccakf1600_event.hpp
"
7
#include "
barretenberg/vm2/simulation/interfaces/memory.hpp
"
8
9
namespace
bb::avm2::simulation
{
10
11
void
PureKeccakF1600::permutation
(
MemoryInterface
&
memory
,
MemoryAddress
dst_addr
,
MemoryAddress
src_addr)
12
{
13
constexpr
MemoryAddress
HIGHEST_SLICE_ADDRESS =
AVM_HIGHEST_MEM_ADDRESS
-
AVM_KECCAKF1600_STATE_SIZE
+ 1;
14
15
bool
src_out_of_range = src_addr > HIGHEST_SLICE_ADDRESS;
16
bool
dst_out_of_range =
dst_addr
> HIGHEST_SLICE_ADDRESS;
17
18
if
(src_out_of_range) {
19
throw
KeccakF1600Exception
(
format
(
"Read slice out of range: "
, src_addr));
20
}
21
if
(dst_out_of_range) {
22
throw
KeccakF1600Exception
(
format
(
"Write slice out of range: "
,
dst_addr
));
23
}
24
25
uint64_t state[
AVM_KECCAKF1600_STATE_SIZE
];
26
27
// Read from memory
28
for
(
size_t
i = 0; i <
AVM_KECCAKF1600_STATE_SIZE
; ++i) {
29
const
auto
addr = src_addr +
static_cast<
MemoryAddress
>
(i);
30
const
MemoryValue
& mem_val =
memory
.get(addr);
31
const
MemoryTag
tag
= mem_val.get_tag();
32
33
if
(
tag
!=
MemoryTag::U64
) {
34
throw
KeccakF1600Exception
(
35
format
(
"Read slice tag invalid - addr: "
, addr,
" tag: "
,
static_cast<
uint32_t
>
(
tag
)));
36
}
37
38
state[i] = mem_val.as<uint64_t>();
39
}
40
41
// Perform permutation
42
ethash_keccakf1600
(state);
43
44
// Write back to memory
45
for
(
size_t
i = 0; i <
AVM_KECCAKF1600_STATE_SIZE
; ++i) {
46
memory
.set(
dst_addr
+
static_cast<
MemoryAddress
>
(i), MemoryValue::from<uint64_t>(state[i]));
47
}
48
}
49
50
}
// namespace bb::avm2::simulation
aztec_constants.hpp
AVM_KECCAKF1600_STATE_SIZE
#define AVM_KECCAKF1600_STATE_SIZE
Definition
aztec_constants.hpp:52
AVM_HIGHEST_MEM_ADDRESS
#define AVM_HIGHEST_MEM_ADDRESS
Definition
aztec_constants.hpp:45
bb::avm2::TaggedValue
Definition
tagged_value.hpp:114
bb::avm2::memory
Definition
memory.hpp:36
bb::avm2::simulation::MemoryInterface
Definition
memory.hpp:10
bb::avm2::simulation::PureKeccakF1600::permutation
void permutation(MemoryInterface &memory, MemoryAddress dst_addr, MemoryAddress src_addr) override
Definition
pure_keccakf1600.cpp:11
log.hpp
format
std::string format(Args... args)
Definition
log.hpp:24
VariableRefMutationOptions::tag
@ tag
dst_addr
uint32_t dst_addr
Definition
data_copy.test.cpp:69
keccak.hpp
ethash_keccakf1600
void ethash_keccakf1600(uint64_t state[KECCAKF1600_LANES]) NOEXCEPT
Definition
keccakf1600.cpp:36
keccakf1600_event.hpp
bb::avm2::simulation
Definition
address_derivation_event.hpp:6
bb::avm2::ValueTag
ValueTag
Definition
tagged_value.hpp:56
bb::avm2::ValueTag::U64
@ U64
bb::avm2::MemoryAddress
uint32_t MemoryAddress
Definition
memory_types.hpp:11
pure_keccakf1600.hpp
memory.hpp
bb::avm2::simulation::KeccakF1600Exception
Definition
keccakf1600_event.hpp:13
src
barretenberg
vm2
simulation
standalone
pure_keccakf1600.cpp
Generated by
1.9.8