Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
hypernova_recursion_constraint.cpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
10
11namespace acir_format {
12
13using namespace bb;
14
32{
33 // Check constraint proof type against the ACIR PROOF_TYPE values emitted by Noir.
34 auto has_proof_type = [](const RecursionConstraint& c, PROOF_TYPE expected) {
35 return c.proof_type == static_cast<uint32_t>(expected);
36 };
37
38 BB_ASSERT(!constraints.empty(), "At least one recursion constraint is required to determine Chonk state");
39 const bool is_init = has_proof_type(constraints[0], PROOF_TYPE::OINK);
40 // Reset and tail kernels are structurally identical from the IVC's perspective: each verifies a
41 // single previous kernel proof (HN). They are not distinguished here.
42 const bool is_reset_or_tail = (constraints.size() == 1 && has_proof_type(constraints[0], PROOF_TYPE::HN));
43 const bool is_hiding = (constraints.size() == 1 && has_proof_type(constraints[0], PROOF_TYPE::HN_FINAL));
44 const size_t upper_bound = is_init ? MAX_APPS_PER_KERNEL : MAX_APPS_PER_KERNEL + 1;
45 BB_ASSERT_LTE(constraints.size(), upper_bound, "Too many recursion constraints encountered when mocking IVC state");
46
47 // Build a constructor-valid circuit_kinds stack that faithfully places the kernel being mocked at
48 // `target_idx`, preceded by the circuits whose proofs it verifies (its group). The IVC is then positioned
49 // at `target_idx` so that complete_kernel_circuit_logic derives is_init_kernel()/is_hiding_kernel() from a
50 // state reachable by a real run. For non-hiding kernels the trailing kernels (tail and hiding) are appended to
51 // satisfy the constructor; it does not affect the mocked kernel's VK.
52 //
53 // `group` lists, for each proof the target kernel verifies, whether it is a kernel proof and whether this is
54 // the hiding kernel's group (which additionally needs mock decider and batch-merge proofs).
55 std::vector<CircuitKind> kinds;
56 struct GroupEntry {
57 bool is_kernel;
58 bool is_hiding;
59 };
61 size_t target_idx = 0;
62
63 if (is_init) {
64 // INIT kernel: verifies the leading apps (the first via an OINK proof, the rest via HN). No prior
65 // accumulator exists.
66 group.push_back({ /*is_kernel=*/false, /*is_hiding=*/false });
67 for (size_t idx = 1; idx < constraints.size(); idx++) {
68 BB_ASSERT(has_proof_type(constraints[idx], PROOF_TYPE::HN),
69 "Subsequent constraints in init kernel must be HN");
70 group.push_back({ /*is_kernel=*/false, /*is_hiding=*/false });
71 }
72 kinds.assign(group.size(), CircuitKind::App); // leading apps == the group
73 target_idx = kinds.size();
74 kinds.push_back(CircuitKind::Kernel); // init kernel (target)
75 kinds.push_back(CircuitKind::Kernel); // tail kernel
76 kinds.push_back(CircuitKind::HidingKernel); // hiding kernel
77 } else if (is_hiding) {
78 // HIDING kernel: the final circuit; verifies the tail kernel's proof and adds ZK hiding.
79 group.push_back({ /*is_kernel=*/true, /*is_hiding=*/true });
80 kinds = { CircuitKind::App, CircuitKind::Kernel, CircuitKind::Kernel, CircuitKind::HidingKernel };
81 target_idx = kinds.size() - 1; // the hiding kernel; its group is the tail kernel at index 2
82 } else {
83 // INNER kernel: verifies the previous kernel followed by its apps. RESET/TAIL is the degenerate case
84 // with no apps (a single previous-kernel proof).
85 BB_ASSERT(has_proof_type(constraints[0], PROOF_TYPE::HN),
86 "First constraint in inner/reset kernel must verify the previous kernel (HN)");
87 group.push_back({ /*is_kernel=*/true, /*is_hiding=*/false }); // previous kernel
88 for (size_t idx = 1; idx < constraints.size(); idx++) {
89 BB_ASSERT(has_proof_type(constraints[idx], PROOF_TYPE::HN),
90 "Subsequent constraints in inner kernel must be HN");
91 group.push_back({ /*is_kernel=*/false, /*is_hiding=*/false }); // app
92 }
93 BB_ASSERT(is_reset_or_tail || group.size() > 1,
94 "Single-proof non-init kernel must be a reset/tail (HN) kernel");
95 const size_t num_apps = group.size() - 1;
96 kinds.push_back(CircuitKind::App); // first app of the stack
97 kinds.push_back(CircuitKind::Kernel); // previous kernel (the group's first proof)
98 kinds.insert(kinds.end(), num_apps, CircuitKind::App); // the group's apps
99 target_idx = kinds.size();
100 kinds.push_back(CircuitKind::Kernel); // target kernel
101 kinds.push_back(CircuitKind::Kernel); // tail kernel
102 kinds.push_back(CircuitKind::HidingKernel); // hiding kernel
103 }
104
105 auto ivc = std::make_shared<Chonk>(kinds);
106 for (const auto& entry : group) {
107 mock_chonk_accumulation(ivc, entry.is_kernel, entry.is_hiding);
108 }
109 // Position the IVC at the kernel being mocked so current_kind() reports its kind.
110 ivc->set_num_circuits_accumulated_for_mocking(target_idx);
111 return ivc;
112}
113
125{
126 using IvcType = Chonk;
127 using AppFlavor = IvcType::AppFlavor;
128 using KernelFlavor = IvcType::KernelFlavor;
129
131 entry.kind = is_kernel ? Chonk::CircuitKind::Kernel : Chonk::CircuitKind::App;
132
133 if (is_kernel) {
135 entry.proof = create_mock_sumcheck_to_accumulator_proof<KernelFlavor, KernelIO>();
136 entry.kernel_honk_vk = create_mock_honk_vk<KernelFlavor, KernelIO>(1 << KernelFlavor::VIRTUAL_LOG_N);
137 } else {
139 entry.proof = create_mock_sumcheck_to_accumulator_proof<AppFlavor, AppIO>();
140 entry.app_honk_vk = create_mock_honk_vk<AppFlavor, AppIO>(1 << AppFlavor::VIRTUAL_LOG_N);
141 }
142
143 return entry;
144}
145
159void mock_chonk_accumulation(const std::shared_ptr<Chonk>& ivc, const bool is_kernel, const bool is_hiding_kernel)
160{
161 using FF = Chonk::FF;
162 using Commitment = Chonk::Commitment;
163
164 // The size of the challenge only depends on the VIRTUAL_LOG_N specified by the Flavor.
165 // KernelFlavor and AppFlavor have the same VIRTUAL_LOG_N, so we can generate the challenge
166 // vector with either.
167 ivc->recursive_verifier_native_accum.challenge = std::vector<FF>(Chonk::KernelFlavor::VIRTUAL_LOG_N, FF::zero());
168 ivc->recursive_verifier_native_accum.non_shifted_evaluation = FF::zero();
169 ivc->recursive_verifier_native_accum.shifted_evaluation = FF::zero();
170 ivc->recursive_verifier_native_accum.non_shifted_commitment = Commitment::one();
171 ivc->recursive_verifier_native_accum.shifted_commitment = Commitment::one();
172
174 ivc->verification_queue.emplace_back(entry);
175
176 // The kernel batches the previous accumulator (absent for the init kernel, whose queue
177 // begins with an app) plus one claim per queued proof. Each call refreshes the mock batching proof so the last
178 // one (with the full group) carries the correct width; a single-claim init kernel needs no batching proof.
179 const bool is_init =
180 !ivc->verification_queue.empty() && ivc->verification_queue.front().kind == Chonk::CircuitKind::App;
181 const size_t num_claims =
182 Chonk::group_claim_count(/*has_previous_accumulator=*/!is_init, ivc->verification_queue.size());
183 if (num_claims >= 2) {
184 ivc->multilinear_batch_proof = acir_format::create_mock_multilinear_batch_proof(num_claims);
185 }
186 if (is_hiding_kernel) {
187 ivc->goblin.batch_merge_proof = acir_format::create_mock_batch_merge_proof();
188 // The PCS proof only depends on the VIRTUAL_LOG_N specified by the Flavor. KernelFlavor and
189 // AppFlavor have the same VIRTUAL_LOG_N, so we can generate the mock PCS proof with either.
190 ivc->decider_proof = acir_format::create_mock_pcs_proof<Chonk::KernelFlavor>();
191 }
192 ivc->set_num_circuits_accumulated_for_mocking(ivc->get_num_circuits_accumulated() + 1);
193}
194
195} // namespace acir_format
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_LTE(left, right,...)
Definition assert.hpp:158
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:42
curve::BN254::AffineElement Commitment
Definition chonk.hpp:56
bb::fr FF
Definition chonk.hpp:55
static constexpr size_t group_claim_count(bool has_previous_accumulator, size_t group_size)
Number of claims a kernel batches: the previous accumulator (absent for the init kernel) plus one sum...
Definition chonk.hpp:198
static constexpr size_t VIRTUAL_LOG_N
group class. Represents an elliptic curve group element. Group is parametrised by Fq and Fr
Definition group.hpp:38
Manages the data that is propagated on the public inputs of an application/function circuit.
Manages the data that is propagated on the public inputs of a kernel circuit.
Chonk::VerifierInputs create_mock_verification_queue_entry(const bool is_kernel)
Create a mock verification queue entry with structurally correct proof and VK.
HonkProof create_mock_multilinear_batch_proof(size_t num_claims)
Create a mock multilinear batching proof of the given width (number of batched claims) that has corre...
void mock_chonk_accumulation(const std::shared_ptr< Chonk > &ivc, const bool is_kernel, const bool is_hiding_kernel)
Add mock accumulation state to a Chonk instance for a single circuit.
std::shared_ptr< Chonk > create_mock_chonk_from_constraints(const std::vector< RecursionConstraint > &constraints)
Create a Chonk instance with mocked state corresponding to a set of IVC recursion constraints.
HonkProof create_mock_batch_merge_proof()
Create a mock batch merge proof which has the correct structure but is not necessarily valid.
AvmFlavorSettings::FF FF
Definition field.hpp:10
KernelIO_< MAX_APPS_PER_KERNEL > KernelIO
DefaultIO< MegaCircuitBuilder > AppIO
The data that is propagated on the public inputs of an application/function circuit.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
RecursionConstraint struct contains information required to recursively verify a proof.
std::shared_ptr< KernelVerificationKey > kernel_honk_vk
Definition chonk.hpp:106
std::shared_ptr< AppVerificationKey > app_honk_vk
Definition chonk.hpp:105
std::vector< FF > proof
Definition chonk.hpp:104