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> void generate_basic_arithmetic_circuit(Builder& builder, size_t log2_num_gates)
20{
22
26 // Ensure the circuit is filled but finalisation doesn't make the circuit size go to the next power of two
27 size_t target_gate_count = (1UL << log2_num_gates);
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 passes = (target_gate_count - builder.get_estimated_num_finalized_gates() - GATE_COUNT_BUFFER) / 4;
30 if (static_cast<int>(passes) <= 0) {
31 throw_or_abort("We don't support low values of log2_num_gates.");
32 }
33
34 for (size_t i = 0; i < passes; ++i) {
35 c = a + b;
36 c = a * c;
37 a = b * b;
38 b = c * c;
39 }
40
41 size_t est_gate_count = builder.get_estimated_num_finalized_gates();
42 BB_ASSERT_LTE(est_gate_count,
43 (1UL << log2_num_gates) - GATE_COUNT_BUFFER,
44 "Check that the finalized gate count won't exceed the desired gate count.");
45}
46
47template <typename Prover>
48Prover get_prover(void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
49 size_t num_iterations)
50{
51 using Flavor = typename Prover::Flavor;
52 using Builder = typename Flavor::CircuitBuilder;
53
55 test_circuit_function(builder, num_iterations);
56
57 PROFILE_THIS_NAME("creating prover");
58
60 auto verification_key = std::make_shared<typename Flavor::VerificationKey>(proving_key->get_precomputed());
61 return Prover(proving_key, verification_key);
62};
63
74template <typename Prover>
76 benchmark::State& state,
77 void (*test_circuit_function)(typename Prover::Flavor::CircuitBuilder&, size_t),
78 size_t num_iterations)
79{
81
82 for (auto _ : state) {
83 // Construct circuit and prover; don't include this part in measurement
84 state.PauseTiming();
85 Prover prover = get_prover<Prover>(test_circuit_function, num_iterations);
86 state.ResumeTiming();
87
88 // Construct proof
89 auto proof = prover.construct_proof();
90 }
91}
92
93} // namespace bb::mock_circuits
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:129
MegaCircuitBuilder CircuitBuilder
AluTraceBuilder builder
Definition alu.test.cpp:123
FF a
FF b
void generate_basic_arithmetic_circuit(Builder &builder, size_t log2_num_gates)
Generate test circuit with basic arithmetic operations.
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
#define PROFILE_THIS_NAME(name)
Definition op_count.hpp:16
static field random_element(numeric::RNG *engine=nullptr) noexcept
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.
void throw_or_abort(std::string const &err)