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// =====================
18
19namespace acir_format {
20
21using namespace bb;
22
41{
42 auto ivc = std::make_shared<Chonk>(constraints.size());
43
44 // Check constraint proof type. Throws if proof_type is not a valid HyperNova type
45 auto constraint_has_type = [](const RecursionConstraint& c, Chonk::QUEUE_TYPE expected) {
46 return proof_type_to_chonk_queue_type(c.proof_type) == expected;
47 };
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 (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::OINK)) {
53 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::OINK, /*is_kernel=*/false);
54 return ivc;
55 }
56
57 // RESET kernel: Verifies only a previous kernel (resets the IVC accumulation)
58 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN)) {
59 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
60 return ivc;
61 }
62
63 // TAIL kernel: Final kernel in the chain before generating tube proof
64 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_TAIL)) {
65 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_TAIL, /*is_kernel=*/true);
66 return ivc;
67 }
68
69 // INNER kernel: Verifies previous kernel + new app circuit
70 if (constraints.size() == 2) {
71 BB_ASSERT(constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN),
72 "Inner kernel first constraint must be HN type");
73 BB_ASSERT(constraint_has_type(constraints[1], Chonk::QUEUE_TYPE::HN),
74 "Inner kernel second constraint must be HN type");
75 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
76 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/false);
77 return ivc;
78 }
79
80 // HIDING kernel: Adds zero-knowledge hiding to the final proof
81 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_FINAL)) {
82 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_FINAL, /*is_kernel=*/true);
83 return ivc;
84 }
85
86 throw_or_abort("Invalid set of IVC recursion constraints!");
87 return ivc;
88}
89
106 const bool is_kernel)
107{
108 using IvcType = Chonk;
109 using FF = IvcType::FF;
110 using MegaVerificationKey = IvcType::MegaVerificationKey;
111 using Flavor = IvcType::Flavor;
112
113 size_t dyadic_size = 1 << Flavor::VIRTUAL_LOG_N; // maybe doesnt need to be correct
114
115 std::vector<FF> proof;
117
118 if (is_kernel) {
120 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::HN || verification_type == Chonk::QUEUE_TYPE::HN_TAIL ||
121 verification_type == Chonk::QUEUE_TYPE::HN_FINAL,
122 true);
123
124 // Kernel circuits always have a prior accumulator, so fold proof is always included
125 constexpr bool include_fold = true;
126 proof = create_mock_hyper_nova_proof<Flavor, KernelIO>(include_fold);
127
128 verification_key = create_mock_honk_vk<Flavor, KernelIO>(dyadic_size);
129 } else {
131 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::OINK || verification_type == Chonk::QUEUE_TYPE::HN, true);
132
133 // First app (OINK) has no prior accumulator; subsequent apps (HN) do
134 bool include_fold = (verification_type != Chonk::QUEUE_TYPE::OINK);
135 proof = create_mock_hyper_nova_proof<Flavor, AppIO>(include_fold);
136
137 verification_key = create_mock_honk_vk<Flavor, AppIO>(dyadic_size);
138 }
139
140 return Chonk::VerifierInputs{ proof, verification_key, verification_type, is_kernel };
141}
142
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 ivc->goblin.merge_verification_queue.emplace_back(acir_format::create_mock_merge_proof());
172 if (type == Chonk::QUEUE_TYPE::HN_FINAL) {
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
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:38
Flavor::FF FF
Definition chonk.hpp:45
Flavor::Commitment Commitment
Definition chonk.hpp:46
QUEUE_TYPE
Proof type determining recursive verification logic in kernel circuits.
Definition chonk.hpp:105
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.
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
Goblin::MergeProof create_mock_merge_proof()
Create a mock merge proof which has the correct structure but is not necessarily valid.
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.
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
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.
void throw_or_abort(std::string const &err)