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>(constraints.size());
35
36 // Check constraint proof type. Throws if proof_type is not a valid HyperNova type
37 auto constraint_has_type = [](const RecursionConstraint& c, Chonk::QUEUE_TYPE expected) {
38 return proof_type_to_chonk_queue_type(c.proof_type) == expected;
39 };
40
41 // Match constraint patterns to kernel types and populate appropriate mock data:
42
43 // INIT kernel: Verifies first app circuit (no prior accumulator exists)
44 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::OINK)) {
45 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::OINK, /*is_kernel=*/false);
46 return ivc;
47 }
48
49 // RESET kernel: Verifies only a previous kernel (resets the IVC accumulation)
50 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN)) {
51 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
52 return ivc;
53 }
54
55 // TAIL kernel: Final kernel in the chain before generating tube proof
56 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_TAIL)) {
57 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_TAIL, /*is_kernel=*/true);
58 return ivc;
59 }
60
61 // INNER kernel: Verifies previous kernel + new app circuit
62 if (constraints.size() == 2) {
63 BB_ASSERT(constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN),
64 "Inner kernel first constraint must be HN type");
65 BB_ASSERT(constraint_has_type(constraints[1], Chonk::QUEUE_TYPE::HN),
66 "Inner kernel second constraint must be HN type");
67 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
68 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/false);
69 return ivc;
70 }
71
72 // HIDING kernel: Adds zero-knowledge hiding to the final proof
73 if (constraints.size() == 1 && constraint_has_type(constraints[0], Chonk::QUEUE_TYPE::HN_FINAL)) {
74 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_FINAL, /*is_kernel=*/true);
75 return ivc;
76 }
77
78 throw_or_abort("Invalid set of IVC recursion constraints!");
79 return ivc;
80}
81
98 const bool is_kernel)
99{
100 using IvcType = Chonk;
101 using FF = IvcType::FF;
102 using MegaVerificationKey = IvcType::MegaVerificationKey;
103 using Flavor = IvcType::Flavor;
104
105 size_t dyadic_size = 1 << Flavor::VIRTUAL_LOG_N; // maybe doesnt need to be correct
106
107 std::vector<FF> proof;
109
110 if (is_kernel) {
112 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::HN || verification_type == Chonk::QUEUE_TYPE::HN_TAIL ||
113 verification_type == Chonk::QUEUE_TYPE::HN_FINAL,
114 true);
115
116 // Kernel circuits always have a prior accumulator, so fold proof is always included
117 constexpr bool include_fold = true;
118 proof = create_mock_hyper_nova_proof<Flavor, KernelIO>(include_fold);
119
120 verification_key = create_mock_honk_vk<Flavor, KernelIO>(dyadic_size);
121 } else {
123 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::OINK || verification_type == Chonk::QUEUE_TYPE::HN, true);
124
125 // First app (OINK) has no prior accumulator; subsequent apps (HN) do
126 bool include_fold = (verification_type != Chonk::QUEUE_TYPE::OINK);
127 proof = create_mock_hyper_nova_proof<Flavor, AppIO>(include_fold);
128
129 verification_key = create_mock_honk_vk<Flavor, AppIO>(dyadic_size);
130 }
131
132 return Chonk::VerifierInputs{ proof, verification_key, verification_type, is_kernel };
133}
134
150{
151 using FF = Chonk::FF;
152 using Commitment = Chonk::Commitment;
153
154 // Initialize verifier accumulator with proper structure
155 ivc->recursive_verifier_native_accum.challenge = std::vector<FF>(Chonk::Flavor::VIRTUAL_LOG_N, FF::zero());
156 ivc->recursive_verifier_native_accum.non_shifted_evaluation = FF::zero();
157 ivc->recursive_verifier_native_accum.shifted_evaluation = FF::zero();
158 ivc->recursive_verifier_native_accum.non_shifted_commitment = Commitment::one();
159 ivc->recursive_verifier_native_accum.shifted_commitment = Commitment::one();
160
162 ivc->verification_queue.emplace_back(entry);
163 ivc->goblin.merge_verification_queue.emplace_back(acir_format::create_mock_merge_proof());
164 if (type == Chonk::QUEUE_TYPE::HN_FINAL) {
165 ivc->decider_proof = acir_format::create_mock_pcs_proof<Chonk::Flavor>();
166 }
167 ivc->num_circuits_accumulated++;
168}
169
170} // 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.
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)