Skip to content

Commit

Permalink
simplify rec merge verifier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ledwards2225 committed Dec 6, 2023
1 parent a3b3f6b commit 7a86389
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ TEST_F(GoblinRecursionTests, Pseudo)
GoblinUltraBuilder initial_circuit{ goblin.op_queue };
GoblinTestingUtils::construct_simple_initial_circuit(initial_circuit);

// Note: On the first call to accumulate there is no merge proof to recursively verify
KernelInput kernel_input = goblin.accumulate(initial_circuit);

// Construct a series of simple Goblin circuits; generate and verify their proofs
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/goblin/mock_circuits.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "barretenberg/commitment_schemes/commitment_key.hpp"
#include "barretenberg/flavor/goblin_ultra.hpp"
#include "barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp"
#include "barretenberg/srs/global_crs.hpp"

namespace barretenberg {
class GoblinTestingUtils {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "barretenberg/common/test.hpp"
#include "barretenberg/goblin/mock_circuits.hpp"
#include "barretenberg/stdlib/primitives/curves/bn254.hpp"
#include "barretenberg/stdlib/recursion/honk/verifier/merge_recursive_verifier.hpp"
#include "barretenberg/ultra_honk/ultra_composer.hpp"
Expand Down Expand Up @@ -30,69 +31,9 @@ class RecursiveMergeVerifierTest : public testing::Test {
using FF = InnerFlavor::FF;
using VerifierCommitmentKey = ::proof_system::honk::pcs::VerifierCommitmentKey<curve::BN254>;

/**
* @brief Generate a simple test circuit with some ECC op gates and conventional arithmetic gates
*
* @param builder
*/
static proof_system::GoblinUltraCircuitBuilder generate_sample_circuit(const std::shared_ptr<ECCOpQueue>& op_queue)
{
// Create an arbitrary inner circuit
InnerBuilder builder{ op_queue };

// Add some arbitrary ecc op gates
for (size_t i = 0; i < 3; ++i) {
auto point = Commitment::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) });
}

return builder;
}

public:
static void SetUpTestSuite() { barretenberg::srs::init_crs_factory("../srs_db/ignition"); }

/**
* @brief Test native merge proof construction/verification for the sample circuit
*
*/
static void test_sample_circuit_merge()
{
auto op_queue = std::make_shared<ECCOpQueue>();

// Populate op queue with mock initial data since we don't handle the empty previous aggregate transcript case
op_queue->populate_with_mock_initital_data();

// Create an arbitrary inner circuit with goblin ECC op gates
InnerBuilder sample_circuit = generate_sample_circuit(op_queue);

// Construct and natively verify the merge proof
InnerComposer composer;
auto merge_prover = composer.create_merge_prover(op_queue);
auto merge_verifier = composer.create_merge_verifier();
auto merge_proof = merge_prover.construct_proof();
bool verified = merge_verifier.verify_proof(merge_proof);
EXPECT_TRUE(verified);
}

/**
* @brief Test recursive merge verification for the ops generated by a sample circuit
* @details We construct and verify an Ultra Honk proof of the recursive merge verifier circuit to check its
Expand All @@ -102,10 +43,9 @@ class RecursiveMergeVerifierTest : public testing::Test {
static void test_recursive_merge_verification()
{
auto op_queue = std::make_shared<ECCOpQueue>();
op_queue->populate_with_mock_initital_data();

// Create an arbitrary inner circuit
InnerBuilder inner_circuit = generate_sample_circuit(op_queue);
InnerBuilder sample_circuit{ op_queue };
GoblinTestingUtils::construct_simple_initial_circuit(sample_circuit);

// Generate a proof over the inner circuit
InnerComposer inner_composer;
Expand Down Expand Up @@ -152,11 +92,6 @@ class RecursiveMergeVerifierTest : public testing::Test {
}
};

TEST_F(RecursiveMergeVerifierTest, NativeSampleCircuitMerge)
{
RecursiveMergeVerifierTest::test_sample_circuit_merge();
};

TEST_F(RecursiveMergeVerifierTest, SingleRecursiveVerification)
{
RecursiveMergeVerifierTest::test_recursive_merge_verification();
Expand Down

0 comments on commit 7a86389

Please sign in to comment.