Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
internal_call.test.cpp
Go to the documentation of this file.
1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
3
4#include <cstdint>
5
16
17namespace bb::avm2::constraining {
18namespace {
19
20using tracegen::ExecutionTraceBuilder;
21using tracegen::TestTraceContainer;
23using C = Column;
24using internal_call = bb::avm2::internal_call<FF>;
25
26TEST(InternalCallStackConstrainingTest, EmptyRow)
27{
28 check_relation<internal_call>(testing::empty_trace());
29}
30
31// This test currently does a lot, consider splitting up the various exit call conditions
32TEST(InternalCallStackConstrainingTest, SimpleInternalCallReturn)
33{
34 TestTraceContainer trace({ {
35 { C::execution_next_context_id, 0 },
36 { C::precomputed_first_row, 1 },
37 // Internal Call Stack Cols
38 { C::internal_call_stack_sel, 1 },
39 { C::internal_call_stack_entered_call_id, 2 },
40 { C::internal_call_stack_id, 1 },
41 { C::internal_call_stack_return_id, 0 },
42 { C::internal_call_stack_return_pc, 10 },
43 },
44 // First Row of execution (Internal Call)
45 {
46 { C::execution_sel, 1 },
47 { C::execution_pc, 0 },
48 { C::execution_enqueued_call_start, 1 },
49 { C::execution_next_pc, 10 },
50 { C::execution_sel_execute_internal_call, 1 },
51 // Operands
52 { C::execution_rop_0_, /*loc=*/12345 },
53 // Internal Call Cols
54 { C::execution_next_internal_call_id, 2 },
55 { C::execution_internal_call_id, 1 },
56 { C::execution_internal_call_return_id, 0 },
57 },
58 // Separator row to test propagation
59 {
60 { C::execution_sel, 1 },
61 { C::execution_pc, 12345 },
62 { C::execution_next_pc, 100000 },
63 // Internal Call Cols
64 { C::execution_next_internal_call_id, 3 },
65 { C::execution_internal_call_id, 2 },
66 { C::execution_internal_call_return_id, 1 },
67 },
68 // Internal Return
69 {
70 { C::execution_sel, 1 },
71 { C::execution_pc, 100000 },
72 { C::execution_sel_execute_internal_return, 1 },
73 // Internal Call Cols
74 { C::execution_next_internal_call_id, 3 },
75 { C::execution_internal_call_id, 2 },
76 { C::execution_internal_call_return_id, 1 },
77 // Error flags (no error)
78 { C::execution_internal_call_return_id_inv, 1 }, // FF(1).invert()
79 },
80 // Restored Row
81 {
82 { C::execution_sel, 1 },
83 { C::execution_pc, 10 },
84 { C::execution_next_pc, 20 },
85 // Internal Call Cols
86 { C::execution_next_internal_call_id, 3 },
87 { C::execution_internal_call_id, 1 },
88 { C::execution_internal_call_return_id, 0 },
89 },
90 // Separator Row to test propagation
91 {
92 { C::execution_sel, 1 },
93 { C::execution_pc, 20 },
94 { C::execution_enqueued_call_end, 1 },
95 // Internal Call Cols
96 { C::execution_next_internal_call_id, 3 },
97 { C::execution_internal_call_id, 1 },
98 { C::execution_internal_call_return_id, 0 },
99 },
100 // Last Row
101 {
102 { C::execution_sel, 0 },
103 { C::execution_last, 1 },
104 } });
105
106 check_relation<internal_call>(trace);
107
108 check_interaction<ExecutionTraceBuilder,
111}
112
113TEST(InternalCallStackConstrainingTest, ReturnError)
114{
115 TestTraceContainer trace({ {
116 { C::execution_next_context_id, 0 },
117 { C::precomputed_first_row, 1 },
118 },
119 // First Row of execution
120 {
121 { C::execution_sel, 1 },
122 { C::execution_pc, 0 },
123 { C::execution_enqueued_call_start, 1 },
124 { C::execution_next_pc, 10 },
125 // Internal Call Cols
126 { C::execution_next_internal_call_id, 2 },
127 { C::execution_internal_call_id, 1 },
128 { C::execution_internal_call_return_id, 0 },
129 },
130 // Internal Return with error
131 {
132 { C::execution_sel, 1 },
133 { C::execution_pc, 10 },
134 { C::execution_sel_execute_internal_return, 1 },
135 // Internal Call Cols
136 { C::execution_next_internal_call_id, 2 },
137 { C::execution_internal_call_id, 1 },
138 { C::execution_internal_call_return_id, 0 },
139 // Error flags
140 { C::execution_internal_call_return_id_inv, 0 }, // Cannot invert return_id = 0
141 { C::execution_sel_opcode_error, 1 }, // Error flag
142 },
143 // Last Row
144 {
145 { C::execution_sel, 0 },
146 { C::execution_last, 1 },
147 } });
148
149 check_relation<internal_call>(trace);
150}
151
152} // namespace
153} // namespace bb::avm2::constraining
TestTraceContainer trace
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
Definition tx.test.cpp:508
TestTraceContainer empty_trace()
Definition fixtures.cpp:153
lookup_settings< lookup_internal_call_push_call_stack_settings_ > lookup_internal_call_push_call_stack_settings
lookup_settings< lookup_internal_call_unwind_call_stack_settings_ > lookup_internal_call_unwind_call_stack_settings
typename Flavor::FF FF