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: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
17#include "proof_surgeon.hpp"
19
20namespace acir_format {
21
22using namespace bb;
23
40{
41 auto ivc = std::make_shared<Chonk>(constraints.size());
42
43 uint32_t oink_type = static_cast<uint32_t>(PROOF_TYPE::OINK);
44 uint32_t hn_type = static_cast<uint32_t>(PROOF_TYPE::HN);
45 uint32_t hn_final_type = static_cast<uint32_t>(PROOF_TYPE::HN_FINAL);
46 uint32_t hn_tail_type = static_cast<uint32_t>(PROOF_TYPE::HN_TAIL);
47
48 // There is a fixed set of valid combinations of IVC recursion constraints for Aztec kernel circuits:
49
50 // Case: INIT kernel; single Oink recursive verification of an app
51 if (constraints.size() == 1 && constraints[0].proof_type == oink_type) {
52 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::OINK, /*is_kernel=*/false);
53 return ivc;
54 }
55
56 // Case: RESET kernel; single HN recursive verification of a kernel
57 if (constraints.size() == 1 && constraints[0].proof_type == hn_type) {
58 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
59 return ivc;
60 }
61
62 // Case: TAIL kernel; single HN recursive verification of a kernel
63 if (constraints.size() == 1 && constraints[0].proof_type == hn_tail_type) {
64 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_TAIL, /*is_kernel=*/true);
65 return ivc;
66 }
67 if (constraints.size() == 2) {
68 BB_ASSERT_EQ(constraints[0].proof_type, hn_type);
69 BB_ASSERT_EQ(constraints[1].proof_type, hn_type);
70 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/true);
71 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN, /*is_kernel=*/false);
72 return ivc;
73 }
74
75 // Case: HIDING kernel; single HN_FINAL recursive verification of a kernel
76 if (constraints.size() == 1 && constraints[0].proof_type == hn_final_type) {
77 mock_chonk_accumulation(ivc, Chonk::QUEUE_TYPE::HN_FINAL, /*is_kernel=*/true);
78 return ivc;
79 }
80
81 throw_or_abort("Invalid set of IVC recursion constraints!");
82 return ivc;
83}
84
91 const bool is_kernel)
92{
93 using IvcType = Chonk;
94 using FF = IvcType::FF;
95 using MegaVerificationKey = IvcType::MegaVerificationKey;
96 using Flavor = IvcType::Flavor;
97
98 size_t dyadic_size = 1 << Flavor::VIRTUAL_LOG_N; // maybe doesnt need to be correct
99 size_t pub_inputs_offset = Flavor::has_zero_row ? 1 : 0; // always 1
100
101 // Construct a mock Oink or HN proof and a mock MegaHonk verification key
102 std::vector<FF> proof;
104
105 if (is_kernel) {
107 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::HN || verification_type == Chonk::QUEUE_TYPE::HN_TAIL ||
108 verification_type == Chonk::QUEUE_TYPE::HN_FINAL,
109 true);
110
111 // kernel circuits are always folded, thus the proof always includes the nova fold proof
112 bool include_fold = true;
113 proof = create_mock_hyper_nova_proof<Flavor, KernelIO>(include_fold);
114
115 verification_key = create_mock_honk_vk<Flavor, KernelIO>(dyadic_size, pub_inputs_offset);
116 } else {
118 BB_ASSERT_EQ(verification_type == Chonk::QUEUE_TYPE::OINK || verification_type == Chonk::QUEUE_TYPE::HN, true);
119
120 // The first app is not folded thus the proof does not include the nova fold proof
121 bool include_fold = !(verification_type == Chonk::QUEUE_TYPE::OINK);
122 proof = create_mock_hyper_nova_proof<Flavor, AppIO>(include_fold);
123
124 verification_key = create_mock_honk_vk<Flavor, AppIO>(dyadic_size, pub_inputs_offset);
125 }
126
127 return Chonk::VerifierInputs{ proof, verification_key, verification_type, is_kernel };
128}
129
140{
141 using FF = Chonk::FF;
142 using Commitment = Chonk::Commitment;
143
144 // Initialize verifier accumulator with proper structure
145 ivc->recursive_verifier_native_accum.challenge = std::vector<FF>(Chonk::Flavor::VIRTUAL_LOG_N, FF::zero());
146 ivc->recursive_verifier_native_accum.non_shifted_evaluation = FF::zero();
147 ivc->recursive_verifier_native_accum.shifted_evaluation = FF::zero();
148 ivc->recursive_verifier_native_accum.non_shifted_commitment = Commitment::one();
149 ivc->recursive_verifier_native_accum.shifted_commitment = Commitment::one();
150
152 ivc->verification_queue.emplace_back(entry);
153 ivc->goblin.merge_verification_queue.emplace_back(acir_format::create_mock_merge_proof());
154 if (type == Chonk::QUEUE_TYPE::HN_FINAL) {
155 ivc->decider_proof = acir_format::create_mock_pcs_proof<Chonk::Flavor>();
156 }
157 ivc->num_circuits_accumulated++;
158}
159
168 const std::shared_ptr<MegaFlavor::VerificationKey>& mock_verification_key,
169 std::vector<uint32_t>& key_witness_indices)
170{
171 using FF = Chonk::FF;
172
173 // Convert the VerificationKey to fields
174 std::vector<FF> mock_vk_fields = mock_verification_key->to_field_elements();
175 BB_ASSERT_EQ(mock_vk_fields.size(), key_witness_indices.size());
176
177 // Add the fields to the witness and set the key witness indices accordingly
178 for (auto [witness_idx, value] : zip_view(key_witness_indices, mock_vk_fields)) {
179 builder.set_variable(witness_idx, value);
180 }
181}
182
183} // namespace acir_format
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:77
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
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.
AluTraceBuilder builder
Definition alu.test.cpp:124
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 an IVC object 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 proof and VK that have the correct structure but are not ...
void populate_dummy_vk_in_constraint(MegaCircuitBuilder &builder, const std::shared_ptr< MegaFlavor::VerificationKey > &mock_verification_key, std::vector< uint32_t > &key_witness_indices)
Populate VK witness fields from a recursion constraint from a provided VerificationKey.
void mock_chonk_accumulation(const std::shared_ptr< Chonk > &ivc, Chonk::QUEUE_TYPE type, const bool is_kernel)
Populate an IVC instance with data that mimics the state after a single IVC accumulation.
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
void throw_or_abort(std::string const &err)