Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
keccakf1600.test.cpp
Go to the documentation of this file.
1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
3
13
14namespace bb::avm2::constraining {
15namespace {
16
17using tracegen::KeccakF1600TraceBuilder;
18using tracegen::TestTraceContainer;
19
20using keccakf1600_relation = bb::avm2::keccakf1600<AvmFlavorSettings::FF>;
21using keccak_memory_relation = bb::avm2::keccak_memory<AvmFlavorSettings::FF>;
22
23TEST(KeccakF1600ConstrainingTest, EmptyRow)
24{
25 check_relation<keccakf1600_relation>(testing::empty_trace());
26}
27
28// Positive test of a single permutation with simulation and trace generation and checking interactions.
29TEST(KeccakF1600ConstrainingTest, SinglewithSimulationAndTraceGenInteractions)
30{
31 TestTraceContainer trace;
32
33 const MemoryAddress src_addr = 0;
34 const MemoryAddress dst_addr = 200;
35
36 testing::generate_keccak_trace(trace, { dst_addr }, { src_addr }, /*space_id=*/23);
37
38 check_all_interactions<tracegen::KeccakF1600TraceBuilder>(trace);
39 check_relation<keccakf1600_relation>(trace);
40 check_relation<keccak_memory_relation>(trace);
41}
42
43// Positive test for multiple permutation calls with simulation and trace generation.
44// We also check all interactions.
45TEST(KeccakF1600ConstrainingTest, MultipleWithSimulationAndTraceGenInteractions)
46{
47 TestTraceContainer trace;
48
49 constexpr size_t NUM_PERMUTATIONS = 3;
50
51 std::vector<MemoryAddress> src_addresses(NUM_PERMUTATIONS);
52 std::vector<MemoryAddress> dst_addresses(NUM_PERMUTATIONS);
53
54 for (size_t k = 0; k < NUM_PERMUTATIONS; ++k) {
55 src_addresses.at(k) = static_cast<MemoryAddress>(k * 200);
56 dst_addresses.at(k) = static_cast<MemoryAddress>((k * 200) + 1000);
57 }
58
59 testing::generate_keccak_trace(trace, dst_addresses, src_addresses, /*space_id=*/79);
60
61 check_all_interactions<tracegen::KeccakF1600TraceBuilder>(trace);
62 check_relation<keccakf1600_relation>(trace);
63 check_relation<keccak_memory_relation>(trace);
64}
65
66// Test tag error handling when a memory value has an incorrect tag.
67// We test when the memory tag is not U64 for a read value at index (1, 2).
68// We check that the tag_error is 1 for this index (flattened index 7) and that
69// we correctly propagate the error to the top.
70TEST(KeccakF1600ConstrainingTest, TagErrorHandling)
71{
72 TestTraceContainer trace;
73
74 const MemoryAddress src_addr = 0;
75 const MemoryAddress dst_addr = 200;
76 const uint32_t space_id = 79;
77
78 // Position (1,2) in the 5x5 matrix corresponds to index 7 in the flattened array
79 const size_t error_offset = 7; // (1 * 5) + 2 = 7
80 const MemoryTag error_tag = MemoryTag::U32; // Using U32 instead of U64 to trigger error
81
82 testing::generate_keccak_trace_with_tag_error(trace, dst_addr, src_addr, error_offset, error_tag, space_id);
83
84 check_all_interactions<tracegen::KeccakF1600TraceBuilder>(trace);
85 check_relation<keccakf1600_relation>(trace);
86 check_relation<keccak_memory_relation>(trace);
87}
88
89// Test slice error handling when the src address is out of bounds.
90TEST(KeccakF1600ConstrainingTest, SrcAddressOutOfBounds)
91{
92 TestTraceContainer trace;
93
95 const MemoryAddress dst_addr = 456;
96 const uint32_t space_id = 23;
97
99
100 check_all_interactions<tracegen::KeccakF1600TraceBuilder>(trace);
101 check_relation<keccakf1600_relation>(trace);
102 check_relation<keccak_memory_relation>(trace);
103}
104
105// Test slice error handling when the dst address is out of bounds.
106TEST(KeccakF1600ConstrainingTest, DstAddressOutOfBounds)
107{
108 TestTraceContainer trace;
109
110 const MemoryAddress src_addr = 123;
112 const uint32_t space_id = 23;
113
115
116 check_all_interactions<tracegen::KeccakF1600TraceBuilder>(trace);
117 check_relation<keccakf1600_relation>(trace);
118 check_relation<keccak_memory_relation>(trace);
119}
120
121} // namespace
122} // namespace bb::avm2::constraining
#define AVM_KECCAKF1600_STATE_SIZE
#define AVM_HIGHEST_MEM_ADDRESS
uint32_t dst_addr
TestTraceContainer trace
TEST(TxExecutionConstrainingTest, WriteTreeValue)
Definition tx.test.cpp:508
void generate_keccak_trace_with_slice_error(TestTraceContainer &trace, MemoryAddress dst_address, MemoryAddress src_address, uint32_t space_id)
void generate_keccak_trace_with_tag_error(TestTraceContainer &trace, MemoryAddress dst_address, MemoryAddress src_address, size_t error_offset, MemoryTag error_tag, uint32_t space_id)
void generate_keccak_trace(TestTraceContainer &trace, const std::vector< MemoryAddress > &dst_addresses, const std::vector< MemoryAddress > &src_addresses, uint32_t space_id)
TestTraceContainer empty_trace()
Definition fixtures.cpp:153
uint32_t MemoryAddress
ValueTag MemoryTag
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13