Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ultra_prover.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#include "ultra_prover.hpp"
11namespace bb {
12
13template <IsUltraOrMegaHonk Flavor>
14UltraProver_<Flavor>::UltraProver_(const std::shared_ptr<DeciderPK>& proving_key,
15 const std::shared_ptr<HonkVK>& honk_vk,
16 const CommitmentKey& commitment_key)
17 : proving_key(std::move(proving_key))
18 , honk_vk(honk_vk)
19 , transcript(std::make_shared<Transcript>())
20 , commitment_key(commitment_key)
21{}
22
30template <IsUltraOrMegaHonk Flavor>
31UltraProver_<Flavor>::UltraProver_(const std::shared_ptr<DeciderPK>& proving_key,
32 const std::shared_ptr<HonkVK>& honk_vk,
33 const std::shared_ptr<Transcript>& transcript)
34 : proving_key(std::move(proving_key))
35 , honk_vk(honk_vk)
36 , transcript(transcript)
37 , commitment_key(proving_key->commitment_key)
38{}
39
47template <IsUltraOrMegaHonk Flavor>
49 const std::shared_ptr<HonkVK>& honk_vk,
50 const std::shared_ptr<Transcript>& transcript)
51 : proving_key(std::make_shared<DeciderPK>(circuit))
52 , honk_vk(honk_vk)
53 , transcript(transcript)
54 , commitment_key(proving_key->commitment_key)
55{}
56
57template <IsUltraOrMegaHonk Flavor>
58UltraProver_<Flavor>::UltraProver_(Builder&& circuit, const std::shared_ptr<HonkVK>& honk_vk)
59 : proving_key(std::make_shared<DeciderPK>(circuit))
60 , honk_vk(honk_vk)
61 , transcript(std::make_shared<Transcript>())
62 , commitment_key(proving_key->commitment_key)
63{}
64
65template <IsUltraOrMegaHonk Flavor> typename UltraProver_<Flavor>::Proof UltraProver_<Flavor>::export_proof()
66{
67 auto proof = transcript->export_proof();
68
69 // Add the IPA proof
70 if constexpr (HasIPAAccumulator<Flavor>) {
71 // The extra calculation is for the IPA proof length.
72 BB_ASSERT_EQ(proving_key->ipa_proof.size(), static_cast<size_t>(IPA_PROOF_LENGTH));
73 proof.insert(proof.end(), proving_key->ipa_proof.begin(), proving_key->ipa_proof.end());
74 }
75
76 return proof;
77}
78
79template <IsUltraOrMegaHonk Flavor> void UltraProver_<Flavor>::generate_gate_challenges()
80{
81 // Determine the number of rounds in the sumcheck based on whether or not padding is employed
82 const size_t virtual_log_n =
83 Flavor::USE_PADDING ? Flavor::VIRTUAL_LOG_N : static_cast<size_t>(proving_key->log_dyadic_size());
84
85 proving_key->gate_challenges =
86 transcript->template get_powers_of_challenge<FF>("Sumcheck:gate_challenge", virtual_log_n);
87}
88
89template <IsUltraOrMegaHonk Flavor> typename UltraProver_<Flavor>::Proof UltraProver_<Flavor>::construct_proof()
90{
91 OinkProver<Flavor> oink_prover(proving_key, honk_vk, transcript);
92 oink_prover.prove();
93 vinfo("created oink proof");
94
95 generate_gate_challenges();
96
97 DeciderProver_<Flavor> decider_prover(proving_key, transcript);
98 decider_prover.construct_proof();
99 return export_proof();
100}
101
102template class UltraProver_<UltraFlavor>;
103template class UltraProver_<UltraZKFlavor>;
105#ifdef STARKNET_GARAGA_FLAVORS
108#endif
111template class UltraProver_<MegaFlavor>;
112template class UltraProver_<MegaZKFlavor>;
113
114} // namespace bb
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
static constexpr size_t VIRTUAL_LOG_N
static constexpr bool USE_PADDING
Class for all the oink rounds, which are shared between the folding prover and ultra prover.
void prove()
Oink Prover function that runs all the rounds of the verifier.
UltraProver_(const std::shared_ptr< DeciderPK > &, const std::shared_ptr< HonkVK > &, const CommitmentKey &)
BB_PROFILE void generate_gate_challenges()
typename Transcript::Proof Proof
typename Flavor::CommitmentKey CommitmentKey
typename Flavor::Transcript Transcript
typename Flavor::CircuitBuilder Builder
void vinfo(Args... args)
Definition log.hpp:76
Entry point for Barretenberg command-line interface.
STL namespace.