Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
oink_prover.test.cpp
Go to the documentation of this file.
7
8#include <gtest/gtest.h>
9
10using namespace bb;
11
25
30TEST_F(OinkTests, OinkProverIsDeterministic)
31{
32 Builder circuit;
34 auto prover_instance = std::make_shared<ProverInstance>(circuit);
35 auto verification_key = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
36
37 {
38 // Run OinkProver for the first time
39 OinkProver prover(prover_instance, verification_key, std::make_shared<Transcript>());
40 prover.prove();
41 }
42
43 // Store data generated by Oink prover
44 auto alpha = prover_instance->alpha;
45 auto gate_challenges = prover_instance->gate_challenges;
46 auto w4 = prover_instance->polynomials.w_4();
47 auto lookup_read_counts = prover_instance->polynomials.lookup_read_counts();
48 auto lookup_read_tag = prover_instance->polynomials.lookup_read_tags();
49 auto lookup_inverse = prover_instance->polynomials.lookup_inverses();
50 auto z_perm = prover_instance->polynomials.z_perm();
51 auto databus_inverses = prover_instance->polynomials.get_databus_inverses().get_copy();
52
53 {
54 // Run OinkProver for the second time
55 OinkProver prover(prover_instance, verification_key, std::make_shared<Transcript>());
56 prover.prove();
57 }
58
59 // Check that the data hasn't changed
60 BB_ASSERT_EQ(prover_instance->alpha, alpha);
61
62 for (auto [new_challenge, old_challenge] : zip_view(prover_instance->gate_challenges, gate_challenges)) {
63 BB_ASSERT_EQ(new_challenge, old_challenge);
64 };
65 BB_ASSERT_EQ(prover_instance->polynomials.w_4(), w4);
66 BB_ASSERT_EQ(prover_instance->polynomials.lookup_read_counts(), lookup_read_counts);
67 BB_ASSERT_EQ(prover_instance->polynomials.lookup_read_tags(), lookup_read_tag);
68 BB_ASSERT_EQ(prover_instance->polynomials.lookup_inverses(), lookup_inverse);
69 BB_ASSERT_EQ(prover_instance->polynomials.z_perm(), z_perm);
70 for (auto [new_databus, old_databus] :
71 zip_view(prover_instance->polynomials.get_databus_inverses().get_copy(), databus_inverses)) {
72 BB_ASSERT_EQ(new_databus, old_databus);
73 };
74}
75
76TEST_F(OinkTests, OinkProverCommitments)
77{
78 Builder circuit;
80 auto prover_instance = std::make_shared<ProverInstance>(circuit);
81 auto verification_key = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
82 auto vk_and_hash = std::make_shared<typename Flavor::VKAndHash>(verification_key);
83 auto verifier_instance = std::make_shared<VerifierInstance>(vk_and_hash);
84
85 OinkProver prover(prover_instance, verification_key, std::make_shared<Transcript>());
86 prover.prove();
87 HonkProof proof = prover.export_proof();
88
89 auto prover_commitments =
90 VerifierCommitmentsConstructor<Flavor>::construct(verification_key, prover_instance->commitments);
91
92 auto transcript = std::make_shared<Transcript>();
93 transcript->load_proof(proof);
94 OinkVerifier verifier(verifier_instance, transcript, verification_key->num_public_inputs);
95 verifier.verify();
96
97 auto verifier_commitments = VerifierCommitmentsConstructor<Flavor>::construct(
98 verifier_instance->get_vk(), verifier_instance->witness_commitments);
99
100 for (auto [prover_comm, verifier_comm, label] : zip_view(prover_commitments.get_all(),
101 verifier_commitments.get_all(),
102 decltype(prover_commitments)::get_labels())) {
103 EXPECT_EQ(prover_comm, verifier_comm) << "Mismatch in commitments " << label;
104 }
105}
#define BB_ASSERT_EQ(actual, expected,...)
Definition assert.hpp:83
static void SetUpTestSuite()
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
static void construct_simple_circuit(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
BaseTranscript< Codec, HashFunction > Transcript
MegaCircuitBuilder CircuitBuilder
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key stores commitments to the precomputed (non-witness) polynomials used by the veri...
Base Native verification key class.
Definition flavor.hpp:138
Executes the "Oink" phase of the Honk proving protocol: the initial rounds that commit to witness dat...
void prove(bool emit_alpha=true)
Commit to witnesses, compute relation parameters, and prepare for Sumcheck.
Proof export_proof()
Export the Oink proof.
Verifier counterpart to OinkProver: receives witness commitments, computes relation parameters,...
void verify(bool emit_alpha=true)
Receive witness commitments, compute relation parameters, and prepare for Sumcheck.
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
static Commitments construct(const std::shared_ptr< VerificationKey > &verification_key)
The VerifierInstance encapsulates all the necessary information for a Honk Verifier to verify a proof...
std::string label
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
TEST_F(IPATest, ChallengesAreZero)
Definition ipa.test.cpp:160
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13