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_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);
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_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),
60}
61
62TEST(CtrlFlowConstrainingTest, JumpiFalseCondition)
63{
64 TestTraceContainer trace({
65 { { C::precomputed_first_row, 1 } },
66 { { C::execution_sel, 1 },
67 { C::execution_sel_execute_jumpi, 1 },
68 { C::execution_rop_1_, 120 },
69 { C::execution_next_pc, 220 },
70 { C::execution_register_0_, 0 } }, // False condition
71 { { C::execution_sel, 1 }, { C::execution_pc, 220 } },
72 });
73
74 check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI);
75
76 // Negative test: pc on next row is incorrect
77 trace.set(C::execution_pc, 2, 120);
78 EXPECT_THROW_WITH_MESSAGE(check_relation<execution>(trace, execution::SR_PC_NEXT_ROW_JUMPI),
80}
81
82} // namespace
83} // namespace bb::avm2::constraining
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
Definition assert.hpp:224
static constexpr size_t SR_PC_NEXT_ROW_INT_CALL_JUMP
Definition execution.hpp:55
static std::string get_subrelation_label(size_t index)
Definition execution.hpp:80
static constexpr size_t SR_PC_NEXT_ROW_JUMPI
Definition execution.hpp:56
void set(Column col, uint32_t row, const FF &value, bool use_atomic_limbs=false)
TestTraceContainer trace
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
NiceMock< MockExecution > execution