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 } });
104
105 check_relation<internal_call>(trace);
106
107 check_interaction<ExecutionTraceBuilder,
110}
111
112TEST(InternalCallStackConstrainingTest, ReturnError)
113{
114 TestTraceContainer trace({ {
115 { C::execution_next_context_id, 0 },
116 { C::precomputed_first_row, 1 },
117 },
118 // First Row of execution
119 {
120 { C::execution_sel, 1 },
121 { C::execution_pc, 0 },
122 { C::execution_enqueued_call_start, 1 },
123 { C::execution_next_pc, 10 },
124 // Internal Call Cols
125 { C::execution_next_internal_call_id, 2 },
126 { C::execution_internal_call_id, 1 },
127 { C::execution_internal_call_return_id, 0 },
128 },
129 // Internal Return with error
130 {
131 { C::execution_sel, 1 },
132 { C::execution_pc, 10 },
133 { C::execution_sel_execute_internal_return, 1 },
134 // Internal Call Cols
135 { C::execution_next_internal_call_id, 2 },
136 { C::execution_internal_call_id, 1 },
137 { C::execution_internal_call_return_id, 0 },
138 // Error flags
139 { C::execution_internal_call_return_id_inv, 0 }, // Cannot invert return_id = 0
140 { C::execution_sel_opcode_error, 1 }, // Error flag
141 },
142 // Last Row
143 {
144 { C::execution_sel, 0 },
145 } });
146
147 check_relation<internal_call>(trace);
148}
149
150} // namespace
151} // namespace bb::avm2::constraining
TestTraceContainer trace
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
Definition tx.test.cpp:441
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