1#include <gtest/gtest.h>
40using BuilderTypes = testing::Types<UltraCircuitBuilder, MegaCircuitBuilder>;
48 EXPECT_EQ(
builder.num_gates(), EXPECTED_RESULT);
70 .num_acir_opcodes = 2,
72 .quad_constraints = { quad, quad },
78 auto builder = create_circuit<TypeParam>(program, metadata);
81 EXPECT_EQ(program.constraints.gates_per_opcode,
82 std::vector<size_t>({ QUAD<TypeParam>, QUAD<TypeParam> - ZERO_GATE - MEGA_OFFSET<TypeParam> }));
99 .num_acir_opcodes = 1,
101 .logic_constraints = { logic_constraint },
107 auto builder = create_circuit<TypeParam>(program, metadata);
111 EXPECT_FALSE(
builder.failed());
113 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ LOGIC_XOR_32<TypeParam> }));
123 .is_xor_gate =
false,
130 .num_acir_opcodes = 1,
132 .logic_constraints = { logic_constraint },
138 auto builder = create_circuit<TypeParam>(program, metadata);
142 EXPECT_FALSE(
builder.failed());
144 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ LOGIC_AND_32<TypeParam> }));
158 .num_acir_opcodes = 1,
160 .range_constraints = { range_constraint },
166 auto builder = create_circuit<TypeParam>(program, metadata);
168 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ RANGE_32<TypeParam> }));
175 for (
size_t idx = 0; idx < 25; idx++) {
177 keccak_permutation.
result[idx] =
static_cast<uint32_t
>(idx) + 25;
186 for (
const auto& state : expected_state) {
187 witness.emplace_back(state);
192 .num_acir_opcodes = 1,
194 .keccak_permutations = { keccak_permutation },
200 auto builder = create_circuit<TypeParam>(program, metadata);
203 EXPECT_FALSE(
builder.failed());
205 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ KECCAK_PERMUTATION<TypeParam> }));
212 for (
size_t idx = 0; idx < 4; idx++) {
214 poseidon2_constraint.
result.emplace_back(
static_cast<uint32_t
>(idx) + 5);
221 .num_acir_opcodes = 1,
223 .poseidon2_constraints = { poseidon2_constraint },
229 auto builder = create_circuit<TypeParam>(program, metadata);
231 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ POSEIDON2_PERMUTATION<TypeParam> }));
238 for (
size_t i = 0; i < 16; ++i) {
241 for (
size_t i = 0; i < 8; ++i) {
244 for (
size_t i = 0; i < 8; ++i) {
245 sha256_compression.
result[i] =
static_cast<uint32_t
>(i) + 24;
252 .num_acir_opcodes = 1,
254 .sha256_compression = { sha256_compression },
260 auto builder = create_circuit<TypeParam>(program, metadata);
262 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ SHA256_COMPRESSION<TypeParam> }));
270 for (
size_t i = 0; i < 16; ++i) {
274 for (
size_t i = 0; i < 16; ++i) {
278 for (
size_t i = 0; i < 16; ++i) {
282 for (
size_t i = 0; i < 16; ++i) {
283 aes128_constraint.
outputs.push_back(
static_cast<uint32_t
>(i + 48));
290 .num_acir_opcodes = 1,
292 .aes128_constraints = { aes128_constraint },
298 auto builder = create_circuit<TypeParam>(program, metadata);
300 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ AES128_ENCRYPTION<TypeParam> }));
306 for (
size_t i = 0; i < 32; ++i) {
307 ecdsa_constraint.hashed_message[i] =
static_cast<uint32_t
>(i);
310 for (
size_t i = 0; i < 64; ++i) {
311 ecdsa_constraint.signature[i] =
static_cast<uint32_t
>(i + 32);
314 for (
size_t i = 0; i < 32; ++i) {
315 ecdsa_constraint.pub_x_indices[i] =
static_cast<uint32_t
>(i + 96);
318 for (
size_t i = 0; i < 32; ++i) {
319 ecdsa_constraint.pub_y_indices[i] =
static_cast<uint32_t
>(i + 128);
323 ecdsa_constraint.result =
static_cast<uint32_t
>(161);
327 auto point = bb::curve::SECP256K1::AffineElement::one();
328 auto x_buffer = point.x.to_buffer();
329 auto y_buffer = point.y.to_buffer();
330 for (
size_t idx = 0; idx < 32; idx++) {
331 witness[idx + 96] = x_buffer[idx];
332 witness[idx + 128] = y_buffer[idx];
337 .num_acir_opcodes = 1,
339 .ecdsa_k1_constraints = { ecdsa_constraint },
345 auto builder = create_circuit<TypeParam>(program, metadata);
347 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ ECDSA_SECP256K1<TypeParam> }));
353 for (
size_t i = 0; i < 32; ++i) {
354 ecdsa_constraint.hashed_message[i] =
static_cast<uint32_t
>(i);
357 for (
size_t i = 0; i < 64; ++i) {
358 ecdsa_constraint.signature[i] =
static_cast<uint32_t
>(i + 32);
361 for (
size_t i = 0; i < 32; ++i) {
362 ecdsa_constraint.pub_x_indices[i] =
static_cast<uint32_t
>(i + 96);
365 for (
size_t i = 0; i < 32; ++i) {
366 ecdsa_constraint.pub_y_indices[i] =
static_cast<uint32_t
>(i + 128);
370 ecdsa_constraint.result =
static_cast<uint32_t
>(161);
374 auto point = bb::curve::SECP256K1::AffineElement::one();
375 auto x_buffer = point.x.to_buffer();
376 auto y_buffer = point.y.to_buffer();
377 for (
size_t idx = 0; idx < 32; idx++) {
378 witness[idx + 96] = x_buffer[idx];
379 witness[idx + 128] = y_buffer[idx];
384 .num_acir_opcodes = 1,
386 .ecdsa_r1_constraints = { ecdsa_constraint },
392 auto builder = create_circuit<TypeParam>(program, metadata);
394 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ ECDSA_SECP256R1<TypeParam> }));
403 for (
size_t i = 0; i < 32; ++i) {
404 blake2s_constraint.
result[i] =
static_cast<uint32_t
>(i + 1);
411 .num_acir_opcodes = 1,
413 .blake2s_constraints = { blake2s_constraint },
419 auto builder = create_circuit<TypeParam>(program, metadata);
421 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLAKE2S<TypeParam> }));
430 for (
size_t i = 0; i < 32; ++i) {
431 blake3_constraint.
result[i] =
static_cast<uint32_t
>(i + 1);
438 .num_acir_opcodes = 1,
440 .blake3_constraints = { blake3_constraint },
446 auto builder = create_circuit<TypeParam>(program, metadata);
448 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLAKE3<TypeParam> }));
456 auto point = GrumpkinPoint::one();
476 witness[0] = point.x;
477 witness[1] = point.y;
479 witness[6] = point.x;
480 witness[7] = point.y;
485 .num_acir_opcodes = 1,
487 .multi_scalar_mul_constraints = { msm_constraint },
493 auto builder = create_circuit<TypeParam>(program, metadata);
495 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ MULTI_SCALAR_MUL<TypeParam> }));
503 auto point1 = GrumpkinPoint::one();
504 auto point2 = GrumpkinPoint::one();
506 EcAdd ec_add_constraint{
516 .result_infinite = 9,
521 witness[0] = point1.x;
522 witness[1] = point1.y;
525 witness[3] = point2.x;
526 witness[4] = point2.y;
529 witness[7] = point1.x;
530 witness[8] = point1.y;
535 .num_acir_opcodes = 1,
537 .ec_add_constraints = { ec_add_constraint },
543 auto builder = create_circuit<TypeParam>(program, metadata);
545 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ EC_ADD<TypeParam> }));
553 std::vector<uint32_t>
init;
567 .type = BlockType::ROM,
568 .calldata_id = CallDataType::None,
573 .num_acir_opcodes = 1,
576 .block_constraints = { block_constraint },
582 auto builder = create_circuit<TypeParam>(program, metadata);
584 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLOCK_ROM_READ<TypeParam> }));
592 std::vector<uint32_t>
init;
606 .type = BlockType::RAM,
607 .calldata_id = CallDataType::None,
612 .num_acir_opcodes = 1,
615 .block_constraints = { block_constraint },
621 auto builder = create_circuit<TypeParam>(program, metadata);
629 std::vector<uint32_t>
init;
643 .type = BlockType::RAM,
644 .calldata_id = CallDataType::None,
649 .num_acir_opcodes = 1,
652 .block_constraints = { block_constraint },
658 auto builder = create_circuit<TypeParam>(program, metadata);
660 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLOCK_RAM_WRITE<TypeParam> }));
666 GTEST_SKIP() <<
"CallData only supported on MegaCircuitBuilder";
672 std::vector<uint32_t>
init;
688 .type = BlockType::CallData,
689 .calldata_id = CallDataType::Primary,
694 .num_acir_opcodes = 1,
697 .block_constraints = { block_constraint },
703 auto builder = create_circuit<TypeParam>(program, metadata);
705 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLOCK_CALLDATA<TypeParam> }));
713 .type = BlockType::CallData,
714 .calldata_id = CallDataType::Secondary,
719 .num_acir_opcodes = 1,
722 .block_constraints = { block_constraint },
728 auto builder = create_circuit<TypeParam>(program, metadata);
730 EXPECT_EQ(program.constraints.gates_per_opcode, std::vector<size_t>({ BLOCK_CALLDATA<TypeParam> }));
737 GTEST_SKIP() <<
"ReturnData only supported on MegaCircuitBuilder";
743 std::vector<uint32_t>
init;
750 .type = BlockType::ReturnData,
751 .calldata_id = CallDataType::None,
756 .num_acir_opcodes = 1,
759 .block_constraints = { block_constraint },
768 auto builder = create_circuit<TypeParam>(program, metadata);
770 EXPECT_EQ(
builder.get_num_finalized_gates_inefficient(
false), BLOCK_RETURNDATA<TypeParam>);
static void SetUpTestSuite()
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Applies the Poseidon2 permutation function from https://eprint.iacr.org/2023/323.
group_elements::affine_element< Fq, Fr, Params > affine_element
void ethash_keccakf1600(uint64_t state[KECCAKF1600_LANES]) NOEXCEPT
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.
field< Bn254FrParams > fr
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
::testing::Types< UltraCircuitBuilder, MegaCircuitBuilder > BuilderTypes
static constexpr field neg_one()
static constexpr field one()