Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
mock_circuits.hpp
Go to the documentation of this file.
1#pragma once
2#include <benchmark/benchmark.h>
3
10
12
19template <typename Builder>
21{
23
27 // Ensure the circuit is filled but finalisation doesn't make the circuit size go to the next power of two
28 const size_t GATE_COUNT_BUFFER = 1000; // Since we're using an estimate, let's add an error term in case.
29 size_t current_gates = builder.get_num_finalized_gates_inefficient(/*ensure_nonzero=*/false);
30
31 if (target_gate_count <= current_gates + GATE_COUNT_BUFFER) {
32 throw_or_abort("Target gate count is too low.");
33 }
34
35 size_t passes = (target_gate_count - current_gates - GATE_COUNT_BUFFER) / 4;
36
37 for (size_t i = 0; i < passes; ++i) {
38 c = a + b;
39 c = a * c;
40 a = b * b;
41 b = c * c;
42 }
43
44 size_t est_gate_count = builder.get_num_finalized_gates_inefficient(/*ensure_nonzero=*/false);
45 BB_ASSERT_LTE(est_gate_count,
46 target_gate_count - GATE_COUNT_BUFFER,
47 "Check that the finalized gate count won't exceed the desired gate count.");
48}
49
56template <typename Builder> void generate_basic_arithmetic_circuit(Builder& builder, size_t log2_num_gates)
57{
59}
60
61template <typename Prover>
62Prover get_prover(void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
63 size_t num_iterations)
64{
65 using Flavor = typename Prover::Flavor;
66 using Builder = typename Flavor::CircuitBuilder;
67
69 test_circuit_function(builder, num_iterations);
70
71 BB_BENCH_NAME("creating prover");
72
74 auto verification_key = std::make_shared<typename Flavor::VerificationKey>(prover_instance->get_precomputed());
75 return Prover(prover_instance, verification_key);
76};
77
88template <typename Prover>
90 benchmark::State& state,
91 void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
92 size_t num_iterations)
93{
95
96 for (auto _ : state) {
97 // Construct circuit and prover; don't include this part in measurement
98 state.PauseTiming();
99 Prover prover = get_prover<Prover>(test_circuit_function, num_iterations);
100 state.ResumeTiming();
101
102 // Construct proof
103 auto proof = prover.construct_proof();
104 }
105}
106
107} // namespace bb::mock_circuits
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:152
#define BB_BENCH_NAME(name)
Definition bb_bench.hpp:219
ECCVMCircuitBuilder CircuitBuilder
static void add_default(Builder &builder)
Add default public inputs when they are not present.
AluTraceBuilder builder
Definition alu.test.cpp:124
FF a
FF b
void generate_basic_arithmetic_circuit_with_target_gates(Builder &builder, size_t target_gate_count)
Generate test circuit with basic arithmetic operations, targeting a specific gate count.
void generate_basic_arithmetic_circuit(Builder &builder, size_t log2_num_gates)
Generate test circuit with basic arithmetic operations, using log2 of gate count.
Prover get_prover(void(*test_circuit_function)(typename Prover::Flavor::CircuitBuilder &, size_t), size_t num_iterations)
void construct_proof_with_specified_num_iterations(benchmark::State &state, void(*test_circuit_function)(typename Prover::Flavor::CircuitBuilder &, size_t), size_t num_iterations)
Performs proof constuction for benchmarks based on a provided circuit function.
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept
void throw_or_abort(std::string const &err)