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
8
9namespace bb::avm2::simulation {
10
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) {
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
#define AVM_KECCAKF1600_STATE_SIZE
#define AVM_HIGHEST_MEM_ADDRESS
void permutation(MemoryInterface &memory, MemoryAddress dst_addr, MemoryAddress src_addr) override
std::string format(Args... args)
Definition log.hpp:24
uint32_t dst_addr
void ethash_keccakf1600(uint64_t state[KECCAKF1600_LANES]) NOEXCEPT
uint32_t MemoryAddress