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