Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator.bench.cpp
Go to the documentation of this file.
1#include <benchmark/benchmark.h>
2
6
7using namespace benchmark;
8using namespace bb;
9
10namespace {
11
15
16void add_random_ops(const std::shared_ptr<ECCOpQueue>& op_queue, size_t count)
17{
18 for (size_t i = 0; i < count; ++i) {
19 op_queue->random_op_ultra_only();
20 }
21}
22
23void add_mixed_ops(const std::shared_ptr<ECCOpQueue>& op_queue, size_t count)
24{
25 auto point_a = g1::affine_element::random_element();
26 auto point_b = g1::affine_element::random_element();
27 auto scalar = fr::random_element();
28
29 for (size_t i = 0; i < count; ++i) {
30 op_queue->add_accumulate(point_a);
31 op_queue->mul_accumulate(point_b, scalar);
32 }
33 op_queue->eq_and_reset();
34}
35
36CircuitBuilder generate_translator_circuit(size_t capacity_percent)
37{
38 auto op_queue = std::make_shared<ECCOpQueue>();
39 op_queue->construct_zk_columns();
40
41 constexpr size_t usable_rows =
43 const size_t target_rows = usable_rows * capacity_percent / 100;
44 const size_t mixed_op_count = std::max<size_t>(1, target_rows / 4);
45
46 add_mixed_ops(op_queue, mixed_op_count);
47 add_random_ops(op_queue, TranslatorCircuitBuilder::NUM_RANDOM_OPS_END);
48 op_queue->merge_fixed_append(op_queue->get_append_offset());
49
51}
52
53template <typename Prover, typename ProvingKey> void construct_proof(State& state)
54{
55 const size_t capacity_percent = static_cast<size_t>(state.range(0));
56 for (auto _ : state) {
57 auto circuit = generate_translator_circuit(capacity_percent);
58 auto transcript = std::make_shared<Transcript>();
59 auto proving_key = std::make_shared<ProvingKey>(circuit);
60 Prover prover{ proving_key, transcript };
61 benchmark::DoNotOptimize(prover.construct_proof());
62 }
63 state.counters["capacity_percent"] = static_cast<double>(capacity_percent);
64}
65
66template <typename Prover, typename ProvingKey> void execute_sumcheck(State& state)
67{
68 const size_t capacity_percent = static_cast<size_t>(state.range(0));
69 for (auto _ : state) {
70 state.PauseTiming();
71 auto circuit = generate_translator_circuit(capacity_percent);
72 auto transcript = std::make_shared<Transcript>();
73 auto proving_key = std::make_shared<ProvingKey>(circuit);
74 Prover prover{ proving_key, transcript };
75 prover.execute_preamble_round();
76 prover.execute_wire_and_sorted_constraints_commitments_round();
77 prover.execute_grand_product_computation_round();
78 state.ResumeTiming();
79
80 prover.execute_relation_check_rounds();
81 benchmark::DoNotOptimize(prover.sumcheck_output);
82 }
83 state.counters["capacity_percent"] = static_cast<double>(capacity_percent);
84}
85
86void translator_full_prove(State& state)
87{
88 construct_proof<TranslatorProver, TranslatorProvingKey>(state);
89}
90
91void translator_full_sumcheck(State& state)
92{
93 execute_sumcheck<TranslatorProver, TranslatorProvingKey>(state);
94}
95
96BENCHMARK(translator_full_prove)->Unit(kMillisecond)->Arg(25)->Arg(50)->Arg(75);
97BENCHMARK(translator_full_sumcheck)->Unit(kMillisecond)->Arg(25)->Arg(50)->Arg(75);
98
99} // namespace
100
101int main(int argc, char** argv)
102{
104 benchmark::Initialize(&argc, argv);
105 benchmark::RunSpecifiedBenchmarks();
106 benchmark::Shutdown();
107 return 0;
108}
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
BaseTranscript< Codec, HashFunction > Transcript
TranslatorCircuitBuilder CircuitBuilder
static constexpr size_t RESULT_ROW
static constexpr size_t dyadic_mini_circuit_size_without_masking
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
BENCHMARK(bench_commit_structured_random_poly< curve::BN254 >) -> Unit(benchmark::kMillisecond)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept