Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
recursion_constraint_output.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Federico], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
8
9namespace acir_format {
10
11template <typename Builder>
13 bool update_ipa_data)
14{
15 // Update points accumulator
16 if (this->points_accumulator.is_populated()) {
17 this->points_accumulator.aggregate(other.points_accumulator);
18 } else {
19 this->points_accumulator = other.points_accumulator;
20 }
21
22 if (update_ipa_data) {
23 // Update ipa proofs and claims
24 this->nested_ipa_proofs.push_back(other.ipa_proof);
25 this->nested_ipa_claims.push_back(other.ipa_claim);
26 }
27}
28
29template <typename Builder>
31 bool update_ipa_data)
32{
33 if (this->points_accumulator.is_populated()) {
34 this->points_accumulator.aggregate(other.points_accumulator);
35 } else {
36 this->points_accumulator = other.points_accumulator;
37 }
38
39 if (update_ipa_data) {
40 // Update ipa proofs and claims (if other has no proofs/claims, we are not appending anything)
41 this->nested_ipa_proofs.insert(
42 this->nested_ipa_proofs.end(), other.nested_ipa_proofs.begin(), other.nested_ipa_proofs.end());
43 this->nested_ipa_claims.insert(
44 this->nested_ipa_claims.end(), other.nested_ipa_claims.begin(), other.nested_ipa_claims.end());
45 this->nested_triple_ipa_openings.insert(this->nested_triple_ipa_openings.end(),
46 other.nested_triple_ipa_openings.begin(),
47 other.nested_triple_ipa_openings.end());
48 }
49}
50
51template <typename Builder>
53 const stdlib::recursion::PairingPoints<stdlib::bn254<Builder>>& pairing_points, TripleIpaOpening triple_ipa_opening)
54{
55 if (this->points_accumulator.is_populated()) {
56 this->points_accumulator.aggregate(pairing_points);
57 } else {
58 this->points_accumulator = pairing_points;
59 }
60 this->nested_triple_ipa_openings.push_back(std::move(triple_ipa_opening));
61}
62
63template <>
65 UltraCircuitBuilder>::perform_IPA_accumulation(UltraCircuitBuilder& builder) const
66{
67 using RecursiveCurve = stdlib::grumpkin<UltraCircuitBuilder>;
69 using RecursiveIPA = IPA<RecursiveCurve>;
71 nested_ipa_claims.size(), nested_ipa_proofs.size(), "Mismatched number of nested IPA claims and proofs.");
72
73 std::vector<IPAAccumulator> accumulators;
74 accumulators.reserve(nested_ipa_claims.size() + nested_triple_ipa_openings.size());
75 for (size_t idx = 0; idx < nested_ipa_claims.size(); ++idx) {
76 auto ipa_transcript = std::make_shared<StdlibTranscript>(nested_ipa_proofs[idx]);
77 accumulators.emplace_back(RecursiveIPA::reduce_verify(nested_ipa_claims[idx], ipa_transcript));
78 }
79 for (const auto& opening : nested_triple_ipa_openings) {
80 accumulators.emplace_back(opening.reduce_verify());
81 }
82
83 CommitmentKey<curve::Grumpkin> commitment_key(1 << CONST_ECCVM_LOG_N);
84 if (accumulators.size() == 2) {
85 return RecursiveIPA::accumulate(commitment_key, std::move(accumulators[0]), std::move(accumulators[1]));
86 }
87 if (accumulators.size() == 1) {
88 return RecursiveIPA::prove_accumulator_claim(commitment_key, std::move(accumulators[0]));
89 }
90 if (accumulators.empty()) {
91 info("Proving with UltraRollupHonk but no IPA claims exist.");
92 return RecursiveIPA::create_random_valid_ipa_claim_and_proof(builder);
93 }
94 throw_or_abort("Too many nested IPA accumulators to accumulate");
95}
96
97template <>
100{
102
104 nested_ipa_claims.size(), nested_ipa_proofs.size(), "Mismatched number of nested IPA claims and proofs.");
105 BB_ASSERT_EQ(nested_ipa_claims.size() + nested_triple_ipa_openings.size(),
106 2U,
107 "Root rollup must accumulate two IPA proofs.");
108
109 auto [ipa_claim, ipa_proof] = perform_IPA_accumulation(builder);
110
111 // IPA verification
113 &builder, 1 << CONST_ECCVM_LOG_N, VerifierCommitmentKey<curve::Grumpkin>(1 << CONST_ECCVM_LOG_N));
114
115 auto accumulated_ipa_transcript =
117 IPA<stdlib::grumpkin<UltraCircuitBuilder>>::full_verify_recursive(
118 verifier_commitment_key, ipa_claim, accumulated_ipa_transcript);
119}
120
121template <>
123 [[maybe_unused]] bool is_hn_recursion_constraints,
124 [[maybe_unused]] bool has_ipa_claim)
125{
126 if (has_ipa_claim) {
128
129 // We have multiple IPA claims, we need to accumulate them
130 auto [ipa_claim, ipa_proof] = perform_IPA_accumulation(builder);
131
132 // Set proof
133 builder.ipa_proof = ipa_proof;
134
135 // Propagate pairing points and ipa claim
136 IO inputs;
137 inputs.pairing_inputs =
138 points_accumulator.is_populated()
139 ? points_accumulator
141 inputs.ipa_claim = ipa_claim;
142 inputs.set_public();
143 } else {
145
146 if (is_root_rollup) {
147 // The root rollup performs full IPA verification
148 perform_full_IPA_verification(builder);
149 } else {
150 // We shouldn't accidentally have IPA proofs.
151 BB_ASSERT_EQ(nested_ipa_proofs.size(), static_cast<size_t>(0), "IPA proofs present when not expected.");
152 BB_ASSERT_EQ(nested_triple_ipa_openings.size(),
153 static_cast<size_t>(0),
154 "TripleIPA openings present when not expected.");
155 }
156
157 // Propagate public inputs
158 if (points_accumulator.is_populated()) {
159 IO inputs;
160 inputs.pairing_inputs = points_accumulator;
161 inputs.set_public();
162 } else {
163 IO::add_default(builder);
164 }
165 }
166}
167
168template <>
170 [[maybe_unused]] bool is_hn_recursion_constraints,
171 [[maybe_unused]] bool has_ipa_claim)
172{
174
176 nested_ipa_claims.size(), static_cast<size_t>(0), "IPA claims present when not expected in MegaBuilder.");
177 BB_ASSERT_EQ(nested_triple_ipa_openings.size(),
178 static_cast<size_t>(0),
179 "TripleIPA openings present when not expected in MegaBuilder.");
180
181 // If the recursion constraints from HN, the public inputs have already been set. Otherwise, we need to propagate
182 // the pairing points
183 if (!is_hn_recursion_constraints) {
184 if (points_accumulator.is_populated()) {
185 IO inputs;
186 inputs.pairing_inputs = points_accumulator;
187 inputs.set_public();
188 } else {
189 IO::add_default(builder);
190 }
191 }
192}
193
196
199
202
205
209
210} // namespace acir_format
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:87
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:20
Manages the data that is propagated on the public inputs of an application/function circuit.
The data that is propagated on the public inputs of a rollup circuit.
#define info(...)
Definition log.hpp:93
AluTraceBuilder builder
Definition alu.test.cpp:124
AvmProvingInputs inputs
DefaultIO< MegaCircuitBuilder > AppIO
The data that is propagated on the public inputs of an application/function circuit.
std::vector< fr > HonkProof
Definition proof.hpp:15
BaseTranscript< stdlib::StdlibCodec< stdlib::field_t< UltraCircuitBuilder > >, stdlib::poseidon2< UltraCircuitBuilder > > UltraStdlibTranscript
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Container for the output of multiple recursive verifications.
void finalize(Builder &builder, bool is_hn_recursion_constraints=false, bool has_ipa_claim=false)
Finalize the output by accumulating IPA claims/proofs, performing full IPA verification,...
std::vector< stdlib::Proof< Builder > > nested_ipa_proofs
void perform_full_IPA_verification(Builder &builder) const
Perform full IPA recursive verification of the IPA claims and proofs contained in this output.
typename bb::ECCVMRecursiveVerifier::DeferredTripleIpaOpening TripleIpaOpening
stdlib::recursion::PairingPoints< stdlib::bn254< Builder > > points_accumulator
std::vector< OpeningClaim< stdlib::grumpkin< Builder > > > nested_ipa_claims
void update_triple_ipa_opening(const stdlib::recursion::PairingPoints< stdlib::bn254< Builder > > &pairing_points, TripleIpaOpening triple_ipa_opening)
void update(const HonkRecursionConstraintOutput< Builder > &other, bool update_ipa_data)
Update the current output with another recursion constraint output.
Curve grumpkin in circuit setting.
Definition grumpkin.hpp:21
An object storing two EC points that represent the inputs to a pairing check.
Output type for recursive ultra verification.
void throw_or_abort(std::string const &err)