From 9df73e4c9e6e1718c440e865a0627ebd70c973d6 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 2 May 2024 18:20:31 +0000 Subject: [PATCH 1/5] bump gates buffer to account for gate estimation in goblin ultra honk --- barretenberg/acir_tests/run_acir_tests.sh | 2 +- barretenberg/cpp/src/barretenberg/bb/main.cpp | 30 +++++++++++++++++-- .../sumcheck/instance/prover_instance.hpp | 4 ++- .../barretenberg/ultra_honk/ultra_prover.cpp | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/barretenberg/acir_tests/run_acir_tests.sh b/barretenberg/acir_tests/run_acir_tests.sh index e75f8fb1a6b..88189a43438 100755 --- a/barretenberg/acir_tests/run_acir_tests.sh +++ b/barretenberg/acir_tests/run_acir_tests.sh @@ -35,7 +35,7 @@ export BIN CRS_PATH VERBOSE BRANCH cd acir_tests # Convert them to array -SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member witness_compression) +SKIP_ARRAY=(diamond_deps_0 workspace workspace_default_member) function test() { cd $1 diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index 8ff5c5ba338..f3819d0cb04 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -579,6 +579,27 @@ bool avm_verify(const std::filesystem::path& proof_path) return true; } +template size_t compute_dyadic_size(typename Flavor::CircuitBuilder& circuit) +{ + + // minimum circuit size due to lookup argument + const size_t min_size_due_to_lookups = circuit.get_tables_size() + circuit.get_lookups_size(); + + // minimum size of execution trace due to everything else + size_t min_size_of_execution_trace = circuit.public_inputs.size() + circuit.num_gates; + if constexpr (IsGoblinFlavor) { + min_size_of_execution_trace += circuit.blocks.ecc_op.size(); + } + + // The number of gates is the maximum required by the lookup argument or everything else, plus an optional zero row + // to allow for shifts. + size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; + size_t total_num_gates = num_zero_rows + std::max(min_size_due_to_lookups, min_size_of_execution_trace); + + // Next power of 2 (dyadic circuit size) + return circuit.get_circuit_subgroup_size(total_num_gates); +} + /** * @brief Creates a proof for an ACIR circuit * @@ -601,8 +622,11 @@ void prove_honk(const std::string& bytecodePath, const std::string& witnessPath, auto builder = acir_format::create_circuit(constraint_system, 0, witness); - const size_t additional_gates_buffer = 15; // conservatively large to be safe + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6161): Make the total circuit size estimation more + // accurate for GoblinUltraHonk so that we can remove this magic buffer + const size_t additional_gates_buffer = 30; // conservatively large to be safe size_t srs_size = builder.get_circuit_subgroup_size(builder.get_total_circuit_size() + additional_gates_buffer); + init_bn254_crs(srs_size); // Construct Honk proof @@ -672,7 +696,9 @@ template void write_vk_honk(const std::string& bytecodePa auto constraint_system = get_constraint_system(bytecodePath); auto builder = acir_format::create_circuit(constraint_system, 0, {}); - const size_t additional_gates_buffer = 15; // conservatively large to be safe + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6161): Make the total circuit size estimation more + // accurate for GoblinUltraHonk so that we can remove this magic buffer + const size_t additional_gates_buffer = 30; // conservatively large to be safe size_t srs_size = builder.get_circuit_subgroup_size(builder.get_total_circuit_size() + additional_gates_buffer); init_bn254_crs(srs_size); diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 48b5c8e4ff3..41cd16d1da4 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -37,6 +37,8 @@ template class ProverInstance_ { bool is_accumulator = false; + size_t dyadic_circuit_size = 0; // final power-of-2 circuit size + // The folding parameters (\vec{β}, e) which are set for accumulators (i.e. relaxed instances). std::vector gate_challenges; FF target_sum; @@ -46,6 +48,7 @@ template class ProverInstance_ { BB_OP_COUNT_TIME_NAME("ProverInstance(Circuit&)"); circuit.add_gates_to_ensure_all_polys_are_non_zero(); circuit.finalize_circuit(); + // If using a structured trace, ensure that no block exceeds the fixed size if (is_structured) { for (auto& block : circuit.blocks.get()) { @@ -99,7 +102,6 @@ template class ProverInstance_ { private: static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; static constexpr size_t NUM_WIRES = Circuit::NUM_WIRES; - size_t dyadic_circuit_size = 0; // final power-of-2 circuit size size_t compute_dyadic_size(Circuit&); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index 92166a00142..7030f194cb4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -77,6 +77,7 @@ template HonkProof& UltraProver_::construct_proof OinkProver oink_prover(instance->proving_key, transcript); auto [proving_key, relation_params, alphas] = oink_prover.prove(); instance->proving_key = std::move(proving_key); + instance->relation_parameters = std::move(relation_params); instance->alphas = alphas; From 8aaaf0c057b9f7a239ddb264a3cf9687fdd0321c Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 2 May 2024 18:22:50 +0000 Subject: [PATCH 2/5] remove dyadic size --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index f3819d0cb04..3f57d848caa 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -579,27 +579,6 @@ bool avm_verify(const std::filesystem::path& proof_path) return true; } -template size_t compute_dyadic_size(typename Flavor::CircuitBuilder& circuit) -{ - - // minimum circuit size due to lookup argument - const size_t min_size_due_to_lookups = circuit.get_tables_size() + circuit.get_lookups_size(); - - // minimum size of execution trace due to everything else - size_t min_size_of_execution_trace = circuit.public_inputs.size() + circuit.num_gates; - if constexpr (IsGoblinFlavor) { - min_size_of_execution_trace += circuit.blocks.ecc_op.size(); - } - - // The number of gates is the maximum required by the lookup argument or everything else, plus an optional zero row - // to allow for shifts. - size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; - size_t total_num_gates = num_zero_rows + std::max(min_size_due_to_lookups, min_size_of_execution_trace); - - // Next power of 2 (dyadic circuit size) - return circuit.get_circuit_subgroup_size(total_num_gates); -} - /** * @brief Creates a proof for an ACIR circuit * From fd339953ace02186c677f68106c51cb42cb76187 Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 2 May 2024 18:25:05 +0000 Subject: [PATCH 3/5] cleanup --- .../cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 41cd16d1da4..828c6de0c9e 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -37,8 +37,6 @@ template class ProverInstance_ { bool is_accumulator = false; - size_t dyadic_circuit_size = 0; // final power-of-2 circuit size - // The folding parameters (\vec{β}, e) which are set for accumulators (i.e. relaxed instances). std::vector gate_challenges; FF target_sum; From b1c112fb8b873f3d86ff135d71fb3d0edabf987b Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 2 May 2024 18:28:23 +0000 Subject: [PATCH 4/5] bring back removed field --- .../cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 828c6de0c9e..41cd16d1da4 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -37,6 +37,8 @@ template class ProverInstance_ { bool is_accumulator = false; + size_t dyadic_circuit_size = 0; // final power-of-2 circuit size + // The folding parameters (\vec{β}, e) which are set for accumulators (i.e. relaxed instances). std::vector gate_challenges; FF target_sum; From 546c99d10578df8e666f76afd3b75860b861dd0b Mon Sep 17 00:00:00 2001 From: vezenovm Date: Thu, 2 May 2024 18:28:55 +0000 Subject: [PATCH 5/5] move dyadic size back to private --- .../cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp index 41cd16d1da4..c30999fe761 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/prover_instance.hpp @@ -37,8 +37,6 @@ template class ProverInstance_ { bool is_accumulator = false; - size_t dyadic_circuit_size = 0; // final power-of-2 circuit size - // The folding parameters (\vec{β}, e) which are set for accumulators (i.e. relaxed instances). std::vector gate_challenges; FF target_sum; @@ -102,6 +100,7 @@ template class ProverInstance_ { private: static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; static constexpr size_t NUM_WIRES = Circuit::NUM_WIRES; + size_t dyadic_circuit_size = 0; // final power-of-2 circuit size size_t compute_dyadic_size(Circuit&);