-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: PG + Goblin #4399
Merged
+384
−70
Merged
feat: PG + Goblin #4399
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
38a7327
gob recusion test with goblin.merge
ledwards2225 d5c3dbe
new folding test suite
ledwards2225 1b25736
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 bb08bbe
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 bb728f7
WiP; cant fold recursive folding verifier circuit
ledwards2225 81a5a93
Don't destroy shared_ptr; hack around different PI sizes.
codygunton 668caca
Cleanup (Ultra already decided yeah?)
codygunton 2be164d
Touch up example
codygunton ec5cf1f
Fix size printing
codygunton 0b9e153
Move to new Bb module
codygunton 7e1d64c
Use correct suite name
codygunton a67f8a2
Pseudocode
codygunton 68f3e89
functionality in place; cleanup needed
ledwards2225 0690ac8
ivc prove and verify methods
ledwards2225 2a72e9e
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 a69d34c
Cleanup and commenting
ledwards2225 600a17b
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 416097a
verify final fold proof + typo
ledwards2225 cf24036
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 54db43d
updates based on review
ledwards2225 56c02f0
Merge branch 'master' into lde/goblin_with_folding
ledwards2225 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
barretenberg_module(client_ivc goblin) |
79 changes: 79 additions & 0 deletions
79
barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "barretenberg/client_ivc/client_ivc.hpp" | ||
|
||
namespace bb { | ||
|
||
ClientIVC::ClientIVC() | ||
{ | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/723): | ||
GoblinMockCircuits::perform_op_queue_interactions_for_mock_first_circuit(goblin.op_queue); | ||
} | ||
|
||
/** | ||
* @brief Initialize the IVC with a first circuit | ||
* @details Initializes the accumulator and performs the initial goblin merge | ||
* | ||
* @param circuit | ||
*/ | ||
void ClientIVC::initialize(ClientCircuit& circuit) | ||
{ | ||
goblin.merge(circuit); // Construct new merge proof | ||
Composer composer; | ||
fold_output.accumulator = composer.create_instance(circuit); | ||
} | ||
|
||
/** | ||
* @brief Accumulate a circuit into the IVC scheme | ||
* @details Performs goblin merge, generates circuit instance, folds into accumulator and constructs a folding proof | ||
* | ||
* @param circuit Circuit to be accumulated/folded | ||
* @return FoldProof | ||
*/ | ||
ClientIVC::FoldProof ClientIVC::accumulate(ClientCircuit& circuit) | ||
{ | ||
goblin.merge(circuit); // Add recursive merge verifier and construct new merge proof | ||
Composer composer; | ||
auto instance = composer.create_instance(circuit); | ||
std::vector<std::shared_ptr<Instance>> instances{ fold_output.accumulator, instance }; | ||
auto folding_prover = composer.create_folding_prover(instances); | ||
fold_output = folding_prover.fold_instances(); | ||
return fold_output.folding_data; | ||
} | ||
|
||
/** | ||
* @brief Construct a proof for the IVC, which, if verified, fully establishes its correctness | ||
* | ||
* @return Proof | ||
*/ | ||
ClientIVC::Proof ClientIVC::prove() | ||
{ | ||
// Construct Goblin proof (merge, eccvm, translator) | ||
auto goblin_proof = goblin.prove(); | ||
|
||
// Construct decider proof for the final accumulator | ||
Composer composer; | ||
auto decider_prover = composer.create_decider_prover(fold_output.accumulator); | ||
auto decider_proof = decider_prover.construct_proof(); | ||
return { goblin_proof, fold_output.folding_data, decider_proof }; | ||
} | ||
|
||
/** | ||
* @brief Verify a full proof of the IVC | ||
* | ||
* @param proof | ||
* @return bool | ||
*/ | ||
bool ClientIVC::verify(Proof& proof) | ||
{ | ||
// Goblin verification (merge, eccvm, translator) | ||
bool goblin_verified = goblin.verify(proof.goblin_proof); | ||
|
||
// Decider verification | ||
Composer composer; | ||
auto folding_verifier = composer.create_folding_verifier(); | ||
bool folding_verified = folding_verifier.verify_folding_proof(proof.fold_proof); | ||
// NOTE: Use of member accumulator here will go away with removal of vkey from ProverInstance | ||
auto decider_verifier = composer.create_decider_verifier(fold_output.accumulator); | ||
bool decision = decider_verifier.verify_proof(proof.decider_proof); | ||
return goblin_verified && folding_verified && decision; | ||
} | ||
} // namespace bb |
50 changes: 50 additions & 0 deletions
50
barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include "barretenberg/goblin/goblin.hpp" | ||
#include "barretenberg/goblin/mock_circuits.hpp" | ||
#include "barretenberg/ultra_honk/ultra_composer.hpp" | ||
|
||
namespace bb { | ||
|
||
/** | ||
* @brief The IVC interface to be used by the aztec client for private function execution | ||
* @details Combines Protogalaxy with Goblin to accumulate one circuit instance at a time with efficient EC group | ||
* operations | ||
* | ||
*/ | ||
class ClientIVC { | ||
|
||
public: | ||
using Flavor = GoblinUltraFlavor; | ||
using FF = Flavor::FF; | ||
using FoldProof = std::vector<FF>; | ||
using Accumulator = std::shared_ptr<ProverInstance_<Flavor>>; | ||
using ClientCircuit = GoblinUltraCircuitBuilder; // can only be GoblinUltra | ||
|
||
// A full proof for the IVC scheme | ||
struct Proof { | ||
Goblin::Proof goblin_proof; | ||
FoldProof fold_proof; // final fold proof | ||
HonkProof decider_proof; | ||
}; | ||
|
||
private: | ||
using FoldingOutput = FoldingResult<Flavor>; | ||
using Instance = ProverInstance_<GoblinUltraFlavor>; | ||
using Composer = GoblinUltraComposer; | ||
|
||
public: | ||
Goblin goblin; | ||
FoldingOutput fold_output; | ||
|
||
ClientIVC(); | ||
|
||
void initialize(ClientCircuit& circuit); | ||
|
||
FoldProof accumulate(ClientCircuit& circuit); | ||
|
||
Proof prove(); | ||
|
||
bool verify(Proof& proof); | ||
}; | ||
} // namespace bb |
120 changes: 120 additions & 0 deletions
120
barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include "barretenberg/client_ivc/client_ivc.hpp" | ||
#include "barretenberg/goblin/goblin.hpp" | ||
#include "barretenberg/goblin/mock_circuits.hpp" | ||
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" | ||
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" | ||
#include "barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.hpp" | ||
#include "barretenberg/ultra_honk/ultra_composer.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
using namespace bb; | ||
|
||
class ClientIVCTests : public ::testing::Test { | ||
protected: | ||
static void SetUpTestSuite() | ||
{ | ||
srs::init_crs_factory("../srs_db/ignition"); | ||
srs::init_grumpkin_crs_factory("../srs_db/grumpkin"); | ||
} | ||
|
||
using Flavor = ClientIVC::Flavor; | ||
using FF = typename Flavor::FF; | ||
using Builder = ClientIVC::ClientCircuit; | ||
using Composer = GoblinUltraComposer; | ||
using Accumulator = ClientIVC::Accumulator; | ||
using FoldProof = ClientIVC::FoldProof; | ||
|
||
using GURecursiveFlavor = GoblinUltraRecursiveFlavor_<Builder>; | ||
using RecursiveVerifierInstances = ::bb::VerifierInstances_<GURecursiveFlavor, 2>; | ||
using FoldingRecursiveVerifier = | ||
bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_<RecursiveVerifierInstances>; | ||
|
||
/** | ||
* @brief Construct mock circuit with arithmetic gates and goblin ops | ||
* @details Currently default sized to 2^16 to match kernel. (Note: op gates will bump size to next power of 2) | ||
* | ||
*/ | ||
static Builder create_mock_circuit(ClientIVC& ivc, size_t num_gates = 1 << 15) | ||
{ | ||
Builder circuit{ ivc.goblin.op_queue }; | ||
GoblinMockCircuits::construct_arithmetic_circuit(circuit, num_gates); | ||
GoblinMockCircuits::construct_goblin_ecc_op_circuit(circuit); | ||
return circuit; | ||
} | ||
|
||
/** | ||
* @brief Construct mock kernel consisting of two recursive folding verifiers | ||
* | ||
* @param builder | ||
* @param fctn_fold_proof | ||
* @param kernel_fold_proof | ||
*/ | ||
static void construct_mock_folding_kernel(Builder& builder, | ||
FoldProof& fctn_fold_proof, | ||
FoldProof& kernel_fold_proof) | ||
{ | ||
FoldingRecursiveVerifier verifier_1{ &builder }; | ||
verifier_1.verify_folding_proof(fctn_fold_proof); | ||
|
||
FoldingRecursiveVerifier verifier_2{ &builder }; | ||
verifier_2.verify_folding_proof(kernel_fold_proof); | ||
} | ||
|
||
/** | ||
* @brief Perform native fold verification and run decider prover/verifier | ||
* | ||
*/ | ||
static void EXPECT_FOLDING_AND_DECIDING_VERIFIED(const Accumulator& accumulator, const FoldProof& fold_proof) | ||
{ | ||
// Verify fold proof | ||
Composer composer; | ||
auto folding_verifier = composer.create_folding_verifier(); | ||
bool folding_verified = folding_verifier.verify_folding_proof(fold_proof); | ||
EXPECT_TRUE(folding_verified); | ||
|
||
// Run decider | ||
auto decider_prover = composer.create_decider_prover(accumulator); | ||
auto decider_verifier = composer.create_decider_verifier(accumulator); | ||
auto decider_proof = decider_prover.construct_proof(); | ||
bool decision = decider_verifier.verify_proof(decider_proof); | ||
EXPECT_TRUE(decision); | ||
} | ||
}; | ||
|
||
/** | ||
* @brief A full Goblin test using PG that mimicks the basic aztec client architecture | ||
* | ||
*/ | ||
TEST_F(ClientIVCTests, Full) | ||
{ | ||
ClientIVC ivc; | ||
|
||
// Initialize IVC with function circuit | ||
Builder function_circuit = create_mock_circuit(ivc); | ||
ivc.initialize(function_circuit); | ||
|
||
// Accumulate kernel circuit (first kernel mocked as simple circuit since no folding proofs yet) | ||
Builder kernel_circuit = create_mock_circuit(ivc); | ||
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit); | ||
EXPECT_FOLDING_AND_DECIDING_VERIFIED(ivc.fold_output.accumulator, kernel_fold_proof); | ||
|
||
size_t NUM_CIRCUITS = 1; | ||
for (size_t circuit_idx = 0; circuit_idx < NUM_CIRCUITS; ++circuit_idx) { | ||
// Accumulate function circuit | ||
Builder function_circuit = create_mock_circuit(ivc); | ||
FoldProof function_fold_proof = ivc.accumulate(function_circuit); | ||
EXPECT_FOLDING_AND_DECIDING_VERIFIED(ivc.fold_output.accumulator, function_fold_proof); | ||
|
||
// Accumulate kernel circuit | ||
Builder kernel_circuit{ ivc.goblin.op_queue }; | ||
construct_mock_folding_kernel(kernel_circuit, function_fold_proof, kernel_fold_proof); | ||
FoldProof kernel_fold_proof = ivc.accumulate(kernel_circuit); | ||
EXPECT_FOLDING_AND_DECIDING_VERIFIED(ivc.fold_output.accumulator, kernel_fold_proof); | ||
} | ||
|
||
// Constuct four proofs: merge, eccvm, translator, decider | ||
auto proof = ivc.prove(); | ||
|
||
// Verify all four proofs | ||
EXPECT_TRUE(ivc.verify(proof)); | ||
} |
62 changes: 0 additions & 62 deletions
62
barretenberg/cpp/src/barretenberg/goblin/full_goblin_recursion.test.cpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag was preventing my CMakeTools from building... I guess removing it didn't give you problems?