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 <cstddef>
4
#include <cstdint>
5
6
#include "
barretenberg/aztec/aztec_constants.hpp
"
7
#include "
barretenberg/common/log.hpp
"
8
#include "
barretenberg/crypto/keccak/keccak.hpp
"
9
#include "
barretenberg/vm2/simulation/events/keccakf1600_event.hpp
"
10
#include "
barretenberg/vm2/simulation/interfaces/memory.hpp
"
11
12
namespace
bb::avm2::simulation
{
13
25
void
PureKeccakF1600::permutation
(
MemoryInterface
&
memory
,
MemoryAddress
dst_addr
,
MemoryAddress
src_addr
)
26
{
27
constexpr
MemoryAddress
HIGHEST_SLICE_ADDRESS =
AVM_HIGHEST_MEM_ADDRESS
-
AVM_KECCAKF1600_STATE_SIZE
+ 1;
28
29
bool
src_out_of_range =
src_addr
> HIGHEST_SLICE_ADDRESS;
30
bool
dst_out_of_range =
dst_addr
> HIGHEST_SLICE_ADDRESS;
31
32
if
(src_out_of_range) {
33
throw
KeccakF1600Exception
(
format
(
"Read slice out of range: "
,
src_addr
));
34
}
35
if
(dst_out_of_range) {
36
throw
KeccakF1600Exception
(
format
(
"Write slice out of range: "
,
dst_addr
));
37
}
38
39
uint64_t state[
AVM_KECCAKF1600_STATE_SIZE
];
40
41
// Read from memory
42
for
(
size_t
i = 0; i <
AVM_KECCAKF1600_STATE_SIZE
; ++i) {
43
const
auto
addr =
src_addr
+
static_cast<
MemoryAddress
>
(i);
44
const
MemoryValue
& mem_val =
memory
.get(addr);
45
const
MemoryTag
tag
= mem_val.get_tag();
46
47
if
(
tag
!=
MemoryTag::U64
) {
48
throw
KeccakF1600Exception
(
49
format
(
"Read slice tag invalid - addr: "
, addr,
" tag: "
,
static_cast<
uint32_t
>
(
tag
)));
50
}
51
52
state[i] = mem_val.as<uint64_t>();
53
}
54
55
// Perform permutation
56
ethash_keccakf1600
(state);
57
58
// Write back to memory
59
for
(
size_t
i = 0; i <
AVM_KECCAKF1600_STATE_SIZE
; ++i) {
60
memory
.set(
dst_addr
+
static_cast<
MemoryAddress
>
(i), MemoryValue::from<uint64_t>(state[i]));
61
}
62
}
63
64
}
// namespace bb::avm2::simulation
aztec_constants.hpp
AVM_KECCAKF1600_STATE_SIZE
#define AVM_KECCAKF1600_STATE_SIZE
Definition
aztec_constants.hpp:54
AVM_HIGHEST_MEM_ADDRESS
#define AVM_HIGHEST_MEM_ADDRESS
Definition
aztec_constants.hpp:47
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
Fast-mode Keccak-f[1600] permutation (no event emission).
Definition
pure_keccakf1600.cpp:25
log.hpp
format
std::string format(Args... args)
Definition
log.hpp:23
VariableRefMutationOptions::tag
@ tag
src_addr
uint32_t src_addr
Definition
data_copy.test.cpp:443
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
AVM range check gadget for witness generation.
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
Exception thrown on errors during the Keccak-f[1600] permutation.
Definition
keccakf1600_event.hpp:20
src
barretenberg
vm2
simulation
standalone
pure_keccakf1600.cpp
Generated by
1.9.8