Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pure_keccakf1600.cpp
Go to the documentation of this file.
2
3#include <cstddef>
4#include <cstdint>
5
11
12namespace bb::avm2::simulation {
13
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) {
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
#define AVM_KECCAKF1600_STATE_SIZE
#define AVM_HIGHEST_MEM_ADDRESS
void permutation(MemoryInterface &memory, MemoryAddress dst_addr, MemoryAddress src_addr) override
Fast-mode Keccak-f[1600] permutation (no event emission).
std::string format(Args... args)
Definition log.hpp:23
uint32_t src_addr
uint32_t dst_addr
void ethash_keccakf1600(uint64_t state[KECCAKF1600_LANES]) NOEXCEPT
AVM range check gadget for witness generation.
uint32_t MemoryAddress
Exception thrown on errors during the Keccak-f[1600] permutation.