Skip to content

Commit

Permalink
Fix ensure count
Browse files Browse the repository at this point in the history
  • Loading branch information
codygunton committed Sep 11, 2024
1 parent 6998193 commit 0193003
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ template <typename FF> void MegaCircuitBuilder_<FF>::finalize_circuit(const bool
if (ensure_nonzero && !this->circuit_finalized) {
// do the mega part of ensuring all polynomials are nonzero; ultra part will be done inside of
// Ultra::finalize_circuit
add_gates_to_ensure_all_polys_are_non_zero();
add_mega_gates_to_ensure_all_polys_are_non_zero();
}
// All of the gates involved in finalization are part of the Ultra arithmetization
UltraCircuitBuilder_<MegaArith<FF>>::finalize_circuit(ensure_nonzero);
Expand All @@ -31,7 +31,7 @@ template <typename FF> void MegaCircuitBuilder_<FF>::finalize_circuit(const bool
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1066): This function adds valid (but arbitrary) gates to
// ensure that the circuit which includes them will not result in any zero-polynomials. It also ensures that the first
// coefficient of the wire polynomials is zero, which is required for them to be shiftable.
template <typename FF> void MegaCircuitBuilder_<FF>::add_gates_to_ensure_all_polys_are_non_zero()
template <typename FF> void MegaCircuitBuilder_<FF>::add_mega_gates_to_ensure_all_polys_are_non_zero()
{
// All that remains is to handle databus related and poseidon2 related polynomials. In what follows we populate the
// calldata with some mock data then constuct a single calldata read gate
Expand Down Expand Up @@ -64,6 +64,23 @@ template <typename FF> void MegaCircuitBuilder_<FF>::add_gates_to_ensure_all_pol
this->queue_ecc_eq();
}

/**
* @brief Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial.
* This only adds gates for the Goblin polynomials. Most polynomials are handled via the Ultra method,
* which should be done by a separate call to the Ultra builder's non zero polynomial gates method.
*
* @param in Structure containing variables and witness selectors
*/
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1066): This function adds valid (but arbitrary) gates to
// ensure that the circuit which includes them will not result in any zero-polynomials. It also ensures that the first
// coefficient of the wire polynomials is zero, which is required for them to be shiftable.
template <typename FF> void MegaCircuitBuilder_<FF>::add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero()
{
// Most polynomials are handled via the conventional Ultra method
UltraCircuitBuilder_<MegaArith<FF>>::add_gates_to_ensure_all_polys_are_non_zero();
add_mega_gates_to_ensure_all_polys_are_non_zero();
}

/**
* @brief Add simple point addition operation to the op queue and add corresponding gates
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M
}

void finalize_circuit(const bool ensure_nonzero = false);
void add_gates_to_ensure_all_polys_are_non_zero();
void add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero();
void add_mega_gates_to_ensure_all_polys_are_non_zero();

size_t get_num_constant_gates() const override { return 0; }

Expand Down Expand Up @@ -141,7 +142,7 @@ template <typename FF> class MegaCircuitBuilder_ : public UltraCircuitBuilder_<M
MegaCircuitBuilder_<FF> builder; // instantiate new builder

size_t num_gates_prior = builder.get_num_gates();
builder.add_gates_to_ensure_all_polys_are_non_zero();
builder.add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero();
size_t num_gates_post = builder.get_num_gates(); // accounts for finalization gates

return num_gates_post - num_gates_prior;
Expand Down

0 comments on commit 0193003

Please sign in to comment.