-
Notifications
You must be signed in to change notification settings - Fork 333
/
Copy pathdecider_prover.cpp
116 lines (102 loc) · 5.08 KB
/
decider_prover.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "decider_prover.hpp"
#include "barretenberg/common/op_count.hpp"
#include "barretenberg/sumcheck/sumcheck.hpp"
namespace bb {
/**
* Create DeciderProver_ from an accumulator.
*
* @param accumulator Relaxed instance (ϕ, ω, \vec{β}, e) whose proof we want to generate, produced by Protogalaxy
* folding prover
*
* @tparam a type of UltraFlavor
* */
template <IsUltraFlavor Flavor>
DeciderProver_<Flavor>::DeciderProver_(const std::shared_ptr<DeciderPK>& proving_key,
const std::shared_ptr<Transcript>& transcript)
: proving_key(std::move(proving_key))
, transcript(transcript)
{}
/**
* @brief Run Sumcheck to establish that ∑_i pow(\vec{β*})f_i(ω) = e*. This results in u = (u_1,...,u_d) sumcheck round
* challenges and all evaluations at u being calculated.
*
*/
template <IsUltraFlavor Flavor> void DeciderProver_<Flavor>::execute_relation_check_rounds()
{
using Sumcheck = SumcheckProver<Flavor>;
size_t polynomial_size = proving_key->proving_key.circuit_size;
auto sumcheck = Sumcheck(polynomial_size, transcript);
{
PROFILE_THIS_NAME("sumcheck.prove");
if constexpr (Flavor::HasZK) {
auto commitment_key = std::make_shared<CommitmentKey>(Flavor::BATCHED_RELATION_PARTIAL_LENGTH);
zk_sumcheck_data = ZKSumcheckData<Flavor>(numeric::get_msb(polynomial_size), transcript, commitment_key);
sumcheck_output = sumcheck.prove(proving_key->proving_key.polynomials,
proving_key->relation_parameters,
proving_key->alphas,
proving_key->gate_challenges,
zk_sumcheck_data);
} else {
sumcheck_output = sumcheck.prove(proving_key->proving_key.polynomials,
proving_key->relation_parameters,
proving_key->alphas,
proving_key->gate_challenges);
}
}
}
/**
* @brief Produce a univariate opening claim for the sumcheck multivariate evalutions and a batched univariate claim
* for the transcript polynomials (for the Translator consistency check). Reduce the two opening claims to a single one
* via Shplonk and produce an opening proof with the univariate PCS of choice (IPA when operating on Grumpkin).
*
*/
template <IsUltraFlavor Flavor> void DeciderProver_<Flavor>::execute_pcs_rounds()
{
using OpeningClaim = ProverOpeningClaim<Curve>;
auto& ck = proving_key->proving_key.commitment_key;
ck = ck ? ck : std::make_shared<CommitmentKey>(proving_key->proving_key.circuit_size);
OpeningClaim prover_opening_claim;
if constexpr (!Flavor::HasZK) {
prover_opening_claim = ShpleminiProver_<Curve>::prove(proving_key->proving_key.circuit_size,
proving_key->proving_key.polynomials.get_unshifted(),
proving_key->proving_key.polynomials.get_to_be_shifted(),
sumcheck_output.challenge,
ck,
transcript);
} else {
prover_opening_claim = ShpleminiProver_<Curve>::prove(proving_key->proving_key.circuit_size,
proving_key->proving_key.polynomials.get_unshifted(),
proving_key->proving_key.polynomials.get_to_be_shifted(),
sumcheck_output.challenge,
ck,
transcript,
zk_sumcheck_data.libra_univariates_monomial,
sumcheck_output.claimed_libra_evaluations);
}
vinfo("executed multivariate-to-univarite reduction");
PCS::compute_opening_proof(ck, prover_opening_claim, transcript);
vinfo("computed opening proof");
}
template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::export_proof()
{
proof = transcript->proof_data;
return proof;
}
template <IsUltraFlavor Flavor> HonkProof DeciderProver_<Flavor>::construct_proof()
{
PROFILE_THIS_NAME("Decider::construct_proof");
// Run sumcheck subprotocol.
vinfo("executing relation checking rounds...");
execute_relation_check_rounds();
// Fiat-Shamir: rho, y, x, z
// Execute Shplemini PCS
vinfo("executing pcs opening rounds...");
execute_pcs_rounds();
return export_proof();
}
template class DeciderProver_<UltraFlavor>;
template class DeciderProver_<UltraRollupFlavor>;
template class DeciderProver_<UltraKeccakFlavor>;
template class DeciderProver_<MegaFlavor>;
template class DeciderProver_<MegaZKFlavor>;
} // namespace bb