Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ctrl_flow.test.cpp
Go to the documentation of this file.
1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
3
4#include <cstdint>
5
12
13namespace bb::avm2::constraining {
14namespace {
15
16using tracegen::TestTraceContainer;
18using C = Column;
20using registers = bb::avm2::registers<FF>;
21
22TEST(CtrlFlowConstrainingTest, Jump)
23{
24 TestTraceContainer trace({
25 { { C::precomputed_first_row, 1 } },
26 {
27 { C::execution_sel, 1 },
28 { C::execution_sel_execute_jump, 1 },
29 { C::execution_rop_0_, 120 },
30 },
31 { { C::execution_sel, 1 }, { C::execution_last, 1 }, { C::execution_pc, 120 } },
32 });
33
34 check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_INT_CALL_JUMP);
35
36 // Negative test: pc on next row is incorrect
37 trace.set(C::execution_pc, 2, 121);
39 "PC_NEXT_ROW_INT_CALL_JUMP");
40}
41
42TEST(CtrlFlowConstrainingTest, JumpiTrueCondition)
43{
44 TestTraceContainer trace({
45 { { C::precomputed_first_row, 1 } },
46 { { C::execution_sel, 1 },
47 { C::execution_sel_execute_jumpi, 1 },
48 { C::execution_rop_1_, 120 },
49 { C::execution_next_pc, 220 },
50 { C::execution_register_0_, 1 } }, // True condition
51 { { C::execution_sel, 1 }, { C::execution_last, 1 }, { C::execution_pc, 120 } },
52 });
53
54 check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI);
55
56 // Negative test: pc on next row is incorrect
57 trace.set(C::execution_pc, 2, 220);
58 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI), "PC_NEXT_ROW_JUMPI");
59}
60
61TEST(CtrlFlowConstrainingTest, JumpiFalseCondition)
62{
63 TestTraceContainer trace({
64 { { C::precomputed_first_row, 1 } },
65 { { C::execution_sel, 1 },
66 { C::execution_sel_execute_jumpi, 1 },
67 { C::execution_rop_1_, 120 },
68 { C::execution_next_pc, 220 },
69 { C::execution_register_0_, 0 } }, // False condition
70 { { C::execution_sel, 1 }, { C::execution_last, 1 }, { C::execution_pc, 220 } },
71 });
72
73 check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI);
74
75 // Negative test: pc on next row is incorrect
76 trace.set(C::execution_pc, 2, 120);
77 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI), "PC_NEXT_ROW_JUMPI");
78}
79
80} // namespace
81} // namespace bb::avm2::constraining
static constexpr size_t SR_PC_NEXT_ROW_INT_CALL_JUMP
static constexpr size_t SR_PC_NEXT_ROW_JUMPI
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
NiceMock< MockExecution > execution