Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
acir_format.test.cpp
Go to the documentation of this file.
1#include <gtest/gtest.h>
2#include <memory>
3#include <vector>
4
5#include "acir_format.hpp"
10
12
13using namespace bb;
14using namespace bb::crypto;
15using namespace acir_format;
16
17template <typename Builder> class AcirFormatTests : public ::testing::Test {
18 protected:
20};
21
22using BuilderTypes = testing::Types<UltraCircuitBuilder, MegaCircuitBuilder>;
24
25TYPED_TEST(AcirFormatTests, ExpressionWithOnlyConstantTermFails)
26{
27 // Test that circuit construction fails if we have an expression with only a constant term. This is expected
28 // behavior: an expression with only a constant term represent either:
29 // 1) an unsatisfied constraint if the constant term is non-zero
30 // 2) a zero constraint if the constant term is zero
31 // In both cases, we should not construct a circuit as either the circuit is not satisfiable, or there is zero gate.
33 Acir::Circuit circuit{
35 .opcodes = { Acir::Opcode{ Acir::Opcode::AssertZero{ .value = expr } } },
36 .public_parameters = {},
37 .return_values = {},
38 };
39
41 "split_into_mul_quad_gates: resulted in zero gates.");
42}
43
44TYPED_TEST(AcirFormatTests, ExpressionWithCancellingCoefficientsFails)
45{
46 // Test that circuit construction fails if we have an expression where all linear terms cancel out. This is expected
47 // behavior as such an expression would result in a zero gate.
49 { bb::fr(-1).to_buffer(), Acir::Witness{ 0 } } },
50 .q_c = bb::fr::zero().to_buffer() };
51 Acir::Circuit circuit{
53 .opcodes = { Acir::Opcode{ Acir::Opcode::AssertZero{ .value = expr } } },
54 .public_parameters = {},
55 .return_values = {},
56 };
57
59 "acir_format::assert_zero_to_quad_constraints: produced an arithmetic zero gate.");
60}
61
63{
64 // Test that public inputs are handled correctly.
65 WitnessVector witnesses = { 2, 4, 6, 8, 10, 12 };
66
67 // 8 - 6 - 2 = 0
69 { bb::fr(-1).to_buffer(), Acir::Witness{ 2 } } },
70 .q_c = bb::fr(-2).to_buffer() };
71
72 Acir::Circuit circuit{
73 .current_witness_index = static_cast<uint32_t>(witnesses.size() - 1),
74 .opcodes = { Acir::Opcode{ Acir::Opcode::AssertZero{ .value = expr } } },
75 .public_parameters =
77 .return_values = Acir::PublicInputs{ .value = { Acir::Witness{ .value = 4 }, Acir::Witness{ .value = 5 } } },
78 };
79
81 BB_ASSERT_EQ(acir_format.public_inputs, std::vector<uint32_t>({ 0, 1, 4, 5 }));
82
83 AcirProgram program{ acir_format, witnesses };
84 auto builder = create_circuit<TypeParam>(program, {});
85
86 for (size_t idx = 0; idx < acir_format.public_inputs.size(); ++idx) {
87 uint32_t pub_input_idx = acir_format.public_inputs[idx];
88 EXPECT_EQ(pub_input_idx, builder.public_inputs()[idx]);
89 EXPECT_EQ(witnesses[pub_input_idx], builder.get_variable(pub_input_idx));
90 }
91}
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:93
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
Definition assert.hpp:192
static void SetUpTestSuite()
AluTraceBuilder builder
Definition alu.test.cpp:124
AcirFormat circuit_serde_to_acir_format(Acir::Circuit const &circuit)
Convert an Acir::Circuit into an AcirFormat by processing all the opcodes.
std::vector< bb::fr > WitnessVector
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TYPED_TEST_SUITE(BoomerangRecursiveVerifierTest, Flavors)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
field< Bn254FrParams > fr
Definition fr.hpp:174
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
::testing::Types< UltraCircuitBuilder, MegaCircuitBuilder > BuilderTypes
uint32_t current_witness_index
Definition acir.hpp:5004
std::vector< std::tuple< std::vector< uint8_t >, Acir::Witness > > linear_combinations
Definition acir.hpp:4000
std::vector< uint8_t > q_c
Definition acir.hpp:4001
Acir::Expression value
Definition acir.hpp:4359
std::vector< Acir::Witness > value
Definition acir.hpp:4983
uint32_t value
Definition acir.hpp:2901
Barretenberg's representation of ACIR constraints.
Struct containing both the constraints to be added to the circuit and the witness vector.
static constexpr field one()
BB_INLINE std::vector< uint8_t > to_buffer() const
static constexpr field zero()