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_public_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_public_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_public_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_public_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_PUBLIC_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_public_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_public_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 public logs
276
278 "PUBLIC_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 "PUBLIC_LOG_COUNT_PADDED_IMMUTABILITY");
326
328 check_relation<tx_context>(trace, tx_context::SR_L2_TO_L1_MESSAGE_COUNT_PADDED_IMMUTABILITY),
329 "L2_TO_L1_MESSAGE_COUNT_PADDED_IMMUTABILITY");
330}
331
332TEST(TxContextConstrainingTest, InitialStateChecks)
333{
334 Gas start_gas_used = { 1, 2 };
335 Gas gas_limit = { 1000, 2000 };
336 GasSettings gas_settings = { .gas_limits = gas_limit };
337 TreeSnapshots tree_snapshots = { .l1_to_l2_message_tree = { .root = 20, .next_available_leaf_index = 19 },
338 .note_hash_tree = { .root = 21, .next_available_leaf_index = 20 },
339 .nullifier_tree = { .root = 22, .next_available_leaf_index = 21 },
340 .public_data_tree = { .root = 23, .next_available_leaf_index = 22 } };
341 auto public_inputs = PublicInputsBuilder()
342 .with_start_gas_used(start_gas_used)
343 .with_gas_settings(gas_settings)
344 .with_start_tree_snapshots(tree_snapshots)
345 .build();
346
347 TestTraceContainer trace({
348 {
349 // Row 0
350 { C::precomputed_first_row, 1 },
351 },
352 {
353 // Row 1
354 { C::tx_sel, 1 },
355 { C::tx_start_tx, 1 },
356 { C::tx_prev_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
357 { C::tx_prev_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
358 { C::tx_prev_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
359 { C::tx_prev_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
360 { C::tx_prev_public_data_tree_root, tree_snapshots.public_data_tree.root },
361 { C::tx_prev_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
362 { C::tx_prev_written_public_data_slots_tree_root, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT) },
363 { C::tx_prev_written_public_data_slots_tree_size, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE) },
364 { C::tx_prev_retrieved_bytecodes_tree_root, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT) },
365 { C::tx_prev_retrieved_bytecodes_tree_size, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE) },
366 { C::tx_l1_l2_tree_root, tree_snapshots.l1_to_l2_message_tree.root },
367 { C::tx_l1_l2_tree_size, tree_snapshots.l1_to_l2_message_tree.next_available_leaf_index },
368 { C::tx_prev_l2_gas_used, start_gas_used.l2_gas },
369 { C::tx_prev_da_gas_used, start_gas_used.da_gas },
370 { C::tx_l2_gas_limit, gas_limit.l2_gas },
371 { C::tx_da_gas_limit, gas_limit.da_gas },
372 { C::tx_prev_num_public_log_fields, 0 },
373 { C::tx_prev_num_l2_to_l1_messages, 0 },
375 { C::tx_sel_read_trees_and_gas_used, 1 },
379 { C::tx_gas_used_pi_offset, FF(AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX) },
380 { C::tx_gas_limit_pi_offset, FF(AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX) },
381 { C::tx_should_read_gas_limit, 1 },
382 { C::tx_next_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
383 { C::tx_next_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
384 { C::tx_next_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
385 { C::tx_next_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
386 { C::tx_next_public_data_tree_root, tree_snapshots.public_data_tree.root },
387 { C::tx_next_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
388 { C::tx_next_written_public_data_slots_tree_root, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT) },
389 { C::tx_next_written_public_data_slots_tree_size, FF(AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_SIZE) },
390 { C::tx_next_retrieved_bytecodes_tree_root, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_ROOT) },
391 { C::tx_next_retrieved_bytecodes_tree_size, FF(AVM_RETRIEVED_BYTECODES_TREE_INITIAL_SIZE) },
392 { C::tx_next_l2_gas_used, start_gas_used.l2_gas },
393 { C::tx_next_da_gas_used, start_gas_used.da_gas },
394 { C::tx_setup_phase_value, static_cast<uint8_t>(TransactionPhase::SETUP) },
395 { C::tx_next_context_id, 1 },
396 },
397 });
398
399 PublicInputsTraceBuilder public_inputs_builder;
400 public_inputs_builder.process_public_inputs(trace, public_inputs);
401 public_inputs_builder.process_public_inputs_aux_precomputed(trace);
402
403 PrecomputedTraceBuilder precomputed_builder;
405
406 check_relation<tx_context>(trace);
407 // All tx_context interactions
408 check_interaction<TxTraceBuilder,
420}
421
422TEST(TxContextConstrainingTest, EndStateChecks)
423{
424 Gas end_gas_used = { 1, 2 };
425 TreeSnapshots tree_snapshots = { .l1_to_l2_message_tree = { .root = 20, .next_available_leaf_index = 19 },
426 .note_hash_tree = { .root = 21, .next_available_leaf_index = 20 },
427 .nullifier_tree = { .root = 22, .next_available_leaf_index = 21 },
428 .public_data_tree = { .root = 23, .next_available_leaf_index = 22 } };
429 AvmAccumulatedDataArrayLengths array_lengths = { .note_hashes = 10, .nullifiers = 11, .l2_to_l1_msgs = 12 };
430
431 PublicLog log = {
432 .fields = { FF(4), FF(5) },
433 .contract_address = 11223,
434 };
435 PublicLogs public_logs = {};
436 public_logs.add_log(log);
437 AvmAccumulatedData accumulated_data = { .public_logs = public_logs };
438
439 auto public_inputs = PublicInputsBuilder()
440 .set_end_gas_used(end_gas_used)
441 .set_end_tree_snapshots(tree_snapshots)
442 .set_accumulated_data_array_lengths(array_lengths)
443 .set_accumulated_data(accumulated_data)
444 .build();
445
446 TestTraceContainer trace({
447 {
448 // Row 0
449 { C::precomputed_first_row, 1 },
450 },
451 {
452 // Row 1
453 { C::tx_sel, 1 },
454 { C::tx_is_cleanup, 1 },
455 { C::tx_prev_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
456 { C::tx_prev_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
457 { C::tx_prev_num_note_hashes_emitted, array_lengths.note_hashes },
458 { C::tx_prev_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
459 { C::tx_prev_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
460 { C::tx_prev_num_nullifiers_emitted, array_lengths.nullifiers },
461 { C::tx_prev_public_data_tree_root, tree_snapshots.public_data_tree.root },
462 { C::tx_prev_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
463 { C::tx_l1_l2_tree_root, tree_snapshots.l1_to_l2_message_tree.root },
464 { C::tx_l1_l2_tree_size, tree_snapshots.l1_to_l2_message_tree.next_available_leaf_index },
465 { C::tx_prev_l2_gas_used, end_gas_used.l2_gas },
466 { C::tx_prev_da_gas_used, end_gas_used.da_gas },
467 { C::tx_prev_num_public_log_fields, public_logs.length },
468 { C::tx_prev_num_l2_to_l1_messages, array_lengths.l2_to_l1_msgs },
470 { C::tx_sel_read_trees_and_gas_used, 1 },
474 { C::tx_gas_used_pi_offset, FF(AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX) },
475 { C::tx_reverted_pi_offset, AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX },
476 { C::tx_array_length_note_hashes_pi_offset,
478 { C::tx_array_length_nullifiers_pi_offset,
480 { C::tx_array_length_l2_to_l1_messages_pi_offset,
482 { C::tx_fields_length_public_logs_pi_offset,
484 { C::tx_next_note_hash_tree_root, tree_snapshots.note_hash_tree.root },
485 { C::tx_next_note_hash_tree_size, tree_snapshots.note_hash_tree.next_available_leaf_index },
486 { C::tx_next_num_note_hashes_emitted, array_lengths.note_hashes },
487 { C::tx_next_nullifier_tree_root, tree_snapshots.nullifier_tree.root },
488 { C::tx_next_nullifier_tree_size, tree_snapshots.nullifier_tree.next_available_leaf_index },
489 { C::tx_next_num_nullifiers_emitted, array_lengths.nullifiers },
490 { C::tx_next_public_data_tree_root, tree_snapshots.public_data_tree.root },
491 { C::tx_next_public_data_tree_size, tree_snapshots.public_data_tree.next_available_leaf_index },
492 { C::tx_next_l2_gas_used, end_gas_used.l2_gas },
493 { C::tx_next_da_gas_used, end_gas_used.da_gas },
494 { C::tx_next_num_public_log_fields, public_logs.length },
495 { C::tx_next_num_l2_to_l1_messages, array_lengths.l2_to_l1_msgs },
496 { C::tx_setup_phase_value, static_cast<uint8_t>(TransactionPhase::SETUP) },
497 },
498 });
499
500 PublicInputsTraceBuilder public_inputs_builder;
501 public_inputs_builder.process_public_inputs(trace, public_inputs);
502 public_inputs_builder.process_public_inputs_aux_precomputed(trace);
503
504 PrecomputedTraceBuilder precomputed_builder;
506
507 check_relation<tx_context>(trace);
508 // All tx_context interactions
509 check_interaction<TxTraceBuilder,
522}
523
524TEST(TxContextConstrainingTest, NegativeContextIdChecks)
525{
526 TestTraceContainer trace({
527 {
528 // Row 0
529 { C::precomputed_first_row, 1 },
530 },
531 {
532 // Row 1
533 { C::tx_sel, 1 },
534 { C::tx_start_tx, 1 },
535 { C::tx_next_context_id, 1 },
536 },
537 {
538 // Row 2
539 { C::tx_sel, 1 },
540 { C::tx_next_context_id, 1 },
541 { C::tx_should_process_call_request, 1 },
542 },
543 {
544 // Row 3
545 { C::tx_sel, 1 },
546 { C::tx_next_context_id, 5 },
547 },
548 });
549 check_relation<tx_context>(
551
552 // Negative test: initial context id should be 1
553 trace.set(C::tx_next_context_id, 1, 2);
555 "NEXT_CONTEXT_ID_INITIAL_VALUE");
556
557 // Negative test: continuity check
558 trace.set(C::tx_next_context_id, 2, 42);
560 "NEXT_CONTEXT_ID_CONTINUITY");
561}
562
563TEST(TxContextConstrainingTest, NegativeTxRevertedChecks)
564{
565 TestTraceContainer trace({
566 {
567 // Row 0
568 { C::precomputed_first_row, 1 },
569 },
570 {
571 // Row 1: no revert
572 { C::tx_sel, 1 },
573 { C::tx_start_tx, 1 },
574 },
575 {
576 // Row 2: revert
577 { C::tx_sel, 1 },
578 { C::tx_reverted, 1 },
579 { C::tx_tx_reverted, 1 },
580 },
581 {
582 // Row 3: no revert
583 { C::tx_sel, 1 },
584 { C::tx_tx_reverted, 1 },
585 },
586 });
587 check_relation<tx_context>(
589
590 // Negative test: initial tx_reverted should match reverted
591 trace.set(C::tx_tx_reverted, 1, 1);
592 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_INIT_TX_REVERTED), "INIT_TX_REVERTED");
593
594 // Negative test: continuity check
595 trace.set(C::tx_tx_reverted, 3, 0);
596 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_TX_REVERTED_CONTINUITY),
597 "TX_REVERTED_CONTINUITY");
598
599 // Negative test: tx_reverted should match reverted if reverted == 1
600 trace.set(C::tx_tx_reverted, 2, 0);
601 EXPECT_THROW_WITH_MESSAGE(check_relation<tx_context>(trace, tx_context::SR_SET_TX_REVERTED), "SET_TX_REVERTED");
602}
603
604} // namespace
605} // namespace bb::avm2::constraining
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
Definition assert.hpp:193
#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=PRECOMPUTED_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_PUBLIC_LOG_COUNT_PADDED_IMMUTABILITY
static constexpr size_t SR_NOTE_HASH_ROOT_PADDED_IMMUTABILITY
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_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_PUBLIC_LOG_COUNT_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_WRITTEN_PUBLIC_DATA_SLOTS_TREE_SIZE_CONTINUITY
static constexpr size_t SR_NUM_PUBLIC_LOGS_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
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
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
AvmFlavorSettings::FF FF
Definition field.hpp:10
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_public_inputs_write_public_log_count_settings_ > lookup_tx_context_public_inputs_write_public_log_count_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
tracegen::PublicInputsTraceBuilder public_inputs_builder
Definition tx.test.cpp:81