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 .public_parameters = {},
36 .return_values = {},
37 };
38
40 "split_into_mul_quad_gates: resulted in zero gates.");
41}
42
43TYPED_TEST(AcirFormatTests, ExpressionWithCancellingCoefficientsFails)
44{
45 // Test that circuit construction fails if we have an expression where all linear terms cancel out. This is expected
46 // behavior as such an expression would result in a zero gate.
48 { bb::fr(-1).to_buffer(), Acir::Witness{ 0 } } },
49 .q_c = bb::fr::zero().to_buffer() };
50 Acir::Circuit circuit{
52 .public_parameters = {},
53 .return_values = {},
54 };
55
57 "acir_format::assert_zero_to_quad_constraints: produced an arithmetic zero gate.");
58}
59
61{
62 // Test that public inputs are handled correctly.
63 WitnessVector witnesses = { 2, 4, 6, 8, 10, 12 };
64
65 // 8 - 6 - 2 = 0
67 { bb::fr(-1).to_buffer(), Acir::Witness{ 2 } } },
68 .q_c = bb::fr(-2).to_buffer() };
69
70 Acir::Circuit circuit{
72 .public_parameters =
74 .return_values = Acir::PublicInputs{ .value = { Acir::Witness{ .value = 4 }, Acir::Witness{ .value = 5 } } },
75 };
76
78 BB_ASSERT_EQ(acir_format.public_inputs, std::vector<uint32_t>({ 0, 1, 4, 5 }));
79
80 AcirProgram program{ acir_format, witnesses };
81 auto builder = create_circuit<TypeParam>(program, {});
82
83 for (size_t idx = 0; idx < acir_format.public_inputs.size(); ++idx) {
84 uint32_t pub_input_idx = acir_format.public_inputs[idx];
85 EXPECT_EQ(pub_input_idx, builder.public_inputs()[idx]);
86 EXPECT_EQ(witnesses[pub_input_idx], builder.get_variable(pub_input_idx));
87 }
88}
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
Definition assert.hpp:193
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(CommitmentKeyTest, CommitToZeroPoly)
::testing::Types< UltraCircuitBuilder, MegaCircuitBuilder > BuilderTypes
std::vector< Acir::Opcode > opcodes
Definition acir.hpp:3498
std::vector< std::tuple< std::vector< uint8_t >, Acir::Witness > > linear_combinations
Definition acir.hpp:2796
std::vector< uint8_t > q_c
Definition acir.hpp:2797
Acir::Expression value
Definition acir.hpp:3047
std::vector< Acir::Witness > value
Definition acir.hpp:3480
uint32_t value
Definition acir.hpp:2020
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()