Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ipa.bench.cpp
Go to the documentation of this file.
4#include <benchmark/benchmark.h>
5
6using namespace benchmark;
7using namespace bb;
8
9namespace {
13
14constexpr size_t MIN_POLYNOMIAL_DEGREE_LOG2 = 10;
15constexpr size_t MAX_POLYNOMIAL_DEGREE_LOG2 = 16;
16
19std::vector<std::shared_ptr<NativeTranscript>> prover_transcripts(MAX_POLYNOMIAL_DEGREE_LOG2 -
20 MIN_POLYNOMIAL_DEGREE_LOG2 + 1);
21std::vector<OpeningClaim<Curve>> opening_claims(MAX_POLYNOMIAL_DEGREE_LOG2 - MIN_POLYNOMIAL_DEGREE_LOG2 + 1);
22static void DoSetup(const benchmark::State&)
23{
25 ck = CommitmentKey<Curve>(1 << MAX_POLYNOMIAL_DEGREE_LOG2);
26 vk = VerifierCommitmentKey<Curve>(1 << MAX_POLYNOMIAL_DEGREE_LOG2, srs::get_grumpkin_crs_factory());
27}
28
29void ipa_open(State& state) noexcept
30{
32 for (auto _ : state) {
33 state.PauseTiming();
34 size_t n = 1 << static_cast<size_t>(state.range(0));
35 // Construct the polynomial
36 Polynomial poly(n);
37 for (size_t i = 0; i < n; ++i) {
38 poly.at(i) = Fr::random_element(&engine);
39 }
40 auto x = Fr::random_element(&engine);
41 auto eval = poly.evaluate(x);
42 const OpeningPair<Curve> opening_pair = { x, eval };
43 const OpeningClaim<Curve> opening_claim{ opening_pair, ck.commit(poly) };
44 // initialize empty prover transcript
45 auto prover_transcript = std::make_shared<NativeTranscript>();
46 state.ResumeTiming();
47 // Compute proof
48 IPA<Curve>::compute_opening_proof(ck, { poly, opening_pair }, prover_transcript);
49 // Store info for verifier
50 prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = prover_transcript;
51 opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2] = opening_claim;
52 }
53}
54void ipa_verify(State& state) noexcept
55{
56 for (auto _ : state) {
57 state.PauseTiming();
58 // Retrieve proofs
59 auto prover_transcript = prover_transcripts[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2];
60 auto opening_claim = opening_claims[static_cast<size_t>(state.range(0)) - MIN_POLYNOMIAL_DEGREE_LOG2];
61 // initialize verifier transcript from proof data
62 auto verifier_transcript = std::make_shared<NativeTranscript>();
63 verifier_transcript->load_proof(prover_transcript->export_proof());
64
65 state.ResumeTiming();
66 auto result = IPA<Curve>::reduce_verify(vk, opening_claim, verifier_transcript);
67 ASSERT(result);
68 }
69}
70} // namespace
71BENCHMARK(ipa_open)
72 ->Unit(kMillisecond)
73 ->DenseRange(MIN_POLYNOMIAL_DEGREE_LOG2, MAX_POLYNOMIAL_DEGREE_LOG2)
74 ->Setup(DoSetup);
75BENCHMARK(ipa_verify)
76 ->Unit(kMillisecond)
77 ->DenseRange(MIN_POLYNOMIAL_DEGREE_LOG2, MAX_POLYNOMIAL_DEGREE_LOG2)
78 ->Setup(DoSetup);
#define ASSERT(expression,...)
Definition assert.hpp:49
CommitmentKey object over a pairing group 𝔾₁.
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:95
Unverified claim (C,r,v) for some witness polynomial p(X) such that.
Definition claim.hpp:53
Opening pair (r,v) for some witness polynomial p(X) such that p(r) = v.
Definition claim.hpp:19
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
numeric::RNG & engine
BENCHMARK_MAIN()
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
std::shared_ptr< factories::CrsFactory< curve::Grumpkin > > get_grumpkin_crs_factory()
Entry point for Barretenberg command-line interface.
BENCHMARK(vector_of_evaluations) -> DenseRange(15, 21) ->Unit(kMillisecond) ->Iterations(1)
CommitmentKey< Curve > ck
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept