Skip to content

Commit ec2df16

Browse files
ledwards2225AztecBot
andauthored
chore: simplify is_accum (#16291)
Simplify some PG state, including the `is_accumulator` flag which was serving two purposes for the prover and was not really needed at all for the verifier. Both prover and verifier now have `is_complete` which indicates whether the instance has been "oinked" i.e. completed --------- Co-authored-by: AztecBot <tech@aztecprotocol.com>
1 parent 062ed4e commit ec2df16

12 files changed

Lines changed: 36 additions & 45 deletions

barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ std::pair<ClientIVC::PairingPoints, ClientIVC::TableCommitments> ClientIVC::
139139
// Perform oink recursive verification to complete the initial verifier accumulator
140140
OinkRecursiveVerifier verifier{ &circuit, verifier_accum, accumulation_recursive_transcript };
141141
verifier.verify_proof(verifier_inputs.proof);
142-
verifier_accum->is_accumulator = true; // indicate to PG that it should not run oink
143142

144143
// Extract native verifier accumulator from the stdlib accum for use on the next round
145144
recursive_verifier_native_accum = std::make_shared<DeciderVerificationKey>(verifier_accum->get_value());
@@ -339,9 +338,6 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVer
339338
oink_prover.prove();
340339
HonkProof oink_proof = oink_prover.export_proof();
341340
vinfo("oink proof constructed");
342-
proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key
343-
// Initialize the gate challenges to zero for use in first round of folding
344-
proving_key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
345341

346342
fold_output.accumulator = proving_key; // initialize the prover accum with the completed key
347343

@@ -350,7 +346,6 @@ void ClientIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<MegaVer
350346
OinkVerifier<Flavor> oink_verifier{ decider_vk, oink_verifier_transcript };
351347
oink_verifier.verify();
352348
native_verifier_accum = decider_vk;
353-
native_verifier_accum->is_accumulator = true;
354349
native_verifier_accum->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
355350

356351
queue_entry.type = QUEUE_TYPE::OINK;

barretenberg/cpp/src/barretenberg/dsl/acir_format/mock_verifier_inputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ template <typename Flavor> std::shared_ptr<DeciderVerificationKey_<Flavor>> crea
224224
create_mock_honk_vk<Flavor, stdlib::recursion::honk::DefaultIO<typename Flavor::CircuitBuilder>>(
225225
0, 0); // metadata does not need to be accurate
226226
decider_verification_key->vk = vk;
227-
decider_verification_key->is_accumulator = true;
227+
decider_verification_key->is_complete = true;
228228
decider_verification_key->gate_challenges = std::vector<FF>(static_cast<size_t>(CONST_PG_LOG_N), 0);
229229

230230
for (auto& commitment : decider_verification_key->witness_commitments.get_all()) {

barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ void ProtogalaxyProver_<Flavor, NUM_KEYS>::run_oink_prover_on_each_incomplete_ke
3333
auto& key = keys_to_fold[0];
3434
auto domain_separator = std::to_string(idx);
3535
auto& verifier_accum = vks_to_fold[0];
36-
if (!key->is_accumulator) {
36+
if (!key->is_complete) {
3737
run_oink_prover_on_one_incomplete_key(key, verifier_accum, domain_separator);
38-
key->target_sum = 0;
39-
key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
4038
} else {
4139
// Fiat-Shamir the verifier accumulator
4240
FF accum_hash = verifier_accum->add_hash_to_transcript("", *transcript);

barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ void ProtogalaxyVerifier_<DeciderVerificationKeys>::run_oink_verifier_on_each_in
1919
transcript->load_proof(proof);
2020
auto key = keys_to_fold[0];
2121
auto domain_separator = std::to_string(0);
22-
if (!key->is_accumulator) {
22+
if (!key->is_complete) {
2323
OinkVerifier<Flavor> oink_verifier{ key, transcript, domain_separator + '_' };
2424
oink_verifier.verify();
25-
key->target_sum = 0;
2625
key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
2726
} else {
2827
// Fiat-Shamir the verifier accumulator
@@ -73,8 +72,11 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyVerifier
7372
{
7473
static constexpr size_t BATCHED_EXTENDED_LENGTH = DeciderVerificationKeys::BATCHED_EXTENDED_LENGTH;
7574
static constexpr size_t NUM_KEYS = DeciderVerificationKeys::NUM;
75+
// The degree of the combiner quotient (K in the paper) is dk - k - 1 = k(d - 1) - 1.
76+
// Hence we need k(d - 1) evaluations to represent it.
77+
static constexpr size_t COMBINER_LENGTH = BATCHED_EXTENDED_LENGTH - NUM_KEYS;
7678

77-
const std::shared_ptr<const DeciderVK>& accumulator = keys_to_fold[0];
79+
const std::shared_ptr<DeciderVK>& accumulator = keys_to_fold[0];
7880

7981
run_oink_verifier_on_each_incomplete_key(proof);
8082

@@ -92,9 +94,7 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyVerifier
9294
const Polynomial<FF> perturbator(perturbator_coeffs);
9395
const FF perturbator_evaluation = perturbator.evaluate(perturbator_challenge);
9496

95-
std::array<FF, BATCHED_EXTENDED_LENGTH - NUM_KEYS>
96-
combiner_quotient_evals; // The degree of the combiner quotient (K in the paper) is dk - k - 1 = k(d - 1) - 1.
97-
// Hence we need k(d - 1) evaluations to represent it.
97+
std::array<FF, COMBINER_LENGTH> combiner_quotient_evals;
9898
for (size_t idx = DeciderVerificationKeys::NUM; auto& val : combiner_quotient_evals) {
9999
val = transcript->template receive_from_prover<FF>("combiner_quotient_" + std::to_string(idx++));
100100
}
@@ -104,42 +104,38 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyVerifier
104104
const Univariate<FF, BATCHED_EXTENDED_LENGTH, NUM_KEYS> combiner_quotient(combiner_quotient_evals);
105105
const FF combiner_quotient_evaluation = combiner_quotient.evaluate(combiner_challenge);
106106

107-
auto next_accumulator = std::make_shared<DeciderVK>();
108-
next_accumulator->vk = std::make_shared<VerificationKey>(*accumulator->vk);
109-
next_accumulator->is_accumulator = true;
110-
111107
// Set the accumulator circuit size data based on the max of the keys being accumulated
112108
const size_t accumulator_log_circuit_size = keys_to_fold.get_max_log_circuit_size();
113-
next_accumulator->vk->log_circuit_size = accumulator_log_circuit_size;
109+
accumulator->vk->log_circuit_size = accumulator_log_circuit_size;
114110

115111
// Compute next folding parameters
116112
const auto [vanishing_polynomial_at_challenge, lagranges] =
117113
compute_vanishing_polynomial_and_lagrange_evaluations<FF, NUM_KEYS>(combiner_challenge);
118-
next_accumulator->target_sum =
114+
accumulator->target_sum =
119115
perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_evaluation;
120-
next_accumulator->gate_challenges = // note: known already in previous round
116+
accumulator->gate_challenges = // note: known already in previous round
121117
update_gate_challenges(perturbator_challenge, accumulator->gate_challenges, deltas);
122118

123119
// // Fold the commitments
124120
for (auto [combination, to_combine] :
125-
zip_view(next_accumulator->vk->get_all(), keys_to_fold.get_precomputed_commitments())) {
121+
zip_view(accumulator->vk->get_all(), keys_to_fold.get_precomputed_commitments())) {
126122
combination = batch_mul_native(to_combine, lagranges);
127123
}
128124
for (auto [combination, to_combine] :
129-
zip_view(next_accumulator->witness_commitments.get_all(), keys_to_fold.get_witness_commitments())) {
125+
zip_view(accumulator->witness_commitments.get_all(), keys_to_fold.get_witness_commitments())) {
130126
combination = batch_mul_native(to_combine, lagranges);
131127
}
132128

133129
// Fold the relation parameters
134-
for (auto [combination, to_combine] : zip_view(next_accumulator->alphas, keys_to_fold.get_alphas())) {
130+
for (auto [combination, to_combine] : zip_view(accumulator->alphas, keys_to_fold.get_alphas())) {
135131
combination = linear_combination(to_combine, lagranges);
136132
}
137133
for (auto [combination, to_combine] :
138-
zip_view(next_accumulator->relation_parameters.get_to_fold(), keys_to_fold.get_relation_parameters())) {
134+
zip_view(accumulator->relation_parameters.get_to_fold(), keys_to_fold.get_relation_parameters())) {
139135
combination = linear_combination(to_combine, lagranges);
140136
}
141137

142-
return next_accumulator;
138+
return accumulator;
143139
}
144140

145141
template class ProtogalaxyVerifier_<DeciderVerificationKeys_<MegaFlavor, 2>>;

barretenberg/cpp/src/barretenberg/stdlib/honk_verifier/oink_recursive_verifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ template <typename Flavor> void OinkRecursiveVerifier_<Flavor>::verify()
127127
RelationParameters<FF>{ eta, eta_two, eta_three, beta, gamma, public_input_delta };
128128
decider_vk->witness_commitments = std::move(commitments);
129129
decider_vk->alphas = std::move(alphas);
130+
decider_vk->is_complete = true; // instance has been completely populated
130131
}
131132

132133
template class OinkRecursiveVerifier_<bb::UltraRecursiveFlavor_<UltraCircuitBuilder>>;

barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ void ProtogalaxyRecursiveVerifier_<DeciderVerificationKeys>::run_oink_verifier_o
2121
transcript->load_proof(proof);
2222
auto key = keys_to_fold[0];
2323
auto domain_separator = std::to_string(0);
24-
if (!key->is_accumulator) {
24+
if (!key->is_complete) {
2525
OinkRecursiveVerifier_<Flavor> oink_verifier{ builder, key, transcript, domain_separator + '_' };
2626
oink_verifier.verify();
27-
key->target_sum = 0;
2827
key->gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
2928
} else {
3029
// Fiat-Shamir the accumulator.
@@ -47,11 +46,13 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyRecursiv
4746
{
4847
static constexpr size_t BATCHED_EXTENDED_LENGTH = DeciderVerificationKeys::BATCHED_EXTENDED_LENGTH;
4948
static constexpr size_t NUM_KEYS = DeciderVerificationKeys::NUM;
49+
// The degree of the combiner quotient (K in the paper) is dk - k - 1 = k(d - 1) - 1.
50+
// Hence we need k(d - 1) evaluations to represent it.
5051
static constexpr size_t COMBINER_LENGTH = BATCHED_EXTENDED_LENGTH - NUM_KEYS;
5152

5253
run_oink_verifier_on_each_incomplete_key(proof);
5354

54-
std::shared_ptr<DeciderVK> accumulator = keys_to_fold[0];
55+
const std::shared_ptr<DeciderVK>& accumulator = keys_to_fold[0];
5556

5657
// Perturbator round
5758
const FF delta = transcript->template get_challenge<FF>("delta");
@@ -66,9 +67,7 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyRecursiv
6667
perturbator_coeffs[0] = accumulator->target_sum;
6768
const FF perturbator_evaluation = evaluate_perturbator(perturbator_coeffs, perturbator_challenge);
6869

69-
std::array<FF, COMBINER_LENGTH>
70-
combiner_quotient_evals; // The degree of the combiner quotient (K in the paper) is dk - k - 1 = k(d - 1)
71-
// - 1. Hence we need k(d - 1) evaluations to represent it.
70+
std::array<FF, COMBINER_LENGTH> combiner_quotient_evals;
7271
for (size_t idx = 0; idx < COMBINER_LENGTH; idx++) {
7372
combiner_quotient_evals[idx] =
7473
transcript->template receive_from_prover<FF>("combiner_quotient_" + std::to_string(idx + NUM_KEYS));
@@ -177,7 +176,6 @@ std::shared_ptr<typename DeciderVerificationKeys::DeciderVK> ProtogalaxyRecursiv
177176
output_sum.y.assert_equal(folded_sum.y);
178177

179178
// Compute next folding parameters
180-
accumulator->is_accumulator = true;
181179
accumulator->target_sum =
182180
perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_at_challenge;
183181

barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ class ProtogalaxyRecursiveTests : public testing::Test {
234234
std::make_shared<typename InnerFoldingVerifier::Transcript>());
235235
native_folding_verifier.transcript->enable_manifest();
236236
std::shared_ptr<InnerDeciderVerificationKey> native_accumulator;
237-
native_folding_verifier.verify_folding_proof(folding_proof.proof);
238237
for (size_t idx = 0; idx < num_verifiers; idx++) {
239238
native_accumulator = native_folding_verifier.verify_folding_proof(folding_proof.proof);
240239
if (idx < num_verifiers - 1) { // else the transcript is null in the test below

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ {
3636

3737
std::shared_ptr<VKAndHash> vk_and_hash;
3838

39-
bool is_accumulator = false;
39+
bool is_complete = false; // whether this instance has been completely populated
4040

4141
// An array {1, α₁, …, αₖ}, where k = NUM_SUBRELATIONS - 1.
4242
SubrelationSeparators alphas;
@@ -66,8 +66,8 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ {
6666
RecursiveDeciderVerificationKey_(Builder* builder, std::shared_ptr<NativeDeciderVerificationKey> verification_key)
6767
: RecursiveDeciderVerificationKey_(builder, verification_key->vk)
6868
{
69-
is_accumulator = verification_key->is_accumulator;
70-
if (is_accumulator) {
69+
is_complete = verification_key->is_complete;
70+
if (is_complete) {
7171
for (size_t alpha_idx = 0; alpha_idx < Flavor::NUM_SUBRELATIONS - 1; alpha_idx++) {
7272
alphas[alpha_idx] = FF::from_witness(builder, verification_key->alphas[alpha_idx]);
7373
}
@@ -117,7 +117,7 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ {
117117
}
118118

119119
NativeDeciderVerificationKey decider_vk(native_honk_vk);
120-
decider_vk.is_accumulator = is_accumulator;
120+
decider_vk.is_complete = is_complete;
121121

122122
for (auto [alpha, inst_alpha] : zip_view(alphas, decider_vk.alphas)) {
123123
inst_alpha = alpha.get_value();

barretenberg/cpp/src/barretenberg/ultra_honk/decider_proving_key.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,13 @@ template <IsUltraOrMegaHonk Flavor> class DeciderProvingKey_ {
5555
ProverPolynomials polynomials; // the multilinear polynomials used by the prover
5656
SubrelationSeparators alphas; // a challenge for each subrelation
5757
bb::RelationParameters<FF> relation_parameters;
58-
std::vector<FF> gate_challenges;
59-
FF target_sum{ 0 }; // Sumcheck target sum; typically nonzero for a ProtogalaxyProver's accmumulator
58+
std::vector<FF> gate_challenges = std::vector<FF>(CONST_PG_LOG_N, 0);
59+
FF target_sum{ 0 }; // Sumcheck target sum; typically nonzero for a ProtogalaxyProver's accumulator
6060

6161
HonkProof ipa_proof; // utilized only for UltraRollupFlavor
6262

63-
bool is_accumulator = false;
63+
bool is_accumulator = false; // whether this instance the result of a Protogalaxy folding
64+
bool is_complete = false; // whether this instance has been completely populated
6465
std::vector<uint32_t> memory_read_records;
6566
std::vector<uint32_t> memory_write_records;
6667

barretenberg/cpp/src/barretenberg/ultra_honk/decider_verification_key.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ template <IsUltraOrMegaHonk Flavor> class DeciderVerificationKey_ {
3030

3131
std::shared_ptr<VerificationKey> vk;
3232

33-
bool is_accumulator = false;
33+
bool is_complete = false; // whether this instance has been completely populated
3434

3535
SubrelationSeparators alphas; // a challenge for each subrelation
3636
RelationParameters<FF> relation_parameters;
3737
std::vector<FF> gate_challenges;
38-
// The target sum, which is typically nonzero for a ProtogalaxyProver's accmumulator
38+
// The target sum, which is typically nonzero for a ProtogalaxyProver's accumulator
3939
FF target_sum{ 0 };
4040

4141
WitnessCommitments witness_commitments;
@@ -83,6 +83,6 @@ template <IsUltraOrMegaHonk Flavor> class DeciderVerificationKey_ {
8383
return decider_vk_hash;
8484
}
8585

86-
MSGPACK_FIELDS(vk, relation_parameters, alphas, is_accumulator, gate_challenges, target_sum, witness_commitments);
86+
MSGPACK_FIELDS(vk, relation_parameters, alphas, is_complete, gate_challenges, target_sum, witness_commitments);
8787
};
8888
} // namespace bb

0 commit comments

Comments
 (0)