Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
honk_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
22#include "proof_surgeon.hpp"
24
25#include <cstddef>
26
27namespace acir_format {
28
29using namespace bb;
30using namespace bb::stdlib::recursion::honk;
31template <typename Builder> using field_ct = stdlib::field_t<Builder>;
32template <typename Builder> using bn254 = stdlib::bn254<Builder>;
33template <typename Builder> using PairingPoints = bb::stdlib::recursion::PairingPoints<Builder>;
34
35namespace {
48template <typename Flavor>
50 size_t proof_size,
51 size_t public_inputs_size,
52 const std::vector<field_ct<typename Flavor::CircuitBuilder>>& key_fields,
53 const std::vector<field_ct<typename Flavor::CircuitBuilder>>& proof_fields)
54 requires IsRecursiveFlavor<Flavor>
55{
56 using Builder = typename Flavor::CircuitBuilder;
57 using NativeFlavor = typename Flavor::NativeFlavor;
61
62 // Set vkey->circuit_size correctly based on the proof size
63 BB_ASSERT_EQ(proof_size, NativeFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS());
64
65 size_t num_inner_public_inputs = public_inputs_size - IO::PUBLIC_INPUTS_SIZE;
66 uint32_t pub_inputs_offset = NativeFlavor::has_zero_row ? 1 : 0;
67
68 // Generate mock honk vk
69 auto honk_vk = create_mock_honk_vk<typename Flavor::NativeFlavor, IO>(
70 1 << Flavor::VIRTUAL_LOG_N, pub_inputs_offset, num_inner_public_inputs);
71
72 size_t offset = 0;
73
74 // Set honk vk in builder
75 for (auto& vk_element : honk_vk->to_field_elements()) {
76 builder.set_variable(key_fields[offset].witness_index, vk_element);
77 offset++;
78 }
79
80 // Generate dummy honk proof
81 bb::HonkProof honk_proof = create_mock_honk_proof<typename Flavor::NativeFlavor, IO>(num_inner_public_inputs);
82
83 offset = 0;
84 // Set honk proof in builder
85 for (auto& proof_element : honk_proof) {
86 builder.set_variable(proof_fields[offset].witness_index, proof_element);
87 offset++;
88 }
89
90 BB_ASSERT_EQ(offset, proof_size + public_inputs_size);
91}
92} // namespace
93
103template <typename Flavor>
105 typename Flavor::CircuitBuilder& builder, const RecursionConstraint& input, bool has_valid_witness_assignments)
106 requires(IsRecursiveFlavor<Flavor> && IsUltraHonk<typename Flavor::NativeFlavor>)
107{
108 using Builder = typename Flavor::CircuitBuilder;
109 using RecursiveVerificationKey = Flavor::VerificationKey;
110 using RecursiveVKAndHash = Flavor::VKAndHash;
115
116 ASSERT(input.proof_type == HONK || input.proof_type == HONK_ZK || HasIPAAccumulator<Flavor>);
117 BB_ASSERT_EQ(input.proof_type == ROLLUP_HONK || input.proof_type == ROOT_ROLLUP_HONK, HasIPAAccumulator<Flavor>);
118
119 // Construct an in-circuit representation of the verification key.
120 // For now, the v-key is a circuit constant and is fixed for the circuit.
121 // (We may need a separate recursion opcode for this to vary, or add more config witnesses to this opcode)
123
124 // Create circuit type for vkey hash.
125 auto vk_hash = field_ct<Builder>::from_witness_index(&builder, input.key_hash);
126
127 // Create witness indices for the proof with public inputs reinserted
128 std::vector<uint32_t> proof_indices =
131
132 // Populate the key fields and proof fields with dummy values to prevent issues (e.g. points must be on curve).
133 if (!has_valid_witness_assignments) {
134 // In the constraint, the agg object public inputs are still contained in the proof. To get the 'raw' size of
135 // the proof and public_inputs we subtract and add the corresponding amount from the respective sizes.
136 size_t size_of_proof_with_no_pub_inputs = input.proof.size() - IO::PUBLIC_INPUTS_SIZE;
137 size_t total_num_public_inputs = input.public_inputs.size() + IO::PUBLIC_INPUTS_SIZE;
138
139 create_dummy_vkey_and_proof<Flavor>(
140 builder, size_of_proof_with_no_pub_inputs, total_num_public_inputs, key_fields, proof_fields);
141 }
142
143 // Recursively verify the proof
145 auto vk_and_hash = std::make_shared<RecursiveVKAndHash>(vkey, vk_hash);
146 RecursiveVerifier verifier(&builder, vk_and_hash);
147 UltraRecursiveVerifierOutput<Builder> verifier_output = verifier.template verify_proof<IO>(proof_fields);
148 // TODO(https://github.com/AztecProtocol/barretenberg/issues/996): investigate whether assert_equal on public inputs
149 // is important, like what the plonk recursion constraint does.
150 return verifier_output;
151}
152
155 const RecursionConstraint& input,
156 bool has_valid_witness_assignments);
157
160 const RecursionConstraint& input,
161 bool has_valid_witness_assignments);
162
165 const RecursionConstraint& input,
166 bool has_valid_witness_assignments);
167
170 const RecursionConstraint& input,
171 bool has_valid_witness_assignments);
172
175 const RecursionConstraint& input,
176 bool has_valid_witness_assignments);
177
178} // namespace acir_format
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:59
#define ASSERT(expression,...)
Definition assert.hpp:49
static std::vector< uint32_t > create_indices_for_reconstructed_proof(const std::vector< uint32_t > &proof_in, const std::vector< uint32_t > &public_inputs)
Reconstruct a bberg style proof from a acir style proof + public inputs.
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
MegaCircuitBuilder CircuitBuilder
static constexpr size_t VIRTUAL_LOG_N
An object storing two bn254 points that represent the inputs to a pairing check.
The recursive counterpart to the "native" Ultra flavor.
The recursive counterpart to the "native" UltraRollupFlavor.
The recursive counterpart to the Ultra flavor with ZK.
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
Definition field.cpp:59
Manages the data that is propagated on the public inputs of an application/function circuit.
The data that is propagated on the public inputs of a rollup circuit.
AluTraceBuilder builder
Definition alu.test.cpp:123
ssize_t offset
Definition engine.cpp:36
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
void create_dummy_vkey_and_proof(Builder &builder, size_t proof_size, size_t public_inputs_size, const std::vector< field_ct > &key_fields, const std::vector< field_ct > &proof_fields)
Creates a dummy vkey and proof object.
HonkRecursionConstraintOutput< typename Flavor::CircuitBuilder > create_honk_recursion_constraints(typename Flavor::CircuitBuilder &builder, const RecursionConstraint &input, bool has_valid_witness_assignments)
Add constraints required to recursively verify an UltraHonk proof.
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
Definition proof.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
RecursionConstraint struct contains information required to recursively verify a proof!
static std::vector< bb::stdlib::field_t< Builder > > fields_from_witnesses(Builder &builder, const std::vector< uint32_t > &witness_indices)
An object storing two EC points that represent the inputs to a pairing check.