Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add goblin ops in add_gates_to_ensure_all_polys_are_non_zero #5468

Merged
merged 9 commits into from
Mar 27, 2024
10 changes: 8 additions & 2 deletions barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ class ClientIVCTests : public ::testing::Test {

/**
* @brief Construct mock circuit with arithmetic gates and goblin ops
* @details Currently default sized to 2^16 to match kernel. (Note: op gates will bump size to next power of
2)
* @details Currently default sized to 2^16 to match kernel. (Note: dummy op gates added to avoid non-zero
* polynomials will bump size to next power of 2)
*
*/
static Builder create_mock_circuit(ClientIVC& ivc, size_t log2_num_gates = 15)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments on this function may be a bit confusing/misleading - maybe we can change to say something like "default gates added to avoid nonzero polynomials will bump size to next power of 2"

Builder circuit{ ivc.goblin.op_queue };
MockCircuits::construct_arithmetic_circuit(circuit, log2_num_gates);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/911): We require goblin ops to be added to the
// function circuit because we cannot support zero commtiments. While the builder handles this at
// finalisation stage via the add_gates_to_ensure_all_polys_are_non_zero function for other UGH
// circuits (where we don't explicitly need to add goblin ops), in ClientIVC merge proving happens prior to
// folding where the absense of goblin ecc ops will result in zero commitments.
MockCircuits::construct_goblin_ecc_op_circuit(circuit);
return circuit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,6 @@ GoblinUltraCircuitBuilder create_circuit(const AcirFormat& constraint_system,
bool has_valid_witness_assignments = !witness.empty();
acir_format::build_constraints(builder, constraint_system, has_valid_witness_assignments);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the
// associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process.
MockCircuits::construct_goblin_ecc_op_circuit(builder);

return builder;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void GoblinAcirComposer::create_circuit(acir_format::AcirFormat& constraint_syst
acir_format::build_constraints(builder_, constraint_system, true);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its debatable whether we should remove the ops here. In the case of UGH, removing them is fine since eventually we'd like a world where we dont NEED goblin ops to make a valid proof. This one, however, is a Goblin specific test so it would defeat the purpose of the test to not have any ops. So when/if we get rid of the add_gates_to_ensure.., this test would be quietly made useless. I think we should continue to explicitly add ops here in one way or another, with a comment explaining why, so someone who thinks they're clever doesn't go and remove them later. What do you think?

// TODO(https://github.com/AztecProtocol/barretenberg/issues/817): Add some arbitrary op gates to ensure the
// associated polynomials are non-zero and to give ECCVM and Translator some ECC ops to process.
// to give ECCVM and Translator some ECC ops to process.
MockCircuits::construct_goblin_ecc_op_circuit(builder_);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ TEST_F(GoblinRecursionTests, Vanilla)
size_t NUM_CIRCUITS = 2;
for (size_t circuit_idx = 0; circuit_idx < NUM_CIRCUITS; ++circuit_idx) {

// Construct and accumulate a mock function circuit
// Construct and accumulate a mock function circuit containing both arbitrary arithmetic gates and goblin
// ecc op gates to make it a meaningful test
GoblinUltraCircuitBuilder function_circuit{ goblin.op_queue };
MockCircuits::construct_arithmetic_circuit(function_circuit, /*target_log2_dyadic_size=*/8);
MockCircuits::construct_goblin_ecc_op_circuit(function_circuit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Expand Down
8 changes: 5 additions & 3 deletions barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ class GoblinMockCircuits {
stdlib::generate_ecdsa_verification_test_circuit(builder, NUM_ITERATIONS); // min gates: ~41k
stdlib::generate_merkle_membership_test_circuit(builder, NUM_ITERATIONS); // min gates: ~29k

// Note: its not clear whether goblin ops will be supported for function circuits initially but currently
// UGH can only be used if some op gates are included so for now we'll assume each function circuit has
// some.
// TODO(https://github.com/AztecProtocol/barretenberg/issues/911): We require goblin ops to be added to the
// function circuit because we cannot support zero commtiments. While the builder handles this at
// ProverInstance creation stage via the add_gates_to_ensure_all_polys_are_non_zero function for other UGH
// circuits (where we don't explicitly need to add goblin ops), in ClientIVC merge proving happens prior to
// folding where the absense of goblin ecc ops will result in zero commitments.
MockCircuits::construct_goblin_ecc_op_circuit(builder);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ template <typename FF> void GoblinUltraCircuitBuilder_<FF>::add_gates_to_ensure_
// dummy gate to be read into by previous poseidon internal gate via shifts
this->create_dummy_gate(
this->blocks.poseidon_internal, this->zero_idx, this->zero_idx, this->zero_idx, this->zero_idx);

// add dummy mul accum op and an equality op
this->queue_ecc_mul_accum(bb::g1::affine_element::one() * FF::random_element(), FF::random_element());
maramihali marked this conversation as resolved.
Show resolved Hide resolved
this->queue_ecc_eq();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,15 @@ class MockCircuits {
}

/**
* @brief Populate a builder with some arbitrary goblinized ECC ops
* @brief Populate a builder with some arbitrary goblinized ECC ops, one of each type
*
* @param builder
*/
static void construct_goblin_ecc_op_circuit(GoblinUltraCircuitBuilder& builder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should keep this function but expand it to include at least one of each type of op (mul, add, eq) and use this in the Goblin-specific places I mentioned to continue to ensure we're getting robust testing that's not implicitly tied to the _add_gates_to_ensure functionality.

{
// Add a mul accum op and an equality op
auto point = Point::one() * FF::random_element();
auto scalar = FF::random_element();
builder.queue_ecc_mul_accum(point, scalar);
// Add a mul accum op, an add accum op and an equality op
builder.queue_ecc_add_accum(Point::one() * FF::random_element());
builder.queue_ecc_mul_accum(Point::one() * FF::random_element(), FF::random_element());
builder.queue_ecc_eq();
}
};
Expand Down
Loading