Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
execution.test.cpp
Go to the documentation of this file.
1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
3
4#include <cstdint>
5
14
15namespace bb::avm2::constraining {
16namespace {
17
18using tracegen::TestTraceContainer;
20using C = Column;
22
23TEST(ExecutionConstrainingTest, EmptyRow)
24{
25 check_relation<execution>(testing::empty_trace());
26}
27
28// DO NOT SUBMIT: add full flow tests
29// TEST(ExecutionConstrainingTest, Basic)
30// {
31// // clang-format off
32// TestTraceContainer trace({
33// {{ C::execution_sel, 1 }, { C::execution_pc, 0 }},
34// {{ C::execution_sel, 1 }, { C::execution_pc, 20 }, { C::execution_last, 1 }}
35// });
36// // clang-format on
37
38// check_relation<execution>(trace);
39// }
40
41TEST(ExecutionConstrainingTest, Continuity)
42{
43 // clang-format off
44 TestTraceContainer trace({
45 {{ C::precomputed_first_row, 1 }},
46 {{ C::execution_sel, 1 }},
47 {{ C::execution_sel, 1 }},
48 {{ C::execution_sel, 1 }, {C::execution_last, 1}},
49 });
50 // clang-format on
51
52 check_relation<execution>(trace, execution::SR_TRACE_CONTINUITY);
53}
54
55TEST(ExecutionConstrainingTest, ContinuityBrokenFirstRow)
56{
57 // clang-format off
58 TestTraceContainer trace({
59 {{ C::execution_sel, 0 }}, // End of trace!
60 {{ C::execution_sel, 1 }},
61 {{ C::execution_sel, 1 }},
62 {{ C::execution_sel, 1 }, {C::execution_last, 1}},
63 });
64 // clang-format on
65
66 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_TRACE_CONTINUITY), "TRACE_CONTINUITY");
67}
68
69TEST(ExecutionConstrainingTest, ContinuityBrokenInMiddle)
70{
71 // clang-format off
72 TestTraceContainer trace({
73 {{ C::execution_sel, 1 }},
74 {{ C::execution_sel, 0 }}, // End of trace!
75 {{ C::execution_sel, 1 }},
76 {{ C::execution_sel, 1 }, {C::execution_last, 1}},
77 });
78 // clang-format on
79
80 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_TRACE_CONTINUITY), "TRACE_CONTINUITY");
81}
82
83TEST(ExecutionConstrainingTest, ContinuityMultipleLast)
84{
85 // clang-format off
86 TestTraceContainer trace({
87 {{ C::execution_sel, 1 }},
88 {{ C::execution_sel, 1 }},
89 {{ C::execution_sel, 1 }},
90 {{ C::execution_sel, 1 }, {C::execution_last, 1}},
91 });
92 // clang-format on
93
94 // Last is correct.
95 check_relation<execution>(trace, execution::SR_LAST_IS_LAST);
96 // If we add another last, it should fail.
97 trace.set(C::execution_last, /*row=*/1, /*value=*/1);
98 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_LAST_IS_LAST), "LAST_IS_LAST.*row 1");
99}
100
101TEST(ExecutionConstrainingTest, TreeStateNotChanged)
102{
103 TestTraceContainer trace({
104 {
105 { C::precomputed_first_row, 1 },
106 },
107 {
108 { C::execution_sel, 1 },
109 { C::execution_prev_note_hash_tree_root, 10 },
110 { C::execution_prev_note_hash_tree_size, 9 },
111 { C::execution_prev_num_note_hashes_emitted, 8 },
112 { C::execution_prev_nullifier_tree_root, 7 },
113 { C::execution_prev_nullifier_tree_size, 6 },
114 { C::execution_prev_num_nullifiers_emitted, 5 },
115 { C::execution_prev_public_data_tree_root, 4 },
116 { C::execution_prev_public_data_tree_size, 3 },
117 { C::execution_prev_written_public_data_slots_tree_root, 2 },
118 { C::execution_prev_written_public_data_slots_tree_size, 1 },
119 { C::execution_note_hash_tree_root, 10 },
120 { C::execution_note_hash_tree_size, 9 },
121 { C::execution_num_note_hashes_emitted, 8 },
122 { C::execution_nullifier_tree_root, 7 },
123 { C::execution_nullifier_tree_size, 6 },
124 { C::execution_num_nullifiers_emitted, 5 },
125 { C::execution_public_data_tree_root, 4 },
126 { C::execution_public_data_tree_size, 3 },
127 { C::execution_written_public_data_slots_tree_root, 2 },
128 { C::execution_written_public_data_slots_tree_size, 1 },
129 },
130 });
131
132 check_relation<execution>(trace,
143
144 // Negative test: change note hash tree root
145 trace.set(C::execution_note_hash_tree_root, 1, 100);
147 "NOTE_HASH_TREE_ROOT_NOT_CHANGED");
148
149 // Negative test: change note hash tree size
150 trace.set(C::execution_note_hash_tree_size, 1, 100);
152 "NOTE_HASH_TREE_SIZE_NOT_CHANGED");
153
154 // Negative test: change num note hashes emitted
155 trace.set(C::execution_num_note_hashes_emitted, 1, 100);
157 "NUM_NOTE_HASHES_EMITTED_NOT_CHANGED");
158
159 // Negative test: change nullifier tree root
160 trace.set(C::execution_nullifier_tree_root, 1, 100);
162 "NULLIFIER_TREE_ROOT_NOT_CHANGED");
163
164 // Negative test: change nullifier tree size
165 trace.set(C::execution_nullifier_tree_size, 1, 100);
167 "NULLIFIER_TREE_SIZE_NOT_CHANGED");
168
169 // Negative test: change num nullifiers emitted
170 trace.set(C::execution_prev_num_nullifiers_emitted, 1, 100);
172 "NUM_NULLIFIERS_EMITTED_NOT_CHANGED");
173
174 // Negative test: change public data tree root
175 trace.set(C::execution_public_data_tree_root, 1, 100);
177 "PUBLIC_DATA_TREE_ROOT_NOT_CHANGED");
178
179 // Negative test: change public data tree size
180 trace.set(C::execution_public_data_tree_size, 1, 100);
182 "PUBLIC_DATA_TREE_SIZE_NOT_CHANGED");
183
184 // Negative test: change written public data slots tree root
185 trace.set(C::execution_written_public_data_slots_tree_root, 1, 100);
188 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_NOT_CHANGED");
189
190 // Negative test: change written public data slots tree size
191 trace.set(C::execution_written_public_data_slots_tree_size, 1, 100);
194 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_NOT_CHANGED");
195}
196
197TEST(ExecutionConstrainingTest, SideEffectStateNotChanged)
198{
199 TestTraceContainer trace({
200 {
201 { C::precomputed_first_row, 1 },
202 },
203 {
204 { C::execution_sel, 1 },
205 { C::execution_prev_num_unencrypted_logs, 10 },
206 { C::execution_prev_num_l2_to_l1_messages, 11 },
207 { C::execution_num_unencrypted_logs, 10 },
208 { C::execution_num_l2_to_l1_messages, 11 },
209 },
210 });
211
212 check_relation<execution>(
214
215 // Negative test: change num unencrypted logs
216 trace.set(C::execution_num_unencrypted_logs, 1, 100);
218 "NUM_UNENCRYPTED_LOGS_NOT_CHANGED");
219
220 // Negative test: change num l2 to l1 messages
221 trace.set(C::execution_num_l2_to_l1_messages, 1, 100);
223 "NUM_L2_TO_L1_MESSAGES_NOT_CHANGED");
224}
225
226} // namespace
227} // namespace bb::avm2::constraining
static constexpr size_t SR_NUM_L2_TO_L1_MESSAGES_NOT_CHANGED
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NULLIFIER_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_LAST_IS_LAST
static constexpr size_t SR_NUM_NULLIFIERS_EMITTED_NOT_CHANGED
static constexpr size_t SR_PUBLIC_DATA_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NOTE_HASH_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_TRACE_CONTINUITY
static constexpr size_t SR_NULLIFIER_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_NUM_UNENCRYPTED_LOGS_NOT_CHANGED
static constexpr size_t SR_PUBLIC_DATA_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_NOT_CHANGED
static constexpr size_t SR_NOTE_HASH_TREE_SIZE_NOT_CHANGED
static constexpr size_t SR_NUM_NOTE_HASHES_EMITTED_NOT_CHANGED
void set(Column col, uint32_t row, const FF &value)
TestTraceContainer trace
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
Definition macros.hpp:7
TEST(TxExecutionConstrainingTest, WriteTreeValue)
Definition tx.test.cpp:508
TestTraceContainer empty_trace()
Definition fixtures.cpp:153
typename Flavor::FF FF
NiceMock< MockExecution > execution