Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
verifier.test.cpp
Go to the documentation of this file.
6
7#include <gtest/gtest.h>
8
10
11class AvmVerifierTests : public ::testing::Test {
12 public:
15
17
18 // Helper function to create and verify native proof
25
26 // Helper function to create proof.
28 {
29 auto [trace, public_inputs] = testing::get_minimal_trace_with_pi();
30
31 Prover prover;
32 auto public_inputs_cols = public_inputs.to_columns();
33 const auto proof = prover.prove(std::move(trace));
34 auto vk = AvmProvingHelper::create_verification_key(AvmProvingHelper().get_verification_key());
35
36 return { proof, vk, public_inputs_cols };
37 }
38};
39
40TEST_F(AvmVerifierTests, GoodPublicInputs)
41{
43 GTEST_SKIP() << "Skipping slow test";
44 }
45
46 auto [proof, vk, public_inputs_cols] = create_proof();
47
48 Verifier verifier(vk);
49 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
50
51 ASSERT_TRUE(verified) << "native proof verification failed";
52}
53
54TEST_F(AvmVerifierTests, NegativeBadPublicInputs)
55{
57 GTEST_SKIP() << "Skipping slow test";
58 }
59
60 auto [proof, vk, public_inputs_cols] = create_proof();
61 auto verify_with_corrupt_pi_col = [&](size_t col_idx) {
62 public_inputs_cols[col_idx][5] += FF::one();
63 Verifier verifier(vk);
64 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
65 ASSERT_FALSE(verified)
66 << "native proof verification succeeded, but should have failed due to corruption of public inputs col "
67 << col_idx;
68 public_inputs_cols[col_idx][5] -= FF::one(); // reset
69 };
70 for (size_t col_idx = 0; col_idx < 4; col_idx++) {
71 verify_with_corrupt_pi_col(col_idx);
72 }
73 Verifier verifier(vk);
74 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
75 ASSERT_TRUE(verified) << "native proof verification failed, but should have succeeded";
76}
77
78// Verify that the actual proof size matches COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
79TEST_F(AvmVerifierTests, ProofSizeMatchesComputedConstant)
80{
81 auto [proof, vk, public_inputs_cols] = create_proof();
82
83 const size_t actual_proof_size = proof.size();
84 const size_t computed_proof_size = AvmFlavor::COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS;
85
86 EXPECT_EQ(actual_proof_size, computed_proof_size)
87 << "Actual proof size (" << actual_proof_size << ") does not match COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS ("
88 << computed_proof_size << "). The formula in flavor.hpp needs to be updated.";
89}
90
91} // namespace bb::avm2::constraining
static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
Definition flavor.hpp:104
Proof prove(tracegen::TraceContainer &&trace)
static std::shared_ptr< AvmVerifier::VerificationKey > create_verification_key(const VkData &vk_data)
static NativeProofResult create_proof()
TestTraceContainer trace
TEST_F(AvmRecursiveTests, GoblinRecursionFailsWithWrongPIs)
bool skip_slow_tests()
Check if slow tests should be skipped.
Definition fixtures.cpp:199
std::pair< tracegen::TraceContainer, PublicInputs > get_minimal_trace_with_pi()
Definition fixtures.cpp:183
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::shared_ptr< AvmVerificationKey > verification_key