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
33{
34 auto ivc = std::make_shared<Chonk>(std::max(constraints.size(), static_cast<size_t>(MAX_APPS_PER_KERNEL + 1)));
35 // Check constraint proof type. Throws if proof_type is not a valid HyperNova type
36 auto constraint_has_type = [](const RecursionConstraint& c, Chonk::QUEUE_TYPE expected) {
37 return proof_type_to_chonk_queue_type(c.proof_type) == expected;
38 };
39
40 BB_ASSERT(!constraints.empty(), "At least one recursion constraint is required to determine Chonk state");
41 const bool is_init = constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::OINK);
42 const bool is_reset = (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN));
43 const bool is_tail = (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_TAIL));
44 const bool is_hiding =
45 (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_FINAL));
46 const size_t upper_bound = is_init ? MAX_APPS_PER_KERNEL : MAX_APPS_PER_KERNEL + 1;
47 BB_ASSERT_LTE(constraints.size(), upper_bound, "Too many recursion constraints encountered when mocking IVC state");
48
49 // Match constraint patterns to kernel types and populate appropriate mock data:
50
51 // INIT kernel: Verifies first app circuit (no prior accumulator exists)
52 if (is_init) {
53 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::OINK, /*is_kernel=*/false);
54 for (size_t idx = 1; idx < constraints.size(); idx++) {
55 BB_ASSERT(constraint_has_type(constraints[idx], Chonk::QUEUE_TYPE::HN),
56 "Subsequent constraints in init kernel must be HN type");
57 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/false);
58 }
59 return ivc;
60 }
61
62 // RESET kernel: Verifies only a previous kernel (resets the IVC accumulation)
63 if (is_reset) {
64 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
65 return ivc;
66 }
67
68 // TAIL kernel: Final kernel in the chain before hiding kernel
69 if (is_tail) {
70 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_TAIL, /*is_kernel=*/true);
71 return ivc;
72 }
73
74 // HIDING kernel: Adds zero-knowledge hiding to the final proof
75 if (is_hiding) {
76 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_FINAL, /*is_kernel=*/true);
77 return ivc;
78 }
79
80 // INNER kernel: Verifies previous kernel + app circuits
81 bool is_kernel = true;
82 for (const auto& constraint : constraints) {
83 BB_ASSERT(constraint_has_type(constraint, Chonk::QUEUE_TYPE::HN),
84 "All constraints in inner kernel must be HN type");
85 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/is_kernel);
86 is_kernel = false; // First constraint verifies previous kernel, subsequent constraints verify apps
87 }
88 return ivc;
89}
90
107 const bool is_kernel)
108{
109 using IvcType = Chonk;
110 using FF = IvcType::FF;
111 using MegaVerificationKey = IvcType::MegaVerificationKey;
112 using Flavor = IvcType::Flavor;
113
114 size_t dyadic_size = 1 << Flavor::VIRTUAL_LOG_N; // maybe doesnt need to be correct
115
116 std::vector<FF> proof;
118
119 if (is_kernel) {
121 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::HN || verification_type == Chonk::QUEUE_TYPE::HN_TAIL ||
122 verification_type == Chonk::QUEUE_TYPE::HN_FINAL,
123 true);
124
125 // Kernel circuits always have a prior accumulator, so fold proof is always included
126 constexpr bool include_fold = true;
127 proof = create_mock_hyper_nova_proof<Flavor, KernelIO>(include_fold);
128
129 verification_key = create_mock_honk_vk<Flavor, KernelIO>(dyadic_size);
130 } else {
132 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::OINK || verification_type == Chonk::QUEUE_TYPE::HN, true);
133
134 // First app (OINK) has no prior accumulator; subsequent apps (HN) do
135 bool include_fold = (verification_type != Chonk::QUEUE_TYPE::OINK);
136 proof = create_mock_hyper_nova_proof<Flavor, AppIO>(include_fold);
137
138 verification_key = create_mock_honk_vk<Flavor, AppIO>(dyadic_size);
139 }
140
141 return Chonk::VerifierInputs{ proof, verification_key, verification_type, is_kernel };
142}
143
158{
159 using FF = Chonk::FF;
160 using Commitment = Chonk::Commitment;
161
162 // Initialize verifier accumulator with proper structure
163 ivc->recursive_verifier_native_accum.challenge = std::vector<FF>(Chonk::Flavor::VIRTUAL_LOG_N, FF::zero());
164 ivc->recursive_verifier_native_accum.non_shifted_evaluation = FF::zero();
165 ivc->recursive_verifier_native_accum.shifted_evaluation = FF::zero();
166 ivc->recursive_verifier_native_accum.non_shifted_commitment = Commitment::one();
167 ivc->recursive_verifier_native_accum.shifted_commitment = Commitment::one();
168
170 ivc->verification_queue.emplace_back(entry);
171 if (type == Chonk::QUEUE_TYPE::HN_FINAL) {
172 ivc->goblin.batch_merge_proof = acir_format::create_mock_batch_merge_proof();
173 ivc->decider_proof = acir_format::create_mock_pcs_proof<Chonk::Flavor>();
174 }
175 ivc->num_circuits_accumulated++;
176}
177
178} // namespace acir_format
#define BB_ASSERT(expression,...)
Definition assert.hpp:70
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
#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:39
Flavor::FF FF
Definition chonk.hpp:46
Flavor::Commitment Commitment
Definition chonk.hpp:47
QUEUE_TYPE
Proof type determining recursive verification logic in kernel circuits.
Definition chonk.hpp:117
static constexpr size_t VIRTUAL_LOG_N
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.
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.
Chonk::VerifierInputs create_mock_verification_queue_entry(const Chonk::QUEUE_TYPE verification_type, const bool is_kernel)
Create a mock verification queue entry with structurally correct proof and VK.
HonkProof create_mock_batch_merge_proof()
Create a mock batch merge proof which has the correct structure but is not necessarily valid.
Chonk::QUEUE_TYPE proof_type_to_chonk_queue_type(uint32_t proof_type)
void mock_chonk_accumulation(const std::shared_ptr< Chonk > &ivc, Chonk::QUEUE_TYPE type, const bool is_kernel)
Add mock accumulation state to a Chonk instance for a single circuit.
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.