-
Notifications
You must be signed in to change notification settings - Fork 266
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: Encapsulated Goblin #3524
Merged
Merged
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7950c3c
codys baseline changes
ledwards2225 d0314a5
updates to test structure; passing; no recursion
ledwards2225 2e8ced6
construct recursive ver directly from native vkey
ledwards2225 3ebd005
new test suite; passes with 2 layers of recusion
ledwards2225 cfdbc3b
full test with recursion is passing through trans
ledwards2225 178f646
remove pseudo from composer tests
ledwards2225 fa68496
Merge branch 'master' into lde-cg/full_test_rework
codygunton 6ef21ac
const&
codygunton 91f3b8c
const&
codygunton 466cbf0
basic goblin prove and verify structure
ledwards2225 616fd40
Merge branch 'master' into lde-cg/full_test_rework
ledwards2225 d2db965
It works!
codygunton 385edee
VM verification split out
codygunton b1df3ae
Bring tests in line w/ e/o
codygunton 4e332f4
WIP
codygunton c02db5a
Fix Translator test
codygunton a4b5e2f
Share testing code
codygunton 4f5d1ea
Cleanup
codygunton ba98a33
Cleanup
codygunton 55ec020
Spawn todos.
codygunton e075d93
Remove comment
codygunton 9d9f735
Remove stupid alias.
codygunton c90e3bf
Adjust comments per review.
codygunton 60d7f56
Better modeling of kernel
codygunton 977021e
Merge remote-tracking branch 'origin/master' into lde-cg/full_test_re…
codygunton 791ff7d
Rename utils.hpp
codygunton 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
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 |
---|---|---|
@@ -1 +1 @@ | ||
barretenberg_module(goblin ultra_honk eccvm translator_vm) | ||
barretenberg_module(goblin ultra_honk eccvm translator_vm transcript) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
#include "barretenberg/eccvm/eccvm_composer.hpp" | ||
#include "barretenberg/goblin/goblin.hpp" | ||
#include "barretenberg/goblin/translation_evaluations.hpp" | ||
#include "barretenberg/goblin/utils.hpp" | ||
#include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp" | ||
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp" | ||
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" | ||
|
@@ -8,14 +10,11 @@ | |
|
||
#include <gtest/gtest.h> | ||
|
||
using namespace barretenberg; | ||
using namespace proof_system::honk; | ||
|
||
namespace test_full_goblin_composer { | ||
|
||
namespace { | ||
auto& engine = numeric::random::get_debug_engine(); | ||
} | ||
|
||
class FullGoblinComposerTests : public ::testing::Test { | ||
protected: | ||
static void SetUpTestSuite() | ||
|
@@ -30,110 +29,11 @@ class FullGoblinComposerTests : public ::testing::Test { | |
using Point = Curve::AffineElement; | ||
using CommitmentKey = pcs::CommitmentKey<Curve>; | ||
using OpQueue = proof_system::ECCOpQueue; | ||
using GoblinUltraBuilder = proof_system::GoblinUltraCircuitBuilder; | ||
using ECCVMFlavor = flavor::ECCVM; | ||
using ECCVMBuilder = proof_system::ECCVMCircuitBuilder<ECCVMFlavor>; | ||
using ECCVMComposer = ECCVMComposer_<ECCVMFlavor>; | ||
|
||
static constexpr size_t NUM_OP_QUEUE_COLUMNS = flavor::GoblinUltra::NUM_WIRES; | ||
|
||
/** | ||
* @brief Generate a simple test circuit with some ECC op gates and conventional arithmetic gates | ||
* | ||
* @param builder | ||
*/ | ||
static void generate_test_circuit(proof_system::GoblinUltraCircuitBuilder& builder) | ||
{ | ||
// Add some arbitrary ecc op gates | ||
for (size_t i = 0; i < 3; ++i) { | ||
auto point = Point::random_element(); | ||
auto scalar = FF::random_element(); | ||
builder.queue_ecc_add_accum(point); | ||
builder.queue_ecc_mul_accum(point, scalar); | ||
} | ||
// queues the result of the preceding ECC | ||
builder.queue_ecc_eq(); // should be eq and reset | ||
|
||
// Add some conventional gates that utilize public inputs | ||
for (size_t i = 0; i < 10; ++i) { | ||
FF a = FF::random_element(); | ||
FF b = FF::random_element(); | ||
FF c = FF::random_element(); | ||
FF d = a + b + c; | ||
uint32_t a_idx = builder.add_public_variable(a); | ||
uint32_t b_idx = builder.add_variable(b); | ||
uint32_t c_idx = builder.add_variable(c); | ||
uint32_t d_idx = builder.add_variable(d); | ||
|
||
builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, FF(1), FF(1), FF(1), FF(-1), FF(0) }); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Mock the interactions of a simple curcuit with the op_queue | ||
* @details The transcript aggregation protocol in the Goblin proof system can not yet support an empty "previous | ||
* transcript" (see issue #723). This function mocks the interactions with the op queue of a fictional "first" | ||
* circuit. This way, when we go to generate a proof over our first "real" circuit, the transcript aggregation | ||
* protocol can proceed nominally. The mock data is valid in the sense that it can be processed by all stages of | ||
* Goblin as if it came from a genuine circuit. | ||
* | ||
* @todo WOKTODO: this is a zero commitments issue | ||
* | ||
* @param op_queue | ||
*/ | ||
static void perform_op_queue_interactions_for_mock_first_circuit( | ||
std::shared_ptr<proof_system::ECCOpQueue>& op_queue) | ||
{ | ||
proof_system::GoblinUltraCircuitBuilder builder{ op_queue }; | ||
|
||
// Add a mul accum op and an equality op | ||
auto point = Point::one() * FF::random_element(); | ||
auto scalar = FF::random_element(); | ||
builder.queue_ecc_mul_accum(point, scalar); | ||
builder.queue_ecc_eq(); | ||
|
||
op_queue->set_size_data(); | ||
|
||
// Manually compute the op queue transcript commitments (which would normally be done by the prover) | ||
auto crs_factory_ = barretenberg::srs::get_crs_factory(); | ||
auto commitment_key = CommitmentKey(op_queue->get_current_size(), crs_factory_); | ||
std::array<Point, NUM_OP_QUEUE_COLUMNS> op_queue_commitments; | ||
size_t idx = 0; | ||
for (auto& entry : op_queue->get_aggregate_transcript()) { | ||
op_queue_commitments[idx++] = commitment_key.commit(entry); | ||
} | ||
// Store the commitment data for use by the prover of the next circuit | ||
op_queue->set_commitment_data(op_queue_commitments); | ||
} | ||
|
||
/** | ||
* @brief Construct and a verify a Honk proof | ||
* | ||
*/ | ||
static bool construct_and_verify_honk_proof(GoblinUltraComposer& composer, | ||
proof_system::GoblinUltraCircuitBuilder& builder) | ||
{ | ||
auto instance = composer.create_instance(builder); | ||
auto prover = composer.create_prover(instance); | ||
auto verifier = composer.create_verifier(instance); | ||
auto proof = prover.construct_proof(); | ||
bool verified = verifier.verify_proof(proof); | ||
|
||
return verified; | ||
} | ||
|
||
/** | ||
* @brief Construct and verify a Goblin ECC op queue merge proof | ||
* | ||
*/ | ||
static bool construct_and_verify_merge_proof(GoblinUltraComposer& composer, std::shared_ptr<OpQueue>& op_queue) | ||
{ | ||
auto merge_prover = composer.create_merge_prover(op_queue); | ||
auto merge_verifier = composer.create_merge_verifier(/*srs_size=*/10); | ||
auto merge_proof = merge_prover.construct_proof(); | ||
bool verified = merge_verifier.verify_proof(merge_proof); | ||
|
||
return verified; | ||
} | ||
using KernelInput = Goblin::AccumulationOutput; | ||
}; | ||
|
||
/** | ||
|
@@ -145,52 +45,31 @@ class FullGoblinComposerTests : public ::testing::Test { | |
*/ | ||
TEST_F(FullGoblinComposerTests, SimpleCircuit) | ||
{ | ||
auto op_queue = std::make_shared<proof_system::ECCOpQueue>(); | ||
barretenberg::Goblin goblin; | ||
|
||
// Add mock data to op queue to simulate interaction with a "first" circuit | ||
perform_op_queue_interactions_for_mock_first_circuit(op_queue); | ||
// Construct an initial circuit; its proof will be recursively verified by the first kernel | ||
info("Initial circuit."); | ||
GoblinUltraBuilder initial_circuit{ goblin.op_queue }; | ||
GoblinTestingUtils::construct_simple_initial_circuit(initial_circuit); | ||
KernelInput kernel_input = goblin.accumulate(initial_circuit); | ||
|
||
// Construct a series of simple Goblin circuits; generate and verify their proofs | ||
size_t NUM_CIRCUITS = 3; | ||
size_t NUM_CIRCUITS = 2; | ||
for (size_t circuit_idx = 0; circuit_idx < NUM_CIRCUITS; ++circuit_idx) { | ||
proof_system::GoblinUltraCircuitBuilder builder{ op_queue }; | ||
|
||
generate_test_circuit(builder); | ||
|
||
// The same composer is used to manage Honk and Merge prover/verifier | ||
proof_system::honk::GoblinUltraComposer composer; | ||
// Construct a circuit with logic resembling that of the "kernel circuit" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its a bit misleading to use the kernel terminology here since the point of this test is that there's no recursion. Not a big deal |
||
info("\nKernel circuit ", circuit_idx); | ||
GoblinUltraBuilder circuit_builder{ goblin.op_queue }; | ||
GoblinTestingUtils::construct_arithmetic_circuit(circuit_builder); | ||
|
||
// Construct and verify Ultra Goblin Honk proof | ||
bool honk_verified = construct_and_verify_honk_proof(composer, builder); | ||
EXPECT_TRUE(honk_verified); | ||
|
||
// Construct and verify op queue merge proof | ||
bool merge_verified = construct_and_verify_merge_proof(composer, op_queue); | ||
EXPECT_TRUE(merge_verified); | ||
// Construct proof of the current kernel circuit to be recursively verified by the next one | ||
kernel_input = goblin.accumulate(circuit_builder); | ||
} | ||
|
||
// Execute the ECCVM | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/785) Properly initialize transcript | ||
auto eccvm_builder = ECCVMBuilder(op_queue); | ||
auto eccvm_composer = ECCVMComposer(); | ||
auto eccvm_prover = eccvm_composer.create_prover(eccvm_builder); | ||
auto eccvm_verifier = eccvm_composer.create_verifier(eccvm_builder); | ||
auto eccvm_proof = eccvm_prover.construct_proof(); | ||
bool eccvm_verified = eccvm_verifier.verify_proof(eccvm_proof); | ||
EXPECT_TRUE(eccvm_verified); | ||
|
||
// Execute the Translator | ||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/786) Properly derive batching_challenge | ||
auto batching_challenge = Fbase::random_element(); | ||
auto evaluation_input = eccvm_prover.evaluation_challenge_x; | ||
proof_system::GoblinTranslatorCircuitBuilder translator_builder{ batching_challenge, evaluation_input, op_queue }; | ||
GoblinTranslatorComposer translator_composer; | ||
GoblinTranslatorProver translator_prover = translator_composer.create_prover(translator_builder); | ||
GoblinTranslatorVerifier translator_verifier = translator_composer.create_verifier(translator_builder); | ||
proof_system::plonk::proof translator_proof = translator_prover.construct_proof(); | ||
bool accumulator_construction_verified = translator_verifier.verify_proof(translator_proof); | ||
bool translation_verified = translator_verifier.verify_translation(eccvm_prover.translation_evaluations); | ||
EXPECT_TRUE(accumulator_construction_verified && translation_verified); | ||
Goblin::Proof proof = goblin.prove(); | ||
bool verified = goblin.verify(proof); | ||
EXPECT_TRUE(verified); | ||
} | ||
|
||
// TODO(https://github.com/AztecProtocol/barretenberg/issues/787) Expand these tests. | ||
} // namespace test_full_goblin_composer |
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.
I never intended these prints to stick around but no strong feelings