Skip to content

Commit 4789440

Browse files
authored
refactor: Renaming Instance's (#8362)
The main objective of this PR is to do some renaming to stop using the term "instance" as we currently do in the Honk flavors that can be used to construct proofs from stdlib circuits (Mega, UItra, relative). This is bad terminology for several reasons: - the term "instace-witness pair" is widely in use in ZK, and our existing use of "instance" directly clashes with this. - `ProverInstance` is really just a key for Decider proving; similarly for `VerifierInstance` - `ProvingKey` as it currently exists is de facto deprecated in the contexts where we use "instance"'s since we have have rewritten those provers and verifiers using Oink prover and verifier. - "Prover instance" sounds a lot like an instance of the Prover class--can be confusing in conversation. - I take it as a sign that "instance" is a bad term that we variously use that term and the term "accumulator" for the same thing, depending on the context, whether or not any accumulation is or could even happen. I simply rename things to Decider[Proving/Verification]Key and variants of this depending on context. A sign that this is a good choice is the fact that we now have the absurd-looking `proving_key->proving_key`, which will become non-absurb when the inner proving key type is actually deprecated. At that point the DeciderProvingKey class could move into the flavor, time permitting. I also have a small change to remove the `State` struct I recently added to Protogalaxy Prover. This is where the work started before I undertook the big renaming job, and it's small and localized enough that it feels unnecessary to split it out. Note: renaming of files is done in a follow-on #8383
1 parent 2ea6ec2 commit 4789440

File tree

92 files changed

+1327
-1349
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1327
-1349
lines changed

barretenberg/cpp/scripts/analyze_client_ivc_bench.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Single out an independent set of functions accounting for most of BENCHMARK's real_time
1717
to_keep = [
1818
"construct_circuits(t)",
19-
"ProverInstance(Circuit&)(t)",
19+
"DeciderProvingKey(Circuit&)(t)",
2020
"ProtogalaxyProver::prove(t)",
2121
"Decider::construct_proof(t)",
2222
"ECCVMProver(CircuitBuilder&)(t)",

barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.cpp

+33-32
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,33 @@ void AztecIVC::complete_kernel_circuit_logic(ClientCircuit& circuit)
2323
switch (type) {
2424
case QUEUE_TYPE::PG: {
2525
// Construct stdlib verifier accumulator from the native counterpart computed on a previous round
26-
auto stdlib_verifier_accum = std::make_shared<RecursiveVerifierInstance>(&circuit, verifier_accumulator);
26+
auto stdlib_verifier_accum =
27+
std::make_shared<RecursiveDeciderVerificationKey>(&circuit, verifier_accumulator);
2728

2829
// Perform folding recursive verification to update the verifier accumulator
2930
FoldingRecursiveVerifier verifier{ &circuit, stdlib_verifier_accum, { stdlib_vkey } };
3031
auto verifier_accum = verifier.verify_folding_proof(stdlib_proof);
3132

3233
// Extract native verifier accumulator from the stdlib accum for use on the next round
33-
verifier_accumulator = std::make_shared<VerifierInstance>(verifier_accum->get_value());
34+
verifier_accumulator = std::make_shared<DeciderVerificationKey>(verifier_accum->get_value());
3435

3536
// Perform databus commitment consistency checks and propagate return data commitments via public inputs
36-
bus_depot.execute(verifier.instances[1]->witness_commitments,
37-
verifier.instances[1]->public_inputs,
38-
verifier.instances[1]->verification_key->databus_propagation_data);
37+
bus_depot.execute(verifier.keys_to_fold[1]->witness_commitments,
38+
verifier.keys_to_fold[1]->public_inputs,
39+
verifier.keys_to_fold[1]->verification_key->databus_propagation_data);
3940
break;
4041
}
4142
case QUEUE_TYPE::OINK: {
4243
// Construct an incomplete stdlib verifier accumulator from the corresponding stdlib verification key
43-
auto verifier_accum = std::make_shared<RecursiveVerifierInstance>(&circuit, stdlib_vkey);
44+
auto verifier_accum = std::make_shared<RecursiveDeciderVerificationKey>(&circuit, stdlib_vkey);
4445

4546
// Perform oink recursive verification to complete the initial verifier accumulator
4647
OinkRecursiveVerifier oink{ &circuit, verifier_accum };
4748
oink.verify_proof(stdlib_proof);
48-
verifier_accum->is_accumulator = true; // indicate to PG that it should not run oink on this instance
49+
verifier_accum->is_accumulator = true; // indicate to PG that it should not run oink on this key
4950

5051
// Extract native verifier accumulator from the stdlib accum for use on the next round
51-
verifier_accumulator = std::make_shared<VerifierInstance>(verifier_accum->get_value());
52+
verifier_accumulator = std::make_shared<DeciderVerificationKey>(verifier_accum->get_value());
5253
// Initialize the gate challenges to zero for use in first round of folding
5354
verifier_accumulator->gate_challenges =
5455
std::vector<FF>(verifier_accum->verification_key->log_circuit_size, 0);
@@ -72,9 +73,9 @@ void AztecIVC::complete_kernel_circuit_logic(ClientCircuit& circuit)
7273
}
7374

7475
/**
75-
* @brief Execute prover work for instance accumulation
76-
* @details Construct an instance for the provided circuit. If this is the first instance in the IVC, simply initialize
77-
* the folding accumulator. Otherwise, execute the PG prover to fold the instance into the accumulator and produce a
76+
* @brief Execute prover work for accumulation
77+
* @details Construct an proving key for the provided circuit. If this is the first step in the IVC, simply initialize
78+
* the folding accumulator. Otherwise, execute the PG prover to fold the proving key into the accumulator and produce a
7879
* folding proof. Also execute the merge protocol to produce a merge proof.
7980
*
8081
* @param circuit
@@ -90,40 +91,40 @@ void AztecIVC::accumulate(ClientCircuit& circuit, const std::shared_ptr<Verifica
9091
// verifier.
9192
circuit.add_recursive_proof(stdlib::recursion::init_default_agg_obj_indices<ClientCircuit>(circuit));
9293

93-
// Construct the prover instance for circuit
94-
std::shared_ptr<ProverInstance> prover_instance;
94+
// Construct the proving key for circuit
95+
std::shared_ptr<DeciderProvingKey> proving_key;
9596
if (!initialized) {
96-
prover_instance = std::make_shared<ProverInstance>(circuit, trace_structure);
97+
proving_key = std::make_shared<DeciderProvingKey>(circuit, trace_structure);
9798
} else {
98-
prover_instance = std::make_shared<ProverInstance>(
99+
proving_key = std::make_shared<DeciderProvingKey>(
99100
circuit, trace_structure, fold_output.accumulator->proving_key.commitment_key);
100101
}
101102

102-
// Set the instance verification key from precomputed if available, else compute it
103-
instance_vk = precomputed_vk ? precomputed_vk : std::make_shared<VerificationKey>(prover_instance->proving_key);
103+
// Set the verification key from precomputed if available, else compute it
104+
honk_vk = precomputed_vk ? precomputed_vk : std::make_shared<VerificationKey>(proving_key->proving_key);
104105

105-
// If this is the first circuit in the IVC, use oink to compute the completed instance and generate an oink proof
106+
// If this is the first circuit in the IVC, use oink to complete the decider proving key and generate an oink proof
106107
if (!initialized) {
107-
OinkProver<Flavor> oink_prover{ prover_instance };
108+
OinkProver<Flavor> oink_prover{ proving_key };
108109
oink_prover.prove();
109-
prover_instance->is_accumulator = true; // indicate to PG that it should not run oink on this instance
110+
proving_key->is_accumulator = true; // indicate to PG that it should not run oink on this key
110111
// Initialize the gate challenges to zero for use in first round of folding
111-
prover_instance->gate_challenges = std::vector<FF>(prover_instance->proving_key.log_circuit_size, 0);
112+
proving_key->gate_challenges = std::vector<FF>(proving_key->proving_key.log_circuit_size, 0);
112113

113-
fold_output.accumulator = prover_instance; // initialize the prover accum with the completed instance
114+
fold_output.accumulator = proving_key; // initialize the prover accum with the completed key
114115

115116
// Add oink proof and corresponding verification key to the verification queue
116117
verification_queue.push_back(
117-
bb::AztecIVC::RecursiveVerifierInputs{ oink_prover.transcript->proof_data, instance_vk, QUEUE_TYPE::OINK });
118+
bb::AztecIVC::RecursiveVerifierInputs{ oink_prover.transcript->proof_data, honk_vk, QUEUE_TYPE::OINK });
118119

119120
initialized = true;
120-
} else { // Otherwise, fold the new instance into the accumulator
121-
FoldingProver folding_prover({ fold_output.accumulator, prover_instance });
121+
} else { // Otherwise, fold the new key into the accumulator
122+
FoldingProver folding_prover({ fold_output.accumulator, proving_key });
122123
fold_output = folding_prover.prove();
123124

124125
// Add fold proof and corresponding verification key to the verification queue
125126
verification_queue.push_back(
126-
bb::AztecIVC::RecursiveVerifierInputs{ fold_output.proof, instance_vk, QUEUE_TYPE::PG });
127+
bb::AztecIVC::RecursiveVerifierInputs{ fold_output.proof, honk_vk, QUEUE_TYPE::PG });
127128
}
128129

129130
// Track the maximum size of each block for all circuits porcessed (for debugging purposes only)
@@ -146,8 +147,8 @@ AztecIVC::Proof AztecIVC::prove()
146147
};
147148

148149
bool AztecIVC::verify(const Proof& proof,
149-
const std::shared_ptr<VerifierInstance>& accumulator,
150-
const std::shared_ptr<VerifierInstance>& final_verifier_instance,
150+
const std::shared_ptr<DeciderVerificationKey>& accumulator,
151+
const std::shared_ptr<DeciderVerificationKey>& final_stack_vk,
151152
const std::shared_ptr<AztecIVC::ECCVMVerificationKey>& eccvm_vk,
152153
const std::shared_ptr<AztecIVC::TranslatorVerificationKey>& translator_vk)
153154
{
@@ -156,7 +157,7 @@ bool AztecIVC::verify(const Proof& proof,
156157
bool goblin_verified = goblin_verifier.verify(proof.goblin_proof);
157158

158159
// Decider verification
159-
AztecIVC::FoldingVerifier folding_verifier({ accumulator, final_verifier_instance });
160+
AztecIVC::FoldingVerifier folding_verifier({ accumulator, final_stack_vk });
160161
auto verifier_accumulator = folding_verifier.verify_folding_proof(proof.folding_proof);
161162

162163
AztecIVC::DeciderVerifier decider_verifier(verifier_accumulator);
@@ -170,11 +171,11 @@ bool AztecIVC::verify(const Proof& proof,
170171
* @param proof
171172
* @return bool
172173
*/
173-
bool AztecIVC::verify(Proof& proof, const std::vector<std::shared_ptr<VerifierInstance>>& verifier_instances)
174+
bool AztecIVC::verify(Proof& proof, const std::vector<std::shared_ptr<DeciderVerificationKey>>& vk_stack)
174175
{
175176
auto eccvm_vk = std::make_shared<ECCVMVerificationKey>(goblin.get_eccvm_proving_key());
176177
auto translator_vk = std::make_shared<TranslatorVerificationKey>(goblin.get_translator_proving_key());
177-
return verify(proof, verifier_instances[0], verifier_instances[1], eccvm_vk, translator_vk);
178+
return verify(proof, vk_stack[0], vk_stack[1], eccvm_vk, translator_vk);
178179
}
179180

180181
/**
@@ -199,7 +200,7 @@ bool AztecIVC::prove_and_verify()
199200
auto proof = prove();
200201

201202
ASSERT(verification_queue.size() == 1); // ensure only a single fold proof remains in the queue
202-
auto verifier_inst = std::make_shared<VerifierInstance>(this->verification_queue[0].instance_vk);
203+
auto verifier_inst = std::make_shared<DeciderVerificationKey>(this->verification_queue[0].honk_verification_key);
203204
return verify(proof, { this->verifier_accumulator, verifier_inst });
204205
}
205206

barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp

+19-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace bb {
1515

1616
/**
1717
* @brief The IVC scheme used by the aztec client for private function execution
18-
* @details Combines Protogalaxy with Goblin to accumulate one circuit instance at a time with efficient EC group
18+
* @details Combines Protogalaxy with Goblin to accumulate one circuit at a time with efficient EC group
1919
* operations. It is assumed that the circuits being accumulated correspond alternatingly to an app and a kernel, as is
2020
* the case in Aztec. Two recursive folding verifiers are appended to each kernel (except the first one) to verify the
2121
* folding of a previous kernel and an app/function circuit. Due to this structure it is enforced that the total number
@@ -30,24 +30,25 @@ class AztecIVC {
3030
using FF = Flavor::FF;
3131
using FoldProof = std::vector<FF>;
3232
using MergeProof = std::vector<FF>;
33-
using ProverInstance = ProverInstance_<Flavor>;
34-
using VerifierInstance = VerifierInstance_<Flavor>;
33+
using DeciderProvingKey = DeciderProvingKey_<Flavor>;
34+
using DeciderVerificationKey = DeciderVerificationKey_<Flavor>;
3535
using ClientCircuit = MegaCircuitBuilder; // can only be Mega
3636
using DeciderProver = DeciderProver_<Flavor>;
3737
using DeciderVerifier = DeciderVerifier_<Flavor>;
38-
using ProverInstances = ProverInstances_<Flavor>;
39-
using FoldingProver = ProtogalaxyProver_<ProverInstances>;
40-
using VerifierInstances = VerifierInstances_<Flavor>;
41-
using FoldingVerifier = ProtogalaxyVerifier_<VerifierInstances>;
38+
using DeciderProvingKeys = DeciderProvingKeys_<Flavor>;
39+
using FoldingProver = ProtogalaxyProver_<DeciderProvingKeys>;
40+
using DeciderVerificationKeys = DeciderVerificationKeys_<Flavor>;
41+
using FoldingVerifier = ProtogalaxyVerifier_<DeciderVerificationKeys>;
4242
using ECCVMVerificationKey = bb::ECCVMFlavor::VerificationKey;
4343
using TranslatorVerificationKey = bb::TranslatorFlavor::VerificationKey;
4444

4545
using RecursiveFlavor = MegaRecursiveFlavor_<bb::MegaCircuitBuilder>;
46-
using RecursiveVerifierInstances = bb::stdlib::recursion::honk::RecursiveVerifierInstances_<RecursiveFlavor, 2>;
47-
using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance;
46+
using RecursiveDeciderVerificationKeys =
47+
bb::stdlib::recursion::honk::RecursiveDeciderVerificationKeys_<RecursiveFlavor, 2>;
48+
using RecursiveDeciderVerificationKey = RecursiveDeciderVerificationKeys::DeciderVK;
4849
using RecursiveVerificationKey = RecursiveFlavor::VerificationKey;
4950
using FoldingRecursiveVerifier =
50-
bb::stdlib::recursion::honk::ProtogalaxyRecursiveVerifier_<RecursiveVerifierInstances>;
51+
bb::stdlib::recursion::honk::ProtogalaxyRecursiveVerifier_<RecursiveDeciderVerificationKeys>;
5152
using OinkRecursiveVerifier = stdlib::recursion::honk::OinkRecursiveVerifier_<RecursiveFlavor>;
5253

5354
using DataBusDepot = stdlib::DataBusDepot<ClientCircuit>;
@@ -66,7 +67,7 @@ class AztecIVC {
6667
enum class QUEUE_TYPE { OINK, PG };
6768
struct RecursiveVerifierInputs {
6869
std::vector<FF> proof; // oink or PG
69-
std::shared_ptr<VerificationKey> instance_vk;
70+
std::shared_ptr<VerificationKey> honk_verification_key;
7071
QUEUE_TYPE type;
7172
};
7273

@@ -79,10 +80,10 @@ class AztecIVC {
7980
public:
8081
GoblinProver goblin;
8182

82-
ProverFoldOutput fold_output; // prover accumulator instance and fold proof
83+
ProverFoldOutput fold_output; // prover accumulator and fold proof
8384

84-
std::shared_ptr<VerifierInstance> verifier_accumulator; // verifier accumulator instance
85-
std::shared_ptr<VerificationKey> instance_vk; // verification key for instance to be folded
85+
std::shared_ptr<DeciderVerificationKey> verifier_accumulator; // verifier accumulator
86+
std::shared_ptr<VerificationKey> honk_vk; // honk vk to be completed and folded into the accumulator
8687

8788
// Set of pairs of {fold_proof, verification_key} to be recursively verified
8889
std::vector<RecursiveVerifierInputs> verification_queue;
@@ -92,7 +93,7 @@ class AztecIVC {
9293
// Management of linking databus commitments between circuits in the IVC
9394
DataBusDepot bus_depot;
9495

95-
// A flag indicating whether or not to construct a structured trace in the ProverInstance
96+
// A flag indicating whether or not to construct a structured trace in the DeciderProvingKey
9697
TraceStructure trace_structure = TraceStructure::NONE;
9798

9899
bool initialized = false; // Is the IVC accumulator initialized
@@ -106,12 +107,12 @@ class AztecIVC {
106107
Proof prove();
107108

108109
static bool verify(const Proof& proof,
109-
const std::shared_ptr<VerifierInstance>& accumulator,
110-
const std::shared_ptr<VerifierInstance>& final_verifier_instance,
110+
const std::shared_ptr<DeciderVerificationKey>& accumulator,
111+
const std::shared_ptr<DeciderVerificationKey>& final_stack_vk,
111112
const std::shared_ptr<AztecIVC::ECCVMVerificationKey>& eccvm_vk,
112113
const std::shared_ptr<AztecIVC::TranslatorVerificationKey>& translator_vk);
113114

114-
bool verify(Proof& proof, const std::vector<std::shared_ptr<VerifierInstance>>& verifier_instances);
115+
bool verify(Proof& proof, const std::vector<std::shared_ptr<DeciderVerificationKey>>& vk_stack);
115116

116117
bool prove_and_verify();
117118

barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class AztecIVCTests : public ::testing::Test {
2020
using FF = typename Flavor::FF;
2121
using VerificationKey = Flavor::VerificationKey;
2222
using Builder = AztecIVC::ClientCircuit;
23-
using ProverInstance = AztecIVC::ProverInstance;
24-
using VerifierInstance = AztecIVC::VerifierInstance;
23+
using DeciderProvingKey = AztecIVC::DeciderProvingKey;
24+
using DeciderVerificationKey = AztecIVC::DeciderVerificationKey;
2525
using FoldProof = AztecIVC::FoldProof;
2626
using DeciderProver = AztecIVC::DeciderProver;
2727
using DeciderVerifier = AztecIVC::DeciderVerifier;
28-
using ProverInstances = ProverInstances_<Flavor>;
29-
using FoldingProver = ProtogalaxyProver_<ProverInstances>;
30-
using VerifierInstances = VerifierInstances_<Flavor>;
31-
using FoldingVerifier = ProtogalaxyVerifier_<VerifierInstances>;
28+
using DeciderProvingKeys = DeciderProvingKeys_<Flavor>;
29+
using FoldingProver = ProtogalaxyProver_<DeciderProvingKeys>;
30+
using DeciderVerificationKeys = DeciderVerificationKeys_<Flavor>;
31+
using FoldingVerifier = ProtogalaxyVerifier_<DeciderVerificationKeys>;
3232

3333
/**
3434
* @brief Construct mock circuit with arithmetic gates and goblin ops
@@ -86,7 +86,7 @@ class AztecIVCTests : public ::testing::Test {
8686
for (size_t idx = 0; idx < num_circuits; ++idx) {
8787
ClientCircuit circuit = create_next_circuit(ivc, log2_num_gates); // create the next circuit
8888
ivc.accumulate(circuit); // accumulate the circuit
89-
vkeys.emplace_back(ivc.instance_vk); // save the VK for the circuit
89+
vkeys.emplace_back(ivc.honk_vk); // save the VK for the circuit
9090
}
9191
is_kernel = false;
9292

barretenberg/cpp/src/barretenberg/aztec_ivc/mock_circuit_producer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class PrivateFunctionExecutionMockCircuitProducer {
139139
for (size_t idx = 0; idx < num_circuits; ++idx) {
140140
ClientCircuit circuit = create_next_circuit(ivc); // create the next circuit
141141
ivc.accumulate(circuit); // accumulate the circuit
142-
vkeys.emplace_back(ivc.instance_vk); // save the VK for the circuit
142+
vkeys.emplace_back(ivc.honk_vk); // save the VK for the circuit
143143
}
144144
circuit_counter = 0; // reset the internal circuit counter back to 0
145145

0 commit comments

Comments
 (0)