Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
tx_context.test.cpp
Go to the documentation of this file.
1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
3
4#include <cstdint>
5
20
21namespace bb::avm2::constraining {
22namespace {
23
24using testing::PublicInputsBuilder;
25using tracegen::PrecomputedTraceBuilder;
26using tracegen::PublicInputsTraceBuilder;
27using tracegen::TestTraceContainer;
28using tracegen::TxTraceBuilder;
29
31using C = Column;
32using tx = bb::avm2::tx<FF>;
33using tx_context = bb::avm2::tx_context<FF>;
34
35TEST(TxContextConstrainingTest, Continuity)
36{
37 TestTraceContainer trace({
38 {
39 // Row 0: end of setup
40 { C::tx_sel, 1 },
41 { C::tx_reverted, 0 },
42 { C::tx_tx_reverted, 0 },
43 { C::tx_next_note_hash_tree_root, 1 },
44 { C::tx_next_note_hash_tree_size, 2 },
45 { C::tx_next_num_note_hashes_emitted, 3 },
46 { C::tx_next_nullifier_tree_root, 4 },
47 { C::tx_next_nullifier_tree_size, 5 },
48 { C::tx_next_num_nullifiers_emitted, 6 },
49 { C::tx_next_public_data_tree_root, 7 },
50 { C::tx_next_public_data_tree_size, 8 },
51 { C::tx_next_written_public_data_slots_tree_root, 9 },
52 { C::tx_next_written_public_data_slots_tree_size, 10 },
53 { C::tx_l1_l2_tree_root, 11 },
54 { C::tx_next_retrieved_bytecodes_tree_root, 12 },
55 { C::tx_next_retrieved_bytecodes_tree_size, 13 },
56 { C::tx_next_num_unencrypted_log_fields, 14 },
57 { C::tx_next_num_l2_to_l1_messages, 15 },
58 },
59 {
60 // Row 1: app logic, reverts
61 { C::tx_sel, 1 },
62 { C::tx_reverted, 1 },
63 { C::tx_tx_reverted, 1 },
64 { C::tx_prev_note_hash_tree_root, 1 },
65 { C::tx_prev_note_hash_tree_size, 2 },
66 { C::tx_prev_num_note_hashes_emitted, 3 },
67 { C::tx_prev_nullifier_tree_root, 4 },
68 { C::tx_prev_nullifier_tree_size, 5 },
69 { C::tx_prev_num_nullifiers_emitted, 6 },
70 { C::tx_prev_public_data_tree_root, 7 },
71 { C::tx_prev_public_data_tree_size, 8 },
72 { C::tx_prev_written_public_data_slots_tree_root, 9 },
73 { C::tx_prev_written_public_data_slots_tree_size, 10 },
74 { C::tx_l1_l2_tree_root, 11 },
75 { C::tx_prev_retrieved_bytecodes_tree_root, 12 },
76 { C::tx_prev_retrieved_bytecodes_tree_size, 13 },
77 { C::tx_prev_num_unencrypted_log_fields, 14 },
78 { C::tx_prev_num_l2_to_l1_messages, 15 },
79 { C::tx_next_note_hash_tree_root, 10 },
80 { C::tx_next_note_hash_tree_size, 20 },
81 { C::tx_next_num_note_hashes_emitted, 30 },
82 { C::tx_next_nullifier_tree_root, 40 },
83 { C::tx_next_nullifier_tree_size, 50 },
84 { C::tx_next_num_nullifiers_emitted, 60 },
85 { C::tx_next_public_data_tree_root, 70 },
86 { C::tx_next_public_data_tree_size, 80 },
87 { C::tx_next_written_public_data_slots_tree_root, 90 },
88 { C::tx_next_written_public_data_slots_tree_size, 100 },
89 { C::tx_next_retrieved_bytecodes_tree_root, 120 },
90 { C::tx_next_retrieved_bytecodes_tree_size, 130 },
91 { C::tx_next_num_unencrypted_log_fields, 140 },
92 { C::tx_next_num_l2_to_l1_messages, 150 },
93 },
94 {
95 // Row 2: restored end of setup state
96 { C::tx_sel, 1 },
97 { C::tx_reverted, 0 },
98 { C::tx_tx_reverted, 1 },
99 { C::tx_prev_note_hash_tree_root, 1 },
100 { C::tx_prev_note_hash_tree_size, 2 },
101 { C::tx_prev_num_note_hashes_emitted, 3 },
102 { C::tx_prev_nullifier_tree_root, 4 },
103 { C::tx_prev_nullifier_tree_size, 5 },
104 { C::tx_prev_num_nullifiers_emitted, 6 },
105 { C::tx_prev_public_data_tree_root, 7 },
106 { C::tx_prev_public_data_tree_size, 8 },
107 { C::tx_prev_written_public_data_slots_tree_root, 9 },
108 { C::tx_prev_written_public_data_slots_tree_size, 10 },
109 { C::tx_l1_l2_tree_root, 11 },
110 { C::tx_prev_retrieved_bytecodes_tree_root, 120 },
111 { C::tx_prev_retrieved_bytecodes_tree_size, 130 },
112 { C::tx_prev_num_unencrypted_log_fields, 14 },
113 { C::tx_prev_num_l2_to_l1_messages, 15 },
114 },
115 });
116
117 check_relation<tx_context>(trace,
134
135 // Negative test: if not reverted, it shouldn't be able to rollback state from row 1 to row 2
136
137 trace.set(C::tx_reverted, 1, 0);
138
140 "NOTE_HASH_ROOT_CONTINUITY");
142 "NOTE_HASH_TREE_SIZE_CONTINUITY");
144 "NUM_NOTE_HASHES_EMITTED_CONTINUITY");
146 "NULLIFIER_TREE_ROOT_CONTINUITY");
148 "NULLIFIER_TREE_SIZE_CONTINUITY");
150 "NUM_NULLIFIERS_EMITTED_CONTINUITY");
152 "PUBLIC_DATA_TREE_ROOT_CONTINUITY");
154 "PUBLIC_DATA_TREE_SIZE_CONTINUITY");
156 check_relation<tx_context>(trace, tx_context::SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_CONTINUITY),
157 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_CONTINUITY");
159 check_relation<tx_context>(trace, tx_context::SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_CONTINUITY),
160 "WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_CONTINUITY");
162 "NUM_UNENCRYPTED_LOGS_CONTINUITY");
164 "NUM_L2_TO_L1_MESSAGES_CONTINUITY");
165 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_TX_REVERTED_CONTINUITY),
166 "TX_REVERTED_CONTINUITY");
167
168 // Negative test: l1 to l2 root should not change
169
170 trace.set(C::tx_l1_l2_tree_root, 1, 20);
171
173 "L1_L2_TREE_ROOT_CONTINUITY");
174
175 // Negative test: even in reverts, retrieved bytecodes tree root and size should not change
176 trace.set(C::tx_prev_retrieved_bytecodes_tree_root, 2, 12);
177 trace.set(C::tx_prev_retrieved_bytecodes_tree_size, 2, 13);
178
180 check_relation<tx_context>(trace, tx_context::SR_RETRIEVED_BYTECODES_TREE_ROOT_CONTINUITY),
181 "RETRIEVED_BYTECODES_TREE_ROOT_CONTINUITY");
183 check_relation<tx_context>(trace, tx_context::SR_RETRIEVED_BYTECODES_TREE_SIZE_CONTINUITY),
184 "RETRIEVED_BYTECODES_TREE_SIZE_CONTINUITY");
185}
186
187TEST(TxContextConstrainingTest, StateMutability)
188{
189 TestTraceContainer trace({
190 {
191 { C::tx_sel, 1 },
192 { C::tx_is_public_call_request, 1 },
193 { C::tx_should_process_call_request, 1 },
194 { C::tx_prev_note_hash_tree_root, 1 },
195 { C::tx_prev_note_hash_tree_size, 2 },
196 { C::tx_prev_num_note_hashes_emitted, 3 },
197 { C::tx_prev_nullifier_tree_root, 4 },
198 { C::tx_prev_nullifier_tree_size, 5 },
199 { C::tx_prev_num_nullifiers_emitted, 6 },
200 { C::tx_prev_public_data_tree_root, 7 },
201 { C::tx_prev_public_data_tree_size, 8 },
202 { C::tx_prev_written_public_data_slots_tree_root, 9 },
203 { C::tx_prev_written_public_data_slots_tree_size, 10 },
204 { C::tx_l1_l2_tree_root, 11 },
205 { C::tx_prev_retrieved_bytecodes_tree_root, 12 },
206 { C::tx_prev_retrieved_bytecodes_tree_size, 13 },
207 { C::tx_prev_num_unencrypted_log_fields, 13 },
208 { C::tx_prev_num_l2_to_l1_messages, 14 },
209 { C::tx_next_note_hash_tree_root, 10 },
210 { C::tx_next_note_hash_tree_size, 20 },
211 { C::tx_next_num_note_hashes_emitted, 30 },
212 { C::tx_next_nullifier_tree_root, 40 },
213 { C::tx_next_nullifier_tree_size, 50 },
214 { C::tx_next_num_nullifiers_emitted, 60 },
215 { C::tx_next_public_data_tree_root, 70 },
216 { C::tx_next_public_data_tree_size, 80 },
217 { C::tx_next_written_public_data_slots_tree_root, 90 },
218 { C::tx_next_written_public_data_slots_tree_size, 100 },
219 { C::tx_l1_l2_tree_root, 110 },
220 { C::tx_next_retrieved_bytecodes_tree_root, 120 },
221 { C::tx_next_retrieved_bytecodes_tree_size, 130 },
222 { C::tx_next_num_unencrypted_log_fields, 140 },
223 { C::tx_next_num_l2_to_l1_messages, 150 },
224 },
225 });
226
227 check_relation<tx_context>(trace,
242
243 // Negative test: immutability check on note hashes
244 trace.set(C::tx_is_public_call_request, 0, 0);
245
247 "NOTE_HASH_ROOT_IMMUTABILITY");
249 "NOTE_HASH_SIZE_IMMUTABILITY");
251 "NOTE_HASH_COUNT_IMMUTABILITY");
252
253 // Negative test: immutability check on nullifiers
254
256 "NULLIFIER_ROOT_IMMUTABILITY");
258 "NULLIFIER_SIZE_IMMUTABILITY");
260 "NULLIFIER_COUNT_IMMUTABILITY");
261
262 // Negative test: immutability check on public data
263
265 "PUBLIC_DATA_ROOT_IMMUTABILITY");
267 "PUBLIC_DATA_SIZE_IMMUTABILITY");
269 check_relation<tx_context>(trace, tx_context::SR_WRITTEN_PUBLIC_DATA_SLOTS_ROOT_IMMUTABILITY),
270 "WRITTEN_PUBLIC_DATA_SLOTS_ROOT_IMMUTABILITY");
272 check_relation<tx_context>(trace, tx_context::SR_WRITTEN_PUBLIC_DATA_SLOTS_SIZE_IMMUTABILITY),
273 "WRITTEN_PUBLIC_DATA_SLOTS_SIZE_IMMUTABILITY");
274
275 // Negative test: immutability check on unencrypted logs
276
278 "UNENCRYPTED_LOG_COUNT_IMMUTABILITY");
279
280 // Negative test: immutability check on l2 to l1 messages
281
283 "L2_TO_L1_MESSAGE_COUNT_IMMUTABILITY");
284
285 // Negative test: immutability check on retrieved bytecodes tree
286 trace.set(C::tx_should_process_call_request, 0, 0);
287
289 check_relation<tx_context>(trace, tx_context::SR_RETRIEVED_BYTECODES_TREE_ROOT_IMMUTABILITY),
290 "RETRIEVED_BYTECODES_TREE_ROOT_IMMUTABILITY");
292 check_relation<tx_context>(trace, tx_context::SR_RETRIEVED_BYTECODES_TREE_SIZE_IMMUTABILITY),
293 "RETRIEVED_BYTECODES_TREE_SIZE_IMMUTABILITY");
294
295 // Negative test: selectors enabled but it's a padded row
296 trace.set(C::tx_is_public_call_request, 0, 1);
297 trace.set(C::tx_is_padded, 0, 1);
298
300 "NOTE_HASH_ROOT_PADDED_IMMUTABILITY");
302 "NOTE_HASH_SIZE_PADDED_IMMUTABILITY");
304 "NOTE_HASH_COUNT_PADDED_IMMUTABILITY");
305
307 "NULLIFIER_ROOT_PADDED_IMMUTABILITY");
309 "NULLIFIER_SIZE_PADDED_IMMUTABILITY");
311 "NULLIFIER_COUNT_PADDED_IMMUTABILITY");
312
314 "PUBLIC_DATA_ROOT_PADDED_IMMUTABILITY");
316 "PUBLIC_DATA_SIZE_PADDED_IMMUTABILITY");
319 "WRITTEN_PUBLIC_DATA_SLOTS_ROOT_PADDED_IMMUTABILITY");
322 "WRITTEN_PUBLIC_DATA_SLOTS_SIZE_PADDED_IMMUTABILITY");
323
325 check_relation<tx_context>(trace, tx_context::SR_UNENCRYPTED_LOG_COUNT_PADDED_IMMUTABILITY),
326 "UNENCRYPTED_LOG_COUNT_PADDED_IMMUTABILITY");
327
329 check_relation<tx_context>(trace, tx_context::SR_L2_TO_L1_MESSAGE_COUNT_PADDED_IMMUTABILITY),
330 "L2_TO_L1_MESSAGE_COUNT_PADDED_IMMUTABILITY");
331}
332
333TEST(TxContextConstrainingTest, InitialStateChecks)
334{
335 Gas start_gas_used = { 1, 2 };
336 Gas gas_limit = { 1000, 2000 };
337 GasSettings gas_settings = { .gas_limits = gas_limit };
338 TreeSnapshots tree_snapshots = { .l1_to_l2_message_tree = { .root = 20, .next_available_leaf_index = 19 },
339 .note_hash_tree = { .root = 21, .next_available_leaf_index = 20 },
340 .nullifier_tree = { .root = 22, .next_available_leaf_index = 21 },
341 .public_data_tree = { .root = 23, .next_available_leaf_index = 22 } };
342 auto public_inputs = PublicInputsBuilder()
343 .with_start_gas_used(start_gas_used)
344 .with_gas_settings(gas_settings)
345 .with_start_tree_snapshots(tree_snapshots)
346 .build();
347
348 TestTraceContainer trace({
349 {
350 // Row 0
351 { C::precomputed_first_row, 1 },
352 },
353 {
354 // Row 1
355 { C::tx_sel, 1 },
356 { C::tx_start_tx, 1 },
357 { C::tx_prev_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
358 { C::tx_prev_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
359 { C::tx_prev_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
360 { C::tx_prev_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
361 { C::tx_prev_public_data_tree_root, tree_snapshots.public_data_tree.root },
362 { C::tx_prev_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
363 { C::tx_prev_written_public_data_slots_tree_root, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT) },
364 { C::tx_prev_written_public_data_slots_tree_size, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE) },
365 { C::tx_prev_retrieved_bytecodes_tree_root, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT) },
366 { C::tx_prev_retrieved_bytecodes_tree_size, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE) },
367 { C::tx_l1_l2_tree_root, tree_snapshots.l1_to_l2_message_tree.root },
368 { C::tx_l1_l2_tree_size, tree_snapshots.l1_to_l2_message_tree.next_available_leaf_index },
369 { C::tx_prev_l2_gas_used, start_gas_used.l2_gas },
370 { C::tx_prev_da_gas_used, start_gas_used.da_gas },
371 { C::tx_l2_gas_limit, gas_limit.l2_gas },
372 { C::tx_da_gas_limit, gas_limit.da_gas },
373 { C::tx_prev_num_unencrypted_log_fields, 0 },
374 { C::tx_prev_num_l2_to_l1_messages, 0 },
376 { C::tx_sel_read_trees_and_gas_used, 1 },
380 { C::tx_gas_used_pi_offset, FF(AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX) },
381 { C::tx_gas_limit_pi_offset, FF(AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX) },
382 { C::tx_should_read_gas_limit, 1 },
383 { C::tx_next_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
384 { C::tx_next_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
385 { C::tx_next_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
386 { C::tx_next_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
387 { C::tx_next_public_data_tree_root, tree_snapshots.public_data_tree.root },
388 { C::tx_next_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
389 { C::tx_next_written_public_data_slots_tree_root, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT) },
390 { C::tx_next_written_public_data_slots_tree_size, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE) },
391 { C::tx_next_retrieved_bytecodes_tree_root, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT) },
392 { C::tx_next_retrieved_bytecodes_tree_size, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE) },
393 { C::tx_next_l2_gas_used, start_gas_used.l2_gas },
394 { C::tx_next_da_gas_used, start_gas_used.da_gas },
395 { C::tx_setup_phase_value, static_cast<uint8_t>(TransactionPhase::SETUP) },
396 { C::tx_next_context_id, 1 },
397 },
398 });
399
400 PublicInputsTraceBuilder public_inputs_builder;
401 public_inputs_builder.process_public_inputs(trace, public_inputs);
402 public_inputs_builder.process_public_inputs_aux_precomputed(trace);
403
404 PrecomputedTraceBuilder precomputed_builder;
406
407 check_relation<tx_context>(trace);
408 // All tx_context interactions
409 check_interaction<TxTraceBuilder,
421}
422
423TEST(TxContextConstrainingTest, EndStateChecks)
424{
425 Gas end_gas_used = { 1, 2 };
426 TreeSnapshots tree_snapshots = { .l1_to_l2_message_tree = { .root = 20, .next_available_leaf_index = 19 },
427 .note_hash_tree = { .root = 21, .next_available_leaf_index = 20 },
428 .nullifier_tree = { .root = 22, .next_available_leaf_index = 21 },
429 .public_data_tree = { .root = 23, .next_available_leaf_index = 22 } };
430 AvmAccumulatedDataArrayLengths array_lengths = { .note_hashes = 10, .nullifiers = 11, .l2_to_l1_msgs = 12 };
431
432 PublicLog log = {
433 .fields = { FF(4), FF(5) },
434 .contract_address = 11223,
435 };
436 PublicLogs public_logs = {};
437 public_logs.add_log(log);
438 AvmAccumulatedData accumulated_data = { .public_logs = public_logs };
439
440 auto public_inputs = PublicInputsBuilder()
441 .set_end_gas_used(end_gas_used)
442 .set_end_tree_snapshots(tree_snapshots)
443 .set_accumulated_data_array_lengths(array_lengths)
444 .set_accumulated_data(accumulated_data)
445 .build();
446
447 TestTraceContainer trace({
448 {
449 // Row 0
450 { C::precomputed_first_row, 1 },
451 },
452 {
453 // Row 1
454 { C::tx_sel, 1 },
455 { C::tx_is_cleanup, 1 },
456 { C::tx_prev_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
457 { C::tx_prev_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
458 { C::tx_prev_num_note_hashes_emitted, array_lengths.note_hashes },
459 { C::tx_prev_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
460 { C::tx_prev_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
461 { C::tx_prev_num_nullifiers_emitted, array_lengths.nullifiers },
462 { C::tx_prev_public_data_tree_root, tree_snapshots.public_data_tree.root },
463 { C::tx_prev_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
464 { C::tx_l1_l2_tree_root, tree_snapshots.l1_to_l2_message_tree.root },
465 { C::tx_l1_l2_tree_size, tree_snapshots.l1_to_l2_message_tree.next_available_leaf_index },
466 { C::tx_prev_l2_gas_used, end_gas_used.l2_gas },
467 { C::tx_prev_da_gas_used, end_gas_used.da_gas },
468 { C::tx_prev_num_unencrypted_log_fields, public_logs.length },
469 { C::tx_prev_num_l2_to_l1_messages, array_lengths.l2_to_l1_msgs },
471 { C::tx_sel_read_trees_and_gas_used, 1 },
475 { C::tx_gas_used_pi_offset, FF(AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX) },
476 { C::tx_reverted_pi_offset, AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX },
477 { C::tx_array_length_note_hashes_pi_offset,
479 { C::tx_array_length_nullifiers_pi_offset,
481 { C::tx_array_length_l2_to_l1_messages_pi_offset,
483 { C::tx_fields_length_unencrypted_logs_pi_offset,
485 { C::tx_next_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
486 { C::tx_next_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
487 { C::tx_next_num_note_hashes_emitted, array_lengths.note_hashes },
488 { C::tx_next_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
489 { C::tx_next_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
490 { C::tx_next_num_nullifiers_emitted, array_lengths.nullifiers },
491 { C::tx_next_public_data_tree_root, tree_snapshots.public_data_tree.root },
492 { C::tx_next_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
493 { C::tx_next_l2_gas_used, end_gas_used.l2_gas },
494 { C::tx_next_da_gas_used, end_gas_used.da_gas },
495 { C::tx_next_num_unencrypted_log_fields, public_logs.length },
496 { C::tx_next_num_l2_to_l1_messages, array_lengths.l2_to_l1_msgs },
497 { C::tx_setup_phase_value, static_cast<uint8_t>(TransactionPhase::SETUP) },
498 },
499 });
500
501 PublicInputsTraceBuilder public_inputs_builder;
502 public_inputs_builder.process_public_inputs(trace, public_inputs);
503 public_inputs_builder.process_public_inputs_aux_precomputed(trace);
504
505 PrecomputedTraceBuilder precomputed_builder;
507
508 check_relation<tx_context>(trace);
509 // All tx_context interactions
510 check_interaction<TxTraceBuilder,
523}
524
525TEST(TxContextConstrainingTest, NegativeContextIdChecks)
526{
527 TestTraceContainer trace({
528 {
529 // Row 0
530 { C::precomputed_first_row, 1 },
531 },
532 {
533 // Row 1
534 { C::tx_sel, 1 },
535 { C::tx_start_tx, 1 },
536 { C::tx_next_context_id, 1 },
537 },
538 {
539 // Row 2
540 { C::tx_sel, 1 },
541 { C::tx_next_context_id, 1 },
542 { C::tx_should_process_call_request, 1 },
543 },
544 {
545 // Row 3
546 { C::tx_sel, 1 },
547 { C::tx_next_context_id, 5 },
548 },
549 });
550 check_relation<tx_context>(
552
553 // Negative test: initial context id should be 1
554 trace.set(C::tx_next_context_id, 1, 2);
556 "NEXT_CONTEXT_ID_INITIAL_VALUE");
557
558 // Negative test: continuity check
559 trace.set(C::tx_next_context_id, 2, 42);
561 "NEXT_CONTEXT_ID_CONTINUITY");
562}
563
564TEST(TxContextConstrainingTest, NegativeTxRevertedChecks)
565{
566 TestTraceContainer trace({
567 {
568 // Row 0
569 { C::precomputed_first_row, 1 },
570 },
571 {
572 // Row 1: no revert
573 { C::tx_sel, 1 },
574 { C::tx_start_tx, 1 },
575 },
576 {
577 // Row 2: revert
578 { C::tx_sel, 1 },
579 { C::tx_reverted, 1 },
580 { C::tx_tx_reverted, 1 },
581 },
582 {
583 // Row 3: no revert
584 { C::tx_sel, 1 },
585 { C::tx_tx_reverted, 1 },
586 },
587 });
588 check_relation<tx_context>(
590
591 // Negative test: initial tx_reverted should match reverted
592 trace.set(C::tx_tx_reverted, 1, 1);
593 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_INIT_TX_REVERTED), "INIT_TX_REVERTED");
594
595 // Negative test: continuity check
596 trace.set(C::tx_tx_reverted, 3, 0);
597 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_TX_REVERTED_CONTINUITY),
598 "TX_REVERTED_CONTINUITY");
599
600 // Negative test: tx_reverted should match reverted if reverted == 1
601 trace.set(C::tx_tx_reverted, 2, 0);
602 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_SET_TX_REVERTED), "SET_TX_REVERTED");
603}
604
605} // namespace
606} // namespace bb::avm2::constraining
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX
#define AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT
#define AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX
#define AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX
#define AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX
#define AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX
#define AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX
#define AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX
void process_misc(TraceContainer &trace, const uint32_t num_rows=MAX_AVM_TRACE_SIZE)
void set(Column col, uint32_t row, const FF &value)
static constexpr size_t SR_NULLIFIER_SIZE_IMMUTABILITY
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_ROOT_CONTINUITY
static constexpr size_t SR_NULLIFIER_COUNT_PADDED_IMMUTABILITY
static constexpr size_t SR_INIT_TX_REVERTED
static constexpr size_t SR_NOTE_HASH_ROOT_PADDED_IMMUTABILITY
static constexpr size_t SR_NUM_UNENCRYPTED_LOGS_CONTINUITY
static constexpr size_t SR_NULLIFIER_COUNT_IMMUTABILITY
static constexpr size_t SR_NOTE_HASH_SIZE_PADDED_IMMUTABILITY
static constexpr size_t SR_NULLIFIER_SIZE_PADDED_IMMUTABILITY
static constexpr size_t SR_NUM_L2_TO_L1_MESSAGES_CONTINUITY
static constexpr size_t SR_NOTE_HASH_COUNT_PADDED_IMMUTABILITY
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_ROOT_IMMUTABILITY
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_ROOT_PADDED_IMMUTABILITY
static constexpr size_t SR_PUBLIC_DATA_SIZE_PADDED_IMMUTABILITY
static constexpr size_t SR_NULLIFIER_TREE_SIZE_CONTINUITY
static constexpr size_t SR_UNENCRYPTED_LOG_COUNT_IMMUTABILITY
static constexpr size_t SR_L2_TO_L1_MESSAGE_COUNT_IMMUTABILITY
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_SIZE_CONTINUITY
static constexpr size_t SR_PUBLIC_DATA_ROOT_PADDED_IMMUTABILITY
static constexpr size_t SR_PUBLIC_DATA_TREE_ROOT_CONTINUITY
static constexpr size_t SR_NOTE_HASH_ROOT_IMMUTABILITY
static constexpr size_t SR_NEXT_CONTEXT_ID_CONTINUITY
static constexpr size_t SR_NOTE_HASH_SIZE_IMMUTABILITY
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_SIZE_IMMUTABILITY
static constexpr size_t SR_NOTE_HASH_TREE_SIZE_CONTINUITY
static constexpr size_t SR_NULLIFIER_ROOT_PADDED_IMMUTABILITY
static constexpr size_t SR_UNENCRYPTED_LOG_COUNT_PADDED_IMMUTABILITY
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_CONTINUITY
static constexpr size_t SR_NULLIFIER_ROOT_IMMUTABILITY
static constexpr size_t SR_NOTE_HASH_ROOT_CONTINUITY
static constexpr size_t SR_RETRIEVED_BYTECODES_TREE_ROOT_CONTINUITY
static constexpr size_t SR_PUBLIC_DATA_ROOT_IMMUTABILITY
static constexpr size_t SR_NUM_NOTE_HASHES_EMITTED_CONTINUITY
static constexpr size_t SR_PUBLIC_DATA_SIZE_IMMUTABILITY
static constexpr size_t SR_NUM_NULLIFIERS_EMITTED_CONTINUITY
static constexpr size_t SR_NOTE_HASH_COUNT_IMMUTABILITY
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_SIZE_PADDED_IMMUTABILITY
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_SIZE_IMMUTABILITY
static constexpr size_t SR_L2_TO_L1_MESSAGE_COUNT_PADDED_IMMUTABILITY
static constexpr size_t SR_NEXT_CONTEXT_ID_INITIAL_VALUE
static constexpr size_t SR_WRITTEN_PUBLIC_DATA_SLOTS_ROOT_IMMUTABILITY
static constexpr size_t SR_L1_L2_TREE_ROOT_CONTINUITY
static constexpr size_t SR_NULLIFIER_TREE_ROOT_CONTINUITY
static constexpr size_t SR_TX_REVERTED_CONTINUITY
static constexpr size_t SR_PUBLIC_DATA_TREE_SIZE_CONTINUITY
static constexpr size_t SR_SET_TX_REVERTED
PrecomputedTraceBuilder precomputed_builder
Definition alu.test.cpp:120
TestTraceContainer trace
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
Definition macros.hpp:7
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
Definition tx.test.cpp:441
lookup_settings< lookup_tx_context_public_inputs_write_l2_to_l1_message_count_settings_ > lookup_tx_context_public_inputs_write_l2_to_l1_message_count_settings
lookup_settings< lookup_tx_context_public_inputs_note_hash_tree_settings_ > lookup_tx_context_public_inputs_note_hash_tree_settings
lookup_settings< lookup_tx_context_public_inputs_nullifier_tree_settings_ > lookup_tx_context_public_inputs_nullifier_tree_settings
lookup_settings< lookup_tx_context_public_inputs_read_gas_limit_settings_ > lookup_tx_context_public_inputs_read_gas_limit_settings
lookup_settings< lookup_tx_context_public_inputs_public_data_tree_settings_ > lookup_tx_context_public_inputs_public_data_tree_settings
lookup_settings< lookup_tx_context_public_inputs_gas_used_settings_ > lookup_tx_context_public_inputs_gas_used_settings
lookup_settings< lookup_tx_context_public_inputs_l1_l2_tree_settings_ > lookup_tx_context_public_inputs_l1_l2_tree_settings
lookup_settings< lookup_tx_context_restore_state_on_revert_settings_ > lookup_tx_context_restore_state_on_revert_settings
lookup_settings< lookup_tx_context_public_inputs_write_nullifier_count_settings_ > lookup_tx_context_public_inputs_write_nullifier_count_settings
lookup_settings< lookup_tx_context_public_inputs_write_note_hash_count_settings_ > lookup_tx_context_public_inputs_write_note_hash_count_settings
lookup_settings< lookup_tx_context_public_inputs_read_reverted_settings_ > lookup_tx_context_public_inputs_read_reverted_settings
lookup_settings< lookup_tx_context_public_inputs_write_unencrypted_log_count_settings_ > lookup_tx_context_public_inputs_write_unencrypted_log_count_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
tracegen::PublicInputsTraceBuilder public_inputs_builder
Definition tx.test.cpp:81