Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pg_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// =====================
6
18#include "proof_surgeon.hpp"
20
21namespace acir_format {
22
23using namespace bb;
24
41 const TraceSettings& trace_settings)
42{
43 auto ivc = std::make_shared<ClientIVC>(constraints.size(), trace_settings);
44
45 uint32_t oink_type = static_cast<uint32_t>(PROOF_TYPE::OINK);
46 uint32_t pg_type = static_cast<uint32_t>(PROOF_TYPE::PG);
47 uint32_t pg_final_type = static_cast<uint32_t>(PROOF_TYPE::PG_FINAL);
48 uint32_t pg_tail_type = static_cast<uint32_t>(PROOF_TYPE::PG_TAIL);
49
50 // There is a fixed set of valid combinations of IVC recursion constraints for Aztec kernel circuits:
51
52 // Case: INIT kernel; single Oink recursive verification of an app
53 if (constraints.size() == 1 && constraints[0].proof_type == oink_type) {
54 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::OINK, /*is_kernel=*/false);
55 return ivc;
56 }
57
58 // Case: RESET kernel; single PG recursive verification of a kernel
59 if (constraints.size() == 1 && constraints[0].proof_type == pg_type) {
60 ivc->recursive_verifier_native_accum = create_mock_decider_vk<ClientIVC::Flavor>();
61 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG, /*is_kernel=*/true);
62 return ivc;
63 }
64
65 // Case: TAIL kernel; single PG recursive verification of a kernel
66 if (constraints.size() == 1 && constraints[0].proof_type == pg_tail_type) {
67 ivc->recursive_verifier_native_accum = create_mock_decider_vk<ClientIVC::Flavor>();
68 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG_TAIL, /*is_kernel=*/true);
69 return ivc;
70 }
71
72 // Case: INNER kernel; two PG recursive verifications, kernel and app in that order
73 if (constraints.size() == 2) {
74 BB_ASSERT_EQ(constraints[0].proof_type, pg_type);
75 BB_ASSERT_EQ(constraints[1].proof_type, pg_type);
76 ivc->recursive_verifier_native_accum = create_mock_decider_vk<ClientIVC::Flavor>();
77 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG, /*is_kernel=*/true);
78 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG, /*is_kernel=*/false);
79 return ivc;
80 }
81
82 // Case: HIDING kernel; single PG_FINAL recursive verification of a kernel
83 if (constraints.size() == 1 && constraints[0].proof_type == pg_final_type) {
84 ivc->recursive_verifier_native_accum = create_mock_decider_vk<ClientIVC::Flavor>();
85 mock_ivc_accumulation(ivc, ClientIVC::QUEUE_TYPE::PG_FINAL, /*is_kernel=*/true);
86 return ivc;
87 }
88
89 throw_or_abort("Invalid set of IVC recursion constraints!");
90 return ivc;
91}
92
99 const TraceSettings& trace_settings,
100 const bool is_kernel)
101{
102 using FF = ClientIVC::FF;
103 using MegaVerificationKey = ClientIVC::MegaVerificationKey;
105
106 // Use the trace settings to determine the correct dyadic size and the public inputs offset
108 blocks.set_fixed_block_sizes(trace_settings);
109 blocks.compute_offsets(/*is_structured=*/true);
110 size_t dyadic_size = blocks.get_structured_dyadic_size();
111 size_t pub_inputs_offset = blocks.pub_inputs.trace_offset();
112
113 // Construct a mock Oink or PG proof and a mock MegaHonk verification key
114 std::vector<FF> proof;
116
117 if (is_kernel) {
119 switch (verification_type) {
120 case ClientIVC::QUEUE_TYPE::OINK:
121 proof = create_mock_oink_proof<Flavor, KernelIO>();
122 break;
123 case ClientIVC::QUEUE_TYPE::PG:
124 case ClientIVC::QUEUE_TYPE::PG_FINAL:
125 case ClientIVC::QUEUE_TYPE::PG_TAIL:
126 proof = create_mock_pg_proof<Flavor, KernelIO>();
127 break;
128 default:
129 throw_or_abort("Invalid verification type! Only OINK, PG and PG_FINAL are supported");
130 }
131 verification_key = create_mock_honk_vk<Flavor, KernelIO>(dyadic_size, pub_inputs_offset);
132 } else {
134 switch (verification_type) {
135 case ClientIVC::QUEUE_TYPE::OINK:
136 proof = create_mock_oink_proof<Flavor, AppIO>();
137 break;
138 case ClientIVC::QUEUE_TYPE::PG:
139 proof = create_mock_pg_proof<Flavor, AppIO>();
140 break;
141 default:
142 throw_or_abort("Invalid verification type! Only OINK, PG and PG_FINAL are supported");
143 }
144 verification_key = create_mock_honk_vk<Flavor, AppIO>(dyadic_size, pub_inputs_offset);
145 }
146
147 return ClientIVC::VerifierInputs{ proof, verification_key, verification_type, is_kernel };
148}
149
158{
160 acir_format::create_mock_verification_queue_entry(type, ivc->trace_settings, is_kernel);
161 ivc->verification_queue.emplace_back(entry);
162 ivc->goblin.merge_verification_queue.emplace_back(acir_format::create_mock_merge_proof());
163 // If the type is PG_FINAL, we also need to populate the ivc instance with a mock decider proof
164 if (type == ClientIVC::QUEUE_TYPE::PG_FINAL) {
165 // we have to create a mock honk vk
166 ivc->honk_vk = entry.honk_vk;
167 ivc->decider_proof = acir_format::create_mock_decider_proof<ClientIVC::Flavor>();
168 }
169 ivc->num_circuits_accumulated++;
170}
171
180 const std::shared_ptr<MegaFlavor::VerificationKey>& mock_verification_key,
181 std::vector<uint32_t>& key_witness_indices)
182{
183 using FF = ClientIVC::FF;
184
185 // Convert the VerificationKey to fields
186 std::vector<FF> mock_vk_fields = mock_verification_key->to_field_elements();
187 BB_ASSERT_EQ(mock_vk_fields.size(), key_witness_indices.size());
188
189 // Add the fields to the witness and set the key witness indices accordingly
190 for (auto [witness_idx, value] : zip_view(key_witness_indices, mock_vk_fields)) {
191 builder.set_variable(witness_idx, value);
192 }
193}
194
195} // namespace acir_format
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
MegaFlavor Flavor
Flavor::FF FF
Flavor::VerificationKey MegaVerificationKey
void compute_offsets(bool is_structured)
void set_fixed_block_sizes(const TraceSettings &settings)
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:123
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
void mock_ivc_accumulation(const std::shared_ptr< ClientIVC > &ivc, ClientIVC::QUEUE_TYPE type, const bool is_kernel)
Populate an IVC instance with data that mimics the state after a single IVC accumulation (Oink or PG)
Goblin::MergeProof create_mock_merge_proof()
Create a mock merge proof which has the correct structure but is not necessarily valid.
std::shared_ptr< ClientIVC > create_mock_ivc_from_constraints(const std::vector< RecursionConstraint > &constraints, const TraceSettings &trace_settings)
Create an IVC object with mocked state corresponding to a set of IVC recursion constraints.
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.
ClientIVC::VerifierInputs create_mock_verification_queue_entry(const ClientIVC::QUEUE_TYPE verification_type, const TraceSettings &trace_settings, const bool is_kernel)
Create a mock verification queue entry with proof and VK that have the correct structure but are not ...
DefaultIO< MegaCircuitBuilder > AppIO
The data that is propagated on the public inputs of an application/function circuit.
Entry point for Barretenberg command-line interface.
typename Flavor::FF FF
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::shared_ptr< MegaVerificationKey > honk_vk
MegaTracePublicInputBlock pub_inputs
void throw_or_abort(std::string const &err)