Skip to content

Commit 467166f

Browse files
authored
chore: use public component key for pairing inputs (#13705)
Replaces `pairing_point_accumulator_public_input_indices` and `contains_pairing_point_accumulator` with a `PublicComponentKey` `pairing_inputs_public_input_key`. This reduces the number of field elements in a honk VK (all variants) by 16. (The old components are still used for Plonk so I couldn't remove them entirely yet).
1 parent e4e7fca commit 467166f

File tree

36 files changed

+2024
-2347
lines changed

36 files changed

+2024
-2347
lines changed

barretenberg/acir_tests/internal_test_programs/double_verify_honk_proof/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This circuit aggregates two Honk proof from `assert_statement`.
22
global SIZE_OF_PROOF_IF_LOGN_IS_28: u32 = 456;
33
global HONK_IDENTIFIER: u32 = 1;
4-
global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 128;
4+
global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 112;
55
fn main(
66
verification_key: [Field; HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS],
77
// This is the proof without public inputs attached.

barretenberg/acir_tests/internal_test_programs/verify_honk_proof/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This circuit aggregates a single Honk proof from `assert_statement`.
22
global SIZE_OF_PROOF_IF_LOGN_IS_28: u32 = 456;
33
global HONK_IDENTIFIER: u32 = 1;
4-
global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 128;
4+
global HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 112;
55
fn main(
66
verification_key: [Field; HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS],
77
// This is the proof without public inputs attached.

barretenberg/acir_tests/internal_test_programs/verify_rollup_honk_proof/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This circuit aggregates a single Honk proof from `assert_statement`.
22
global SIZE_OF_PROOF_IF_LOGN_IS_28: u32 = 466 + 69;
33
global ROLLUP_HONK_IDENTIFIER: u32 = 5;
4-
global ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 129;
4+
global ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS: u32 = 113;
55
fn main(
66
verification_key: [Field; ROLLUP_HONK_VERIFICATION_KEY_LENGTH_IN_FIELDS],
77
// This is the proof without public inputs attached.

barretenberg/cpp/src/barretenberg/dsl/acir_format/honk_recursion_constraint.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,21 @@ void create_dummy_vkey_and_proof(typename Flavor::CircuitBuilder& builder,
5555
ASSERT(proof_size == NativeFlavor::PROOF_LENGTH_WITHOUT_PUB_INPUTS);
5656
// Note: this computation should always result in log_circuit_size = CONST_PROOF_SIZE_LOG_N
5757
auto log_circuit_size = CONST_PROOF_SIZE_LOG_N;
58+
uint32_t offset = 0;
5859
// First key field is circuit size
59-
builder.assert_equal(builder.add_variable(1 << log_circuit_size), key_fields[0].witness_index);
60+
builder.assert_equal(builder.add_variable(1 << log_circuit_size), key_fields[offset++].witness_index);
6061
// Second key field is number of public inputs
61-
builder.assert_equal(builder.add_variable(public_inputs_size), key_fields[1].witness_index);
62+
builder.assert_equal(builder.add_variable(public_inputs_size), key_fields[offset++].witness_index);
6263
// Third key field is the pub inputs offset
63-
builder.assert_equal(builder.add_variable(NativeFlavor::has_zero_row ? 1 : 0), key_fields[2].witness_index);
64-
// Fourth key field is the whether the proof contains an aggregation object.
65-
builder.assert_equal(builder.add_variable(1), key_fields[3].witness_index);
66-
uint32_t offset = 4;
64+
builder.assert_equal(builder.add_variable(NativeFlavor::has_zero_row ? 1 : 0), key_fields[offset++].witness_index);
6765
size_t num_inner_public_inputs = public_inputs_size - bb::PAIRING_POINT_ACCUMULATOR_SIZE;
6866
if constexpr (HasIPAAccumulator<Flavor>) {
6967
num_inner_public_inputs -= bb::IPA_CLAIM_SIZE;
7068
}
7169

7270
// We are making the assumption that the pairing point object is behind all the inner public inputs
73-
for (size_t i = 0; i < bb::PAIRING_POINT_ACCUMULATOR_SIZE; i++) {
74-
builder.assert_equal(builder.add_variable(num_inner_public_inputs + i), key_fields[offset].witness_index);
75-
offset++;
76-
}
71+
builder.assert_equal(builder.add_variable(num_inner_public_inputs), key_fields[offset].witness_index);
72+
offset++;
7773

7874
if constexpr (HasIPAAccumulator<Flavor>) {
7975
// We are making the assumption that the IPA claim is behind the inner public inputs and pairing point object
@@ -207,10 +203,6 @@ void create_dummy_vkey_and_proof(typename Flavor::CircuitBuilder& builder,
207203
* @param input
208204
* @param input_aggregation_object_indices. The aggregation object coming from previous Honk recursion constraints.
209205
* @param has_valid_witness_assignment. Do we have witnesses or are we just generating keys?
210-
*
211-
* @note We currently only support HonkRecursionConstraint where inner_proof_contains_pairing_point_accumulator = false.
212-
* We would either need a separate ACIR opcode where inner_proof_contains_pairing_point_accumulator = true,
213-
* or we need non-witness data to be provided as metadata in the ACIR opcode
214206
*/
215207

216208
template <typename Flavor>

barretenberg/cpp/src/barretenberg/dsl/acir_format/ivc_recursion_constraint.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ std::shared_ptr<ClientIVC::MegaVerificationKey> create_mock_honk_vk(const size_t
199199
honk_verification_key->circuit_size = dyadic_size;
200200
honk_verification_key->num_public_inputs = num_public_inputs;
201201
honk_verification_key->pub_inputs_offset = pub_inputs_offset; // must be set correctly
202-
honk_verification_key->contains_pairing_point_accumulator = true;
203202

204203
for (auto& commitment : honk_verification_key->get_all()) {
205204
commitment = curve::BN254::AffineElement::one(); // arbitrary mock commitment

barretenberg/cpp/src/barretenberg/flavor/flavor.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "barretenberg/polynomials/evaluation_domain.hpp"
8484
#include "barretenberg/polynomials/univariate.hpp"
8585
#include "barretenberg/srs/global_crs.hpp"
86+
#include "barretenberg/stdlib_circuit_builders/public_component_key.hpp"
8687

8788
#include <array>
8889
#include <concepts>
@@ -127,8 +128,7 @@ struct ActiveRegionData {
127128
template <typename FF, typename CommitmentKey_> class ProvingKey_ {
128129
public:
129130
size_t circuit_size;
130-
bool contains_pairing_point_accumulator;
131-
PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices;
131+
PublicComponentKey pairing_inputs_public_input_key;
132132
bb::EvaluationDomain<FF> evaluation_domain;
133133
std::shared_ptr<CommitmentKey_> commitment_key;
134134
size_t num_public_inputs;
@@ -173,8 +173,7 @@ class VerificationKey_ : public PrecomputedCommitments {
173173
FF_ log_circuit_size;
174174
FF_ num_public_inputs;
175175
FF_ pub_inputs_offset = 0;
176-
bool contains_pairing_point_accumulator = false;
177-
PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices = {};
176+
PublicComponentKey pairing_inputs_public_input_key;
178177

179178
bool operator==(const VerificationKey_&) const = default;
180179
VerificationKey_() = default;
@@ -204,8 +203,7 @@ class VerificationKey_ : public PrecomputedCommitments {
204203
serialize_to_field_buffer(this->circuit_size, elements);
205204
serialize_to_field_buffer(this->num_public_inputs, elements);
206205
serialize_to_field_buffer(this->pub_inputs_offset, elements);
207-
serialize_to_field_buffer(this->contains_pairing_point_accumulator, elements);
208-
serialize_to_field_buffer(this->pairing_point_accumulator_public_input_indices, elements);
206+
serialize_to_field_buffer(this->pairing_inputs_public_input_key.start_idx, elements);
209207

210208
for (const Commitment& commitment : this->get_all()) {
211209
serialize_to_field_buffer(commitment, elements);

barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/ultra_recursive_verifier.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,9 @@ UltraRecursiveVerifier_<Flavor>::Output UltraRecursiveVerifier_<Flavor>::verify_
8787
gate_challenges[idx] = transcript->template get_challenge<FF>("Sumcheck:gate_challenge_" + std::to_string(idx));
8888
}
8989

90-
// Parse out the aggregation object using the key->pairing_point_accumulator_public_input_indices
91-
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1325): Eventually vk stores public input key directly.
92-
const PublicComponentKey pairing_point_public_input_key{ key->pairing_point_accumulator_public_input_indices[0] };
90+
// Extract the aggregation object from the public inputs
9391
AggregationObject nested_agg_obj =
94-
PublicAggState::reconstruct(verification_key->public_inputs, pairing_point_public_input_key);
92+
PublicAggState::reconstruct(verification_key->public_inputs, key->pairing_inputs_public_input_key);
9593
// TODO(https://github.com/AztecProtocol/barretenberg/issues/995): generate this challenge properly.
9694
typename Curve::ScalarField recursion_separator =
9795
Curve::ScalarField::from_witness_index(builder, builder->add_variable(42));

barretenberg/cpp/src/barretenberg/stdlib/plonk_recursion/aggregation_state/aggregation_state.hpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,7 @@ template <typename Builder_> struct aggregation_state {
115115
P1.set_public();
116116

117117
Builder* ctx = P0.get_context();
118-
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1325): Eventually the builder/PK/VK will store
119-
// public input key which should be set here and pairing_point_accumulator_public_input_indices should go away.
120-
uint32_t pub_idx = start_idx;
121-
for (uint32_t& idx : ctx->pairing_point_accumulator_public_input_indices) {
122-
idx = pub_idx++;
123-
}
124-
ctx->contains_pairing_point_accumulator = true;
118+
ctx->pairing_inputs_public_input_key.start_idx = start_idx;
125119

126120
return start_idx;
127121
}

barretenberg/cpp/src/barretenberg/stdlib/primitives/public_input_component/public_input_component.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ class PublicInputComponent {
6060
{
6161
// Ensure that the key has been set
6262
if (!key.is_set()) {
63-
// TODO(https://github.com/AztecProtocol/barretenberg/issues/1284): determine when/whether a check of this
64-
// form is needed: info("WARNING: Trying to construct a PublicInputComponent from an invalid key!");
65-
// ASSERT(false);
63+
info("WARNING: Trying to construct a PublicInputComponent from an invalid key!");
64+
ASSERT(false);
6665
}
6766

6867
// Use the provided key to extract the limbs of the component from the public inputs then reconstruct it

barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/recursive_decider_verification_key.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ {
110110
static_cast<uint64_t>(verification_key->circuit_size.get_value()),
111111
static_cast<uint64_t>(verification_key->num_public_inputs.get_value()));
112112
native_honk_vk->pub_inputs_offset = static_cast<uint64_t>(verification_key->pub_inputs_offset.get_value());
113-
native_honk_vk->contains_pairing_point_accumulator = verification_key->contains_pairing_point_accumulator;
114-
native_honk_vk->pairing_point_accumulator_public_input_indices =
115-
verification_key->pairing_point_accumulator_public_input_indices;
113+
native_honk_vk->pairing_inputs_public_input_key = verification_key->pairing_inputs_public_input_key;
116114
if constexpr (IsMegaFlavor<Flavor>) {
117115
native_honk_vk->databus_propagation_data = verification_key->databus_propagation_data;
118116
}

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ template <typename FF_> class CircuitBuilderBase {
4545
// DOCTODO(#231): replace with the relevant wiki link.
4646
std::map<uint32_t, uint32_t> tau;
4747

48-
// Public input indices which contain recursive proof information
48+
// (PLONK ONLY) Public input indices which contain recursive proof information
4949
PairingPointAccumulatorPubInputIndices pairing_point_accumulator_public_input_indices;
5050
bool contains_pairing_point_accumulator = false;
5151

52+
// Index of the pairing inputs in the public inputs
53+
PublicComponentKey pairing_inputs_public_input_key;
54+
5255
// Index of the IPA opening claim in the public inputs
5356
PublicComponentKey ipa_claim_public_input_key;
5457

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ class MegaFlavor {
449449
this->log_circuit_size = numeric::get_msb(this->circuit_size);
450450
this->num_public_inputs = proving_key.num_public_inputs;
451451
this->pub_inputs_offset = proving_key.pub_inputs_offset;
452-
this->contains_pairing_point_accumulator = proving_key.contains_pairing_point_accumulator;
453-
this->pairing_point_accumulator_public_input_indices =
454-
proving_key.pairing_point_accumulator_public_input_indices;
452+
this->pairing_inputs_public_input_key = proving_key.pairing_inputs_public_input_key;
455453

456454
// Databus commitment propagation data
457455
this->databus_propagation_data = proving_key.databus_propagation_data;
@@ -486,8 +484,7 @@ class MegaFlavor {
486484
serialize_to_field_buffer(this->circuit_size, elements);
487485
serialize_to_field_buffer(this->num_public_inputs, elements);
488486
serialize_to_field_buffer(this->pub_inputs_offset, elements);
489-
serialize_to_field_buffer(this->contains_pairing_point_accumulator, elements);
490-
serialize_to_field_buffer(this->pairing_point_accumulator_public_input_indices, elements);
487+
serialize_to_field_buffer(this->pairing_inputs_public_input_key.start_idx, elements);
491488

492489
serialize_to_field_buffer(this->databus_propagation_data.app_return_data_commitment_pub_input_key.start_idx,
493490
elements);
@@ -507,8 +504,7 @@ class MegaFlavor {
507504
VerificationKey(const size_t circuit_size,
508505
const size_t num_public_inputs,
509506
const size_t pub_inputs_offset,
510-
const bool contains_pairing_point_accumulator,
511-
const PairingPointAccumulatorPubInputIndices& pairing_point_accumulator_public_input_indices,
507+
const PublicComponentKey& pairing_inputs_public_input_key,
512508
const DatabusPropagationData& databus_propagation_data,
513509
const Commitment& q_m,
514510
const Commitment& q_c,
@@ -545,8 +541,7 @@ class MegaFlavor {
545541
this->log_circuit_size = numeric::get_msb(this->circuit_size);
546542
this->num_public_inputs = num_public_inputs;
547543
this->pub_inputs_offset = pub_inputs_offset;
548-
this->contains_pairing_point_accumulator = contains_pairing_point_accumulator;
549-
this->pairing_point_accumulator_public_input_indices = pairing_point_accumulator_public_input_indices;
544+
this->pairing_inputs_public_input_key = pairing_inputs_public_input_key;
550545
this->databus_propagation_data = databus_propagation_data;
551546
this->q_m = q_m;
552547
this->q_c = q_c;
@@ -583,8 +578,7 @@ class MegaFlavor {
583578
log_circuit_size,
584579
num_public_inputs,
585580
pub_inputs_offset,
586-
contains_pairing_point_accumulator,
587-
pairing_point_accumulator_public_input_indices,
581+
pairing_inputs_public_input_key,
588582
databus_propagation_data,
589583
q_m,
590584
q_c,

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_recursive_flavor.hpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ template <typename BuilderType> class MegaRecursiveFlavor_ {
131131
this->log_circuit_size = FF::from_witness(builder, numeric::get_msb(native_key->circuit_size));
132132
this->num_public_inputs = FF::from_witness(builder, native_key->num_public_inputs);
133133
this->pub_inputs_offset = FF::from_witness(builder, native_key->pub_inputs_offset);
134-
this->contains_pairing_point_accumulator = native_key->contains_pairing_point_accumulator;
135-
this->pairing_point_accumulator_public_input_indices =
136-
native_key->pairing_point_accumulator_public_input_indices;
134+
this->pairing_inputs_public_input_key = native_key->pairing_inputs_public_input_key;
137135
this->databus_propagation_data = native_key->databus_propagation_data;
138136

139137
// Generate stdlib commitments (biggroup) from the native counterparts
@@ -159,12 +157,9 @@ template <typename BuilderType> class MegaRecursiveFlavor_ {
159157
this->log_circuit_size = numeric::get_msb(static_cast<uint32_t>(this->circuit_size.get_value()));
160158
this->num_public_inputs = deserialize_from_frs<FF>(builder, elements, num_frs_read);
161159
this->pub_inputs_offset = deserialize_from_frs<FF>(builder, elements, num_frs_read);
162-
this->contains_pairing_point_accumulator =
163-
bool(deserialize_from_frs<FF>(builder, elements, num_frs_read).get_value());
164160

165-
for (uint32_t& idx : this->pairing_point_accumulator_public_input_indices) {
166-
idx = uint32_t(deserialize_from_frs<FF>(builder, elements, num_frs_read).get_value());
167-
}
161+
this->pairing_inputs_public_input_key.start_idx =
162+
uint32_t(deserialize_from_frs<FF>(builder, elements, num_frs_read).get_value());
168163

169164
this->databus_propagation_data.app_return_data_commitment_pub_input_key.start_idx =
170165
uint32_t(deserialize_from_frs<FF>(builder, elements, num_frs_read).get_value());

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/public_component_key.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace bb {
1313
// The data needed to reconstruct a public input component from its limbs stored in the public inputs
1414
struct PublicComponentKey {
1515
constexpr static uint32_t DEFAULT_IDX = std::numeric_limits<uint32_t>::max();
16+
1617
uint32_t start_idx = DEFAULT_IDX; // start index within public inputs array
1718

1819
bool operator==(const PublicComponentKey&) const = default;

barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,7 @@ class UltraFlavor {
370370
this->log_circuit_size = numeric::get_msb(this->circuit_size);
371371
this->num_public_inputs = proving_key.num_public_inputs;
372372
this->pub_inputs_offset = proving_key.pub_inputs_offset;
373-
this->contains_pairing_point_accumulator = proving_key.contains_pairing_point_accumulator;
374-
this->pairing_point_accumulator_public_input_indices =
375-
proving_key.pairing_point_accumulator_public_input_indices;
373+
this->pairing_inputs_public_input_key = proving_key.pairing_inputs_public_input_key;
376374

377375
if (proving_key.commitment_key == nullptr) {
378376
proving_key.commitment_key = std::make_shared<CommitmentKey>(proving_key.circuit_size);
@@ -386,8 +384,7 @@ class UltraFlavor {
386384
VerificationKey(const uint64_t circuit_size,
387385
const uint64_t num_public_inputs,
388386
const uint64_t pub_inputs_offset,
389-
const bool contains_pairing_point_accumulator,
390-
const PairingPointAccumulatorPubInputIndices& pairing_point_accumulator_public_input_indices,
387+
const PublicComponentKey& pairing_inputs_public_input_key,
391388
const Commitment& q_m,
392389
const Commitment& q_c,
393390
const Commitment& q_l,
@@ -420,8 +417,7 @@ class UltraFlavor {
420417
this->log_circuit_size = numeric::get_msb(this->circuit_size);
421418
this->num_public_inputs = num_public_inputs;
422419
this->pub_inputs_offset = pub_inputs_offset;
423-
this->contains_pairing_point_accumulator = contains_pairing_point_accumulator;
424-
this->pairing_point_accumulator_public_input_indices = pairing_point_accumulator_public_input_indices;
420+
this->pairing_inputs_public_input_key = pairing_inputs_public_input_key;
425421
this->q_m = q_m;
426422
this->q_c = q_c;
427423
this->q_l = q_l;
@@ -456,8 +452,7 @@ class UltraFlavor {
456452
log_circuit_size,
457453
num_public_inputs,
458454
pub_inputs_offset,
459-
contains_pairing_point_accumulator,
460-
pairing_point_accumulator_public_input_indices,
455+
pairing_inputs_public_input_key,
461456
q_m,
462457
q_c,
463458
q_l,

0 commit comments

Comments
 (0)