|
| 1 | + |
| 2 | +#include <benchmark/benchmark.h> |
| 3 | + |
| 4 | +#include "barretenberg/benchmark/ultra_bench/mock_proofs.hpp" |
| 5 | +#include "barretenberg/client_ivc/client_ivc.hpp" |
| 6 | +#include "barretenberg/common/op_count_google_bench.hpp" |
| 7 | +#include "barretenberg/goblin/goblin.hpp" |
| 8 | +#include "barretenberg/goblin/mock_circuits.hpp" |
| 9 | +#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" |
| 10 | +#include "barretenberg/ultra_honk/ultra_composer.hpp" |
| 11 | + |
| 12 | +using namespace benchmark; |
| 13 | +using namespace bb; |
| 14 | + |
| 15 | +namespace { |
| 16 | + |
| 17 | +/** |
| 18 | + * @brief Benchmark suite for the aztec client PG-Goblin IVC scheme |
| 19 | + * |
| 20 | + */ |
| 21 | +class IvcBench : public benchmark::Fixture { |
| 22 | + public: |
| 23 | + using Builder = GoblinUltraCircuitBuilder; |
| 24 | + |
| 25 | + // Number of function circuits to accumulate(based on Zacs target numbers) |
| 26 | + static constexpr size_t NUM_ITERATIONS_MEDIUM_COMPLEXITY = 6; |
| 27 | + |
| 28 | + void SetUp([[maybe_unused]] const ::benchmark::State& state) override |
| 29 | + { |
| 30 | + bb::srs::init_crs_factory("../srs_db/ignition"); |
| 31 | + bb::srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @brief Perform a specified number of function circuit accumulation rounds |
| 36 | + * @details Each round "accumulates" a mock function circuit and a mock kernel circuit. Each round thus consists of |
| 37 | + * the generation of two circuits, two folding proofs and two Merge proofs. To match the sizes called out in the |
| 38 | + * spec |
| 39 | + * (https://github.com/AztecProtocol/aztec-packages/blob/master/yellow-paper/docs/cryptography/performance-targets.md) |
| 40 | + * we set the size of the function circuit to be 2^17. The first one should be 2^19 but we can't currently support |
| 41 | + * folding circuits of unequal size. |
| 42 | + * |
| 43 | + */ |
| 44 | + static void perform_ivc_accumulation_rounds(State& state, ClientIVC& ivc) |
| 45 | + { |
| 46 | + // Initialize IVC with function circuit |
| 47 | + Builder function_circuit{ ivc.goblin.op_queue }; |
| 48 | + GoblinMockCircuits::construct_mock_function_circuit(function_circuit); |
| 49 | + ivc.initialize(function_circuit); |
| 50 | + |
| 51 | + // Accumulate kernel circuit (first kernel mocked as simple circuit since no folding proofs yet) |
| 52 | + Builder kernel_circuit{ ivc.goblin.op_queue }; |
| 53 | + GoblinMockCircuits::construct_mock_function_circuit(kernel_circuit); |
| 54 | + auto kernel_fold_proof = ivc.accumulate(kernel_circuit); |
| 55 | + |
| 56 | + auto NUM_CIRCUITS = static_cast<size_t>(state.range(0)); |
| 57 | + NUM_CIRCUITS -= 1; // Subtract one to account for the "initialization" round above |
| 58 | + for (size_t circuit_idx = 0; circuit_idx < NUM_CIRCUITS; ++circuit_idx) { |
| 59 | + |
| 60 | + // Accumulate function circuit |
| 61 | + Builder function_circuit{ ivc.goblin.op_queue }; |
| 62 | + GoblinMockCircuits::construct_mock_function_circuit(function_circuit); |
| 63 | + auto function_fold_proof = ivc.accumulate(function_circuit); |
| 64 | + |
| 65 | + // Accumulate kernel circuit |
| 66 | + Builder kernel_circuit{ ivc.goblin.op_queue }; |
| 67 | + GoblinMockCircuits::construct_mock_folding_kernel(kernel_circuit, function_fold_proof, kernel_fold_proof); |
| 68 | + auto kernel_fold_proof = ivc.accumulate(kernel_circuit); |
| 69 | + } |
| 70 | + } |
| 71 | +}; |
| 72 | + |
| 73 | +/** |
| 74 | + * @brief Benchmark the prover work for the full PG-Goblin IVC protocol |
| 75 | + * |
| 76 | + */ |
| 77 | +BENCHMARK_DEFINE_F(IvcBench, Full)(benchmark::State& state) |
| 78 | +{ |
| 79 | + ClientIVC ivc; |
| 80 | + |
| 81 | + for (auto _ : state) { |
| 82 | + BB_REPORT_OP_COUNT_IN_BENCH(state); |
| 83 | + // Perform a specified number of iterations of function/kernel accumulation |
| 84 | + perform_ivc_accumulation_rounds(state, ivc); |
| 85 | + |
| 86 | + // Construct IVC scheme proof (fold, decider, merge, eccvm, translator) |
| 87 | + ivc.prove(); |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * @brief Benchmark only the accumulation rounds |
| 93 | + * |
| 94 | + */ |
| 95 | +BENCHMARK_DEFINE_F(IvcBench, Accumulate)(benchmark::State& state) |
| 96 | +{ |
| 97 | + ClientIVC ivc; |
| 98 | + |
| 99 | + // Perform a specified number of iterations of function/kernel accumulation |
| 100 | + for (auto _ : state) { |
| 101 | + perform_ivc_accumulation_rounds(state, ivc); |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +/** |
| 106 | + * @brief Benchmark only the Decider component |
| 107 | + * |
| 108 | + */ |
| 109 | +BENCHMARK_DEFINE_F(IvcBench, Decide)(benchmark::State& state) |
| 110 | +{ |
| 111 | + ClientIVC ivc; |
| 112 | + |
| 113 | + BB_REPORT_OP_COUNT_IN_BENCH(state); |
| 114 | + // Perform a specified number of iterations of function/kernel accumulation |
| 115 | + perform_ivc_accumulation_rounds(state, ivc); |
| 116 | + |
| 117 | + // Construct eccvm proof, measure only translator proof construction |
| 118 | + for (auto _ : state) { |
| 119 | + ivc.decider_prove(); |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +/** |
| 124 | + * @brief Benchmark only the ECCVM component |
| 125 | + * |
| 126 | + */ |
| 127 | +BENCHMARK_DEFINE_F(IvcBench, ECCVM)(benchmark::State& state) |
| 128 | +{ |
| 129 | + ClientIVC ivc; |
| 130 | + |
| 131 | + BB_REPORT_OP_COUNT_IN_BENCH(state); |
| 132 | + // Perform a specified number of iterations of function/kernel accumulation |
| 133 | + perform_ivc_accumulation_rounds(state, ivc); |
| 134 | + |
| 135 | + // Construct and measure eccvm only |
| 136 | + for (auto _ : state) { |
| 137 | + ivc.goblin.prove_eccvm(); |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | +/** |
| 142 | + * @brief Benchmark only the Translator component |
| 143 | + * |
| 144 | + */ |
| 145 | +BENCHMARK_DEFINE_F(IvcBench, Translator)(benchmark::State& state) |
| 146 | +{ |
| 147 | + ClientIVC ivc; |
| 148 | + |
| 149 | + BB_REPORT_OP_COUNT_IN_BENCH(state); |
| 150 | + // Perform a specified number of iterations of function/kernel accumulation |
| 151 | + perform_ivc_accumulation_rounds(state, ivc); |
| 152 | + |
| 153 | + // Construct eccvm proof, measure only translator proof construction |
| 154 | + ivc.goblin.prove_eccvm(); |
| 155 | + for (auto _ : state) { |
| 156 | + ivc.goblin.prove_translator(); |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +#define ARGS \ |
| 161 | + Arg(IvcBench::NUM_ITERATIONS_MEDIUM_COMPLEXITY) \ |
| 162 | + ->Arg(1 << 0) \ |
| 163 | + ->Arg(1 << 1) \ |
| 164 | + ->Arg(1 << 2) \ |
| 165 | + ->Arg(1 << 3) \ |
| 166 | + ->Arg(1 << 4) \ |
| 167 | + ->Arg(1 << 5) \ |
| 168 | + ->Arg(1 << 6) |
| 169 | + |
| 170 | +BENCHMARK_REGISTER_F(IvcBench, Full)->Unit(benchmark::kMillisecond)->ARGS; |
| 171 | +BENCHMARK_REGISTER_F(IvcBench, Accumulate)->Unit(benchmark::kMillisecond)->ARGS; |
| 172 | +BENCHMARK_REGISTER_F(IvcBench, Decide)->Unit(benchmark::kMillisecond)->ARGS; |
| 173 | +BENCHMARK_REGISTER_F(IvcBench, ECCVM)->Unit(benchmark::kMillisecond)->ARGS; |
| 174 | +BENCHMARK_REGISTER_F(IvcBench, Translator)->Unit(benchmark::kMillisecond)->ARGS; |
| 175 | + |
| 176 | +} // namespace |
| 177 | + |
| 178 | +BENCHMARK_MAIN(); |
0 commit comments