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
23
24 // Helper function to create proof.
26 {
27 auto [trace, public_inputs] = testing::get_minimal_trace_with_pi();
28
29 Prover prover;
30 auto public_inputs_cols = public_inputs.to_columns();
31 const auto proof = prover.prove(std::move(trace));
32
33 return { proof, public_inputs_cols };
34 }
35};
36
37TEST_F(AvmVerifierTests, GoodPublicInputs)
38{
40 GTEST_SKIP() << "Skipping slow test";
41 }
42
43 auto [proof, public_inputs_cols] = create_proof();
44
45 Verifier verifier;
46 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
47
48 ASSERT_TRUE(verified) << "native proof verification failed";
49}
50
51TEST_F(AvmVerifierTests, NegativeBadPublicInputs)
52{
54 GTEST_SKIP() << "Skipping slow test";
55 }
56
57 auto [proof, public_inputs_cols] = create_proof();
58 auto verify_with_corrupt_pi_col = [&](size_t col_idx) {
59 public_inputs_cols[col_idx][5] += FF::one();
60 Verifier verifier;
61 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
62 ASSERT_FALSE(verified)
63 << "native proof verification succeeded, but should have failed due to corruption of public inputs col "
64 << col_idx;
65 public_inputs_cols[col_idx][5] -= FF::one(); // reset
66 };
67 for (size_t col_idx = 0; col_idx < 4; col_idx++) {
68 verify_with_corrupt_pi_col(col_idx);
69 }
70 Verifier verifier;
71 const bool verified = verifier.verify_proof(proof, public_inputs_cols);
72 ASSERT_TRUE(verified) << "native proof verification failed, but should have succeeded";
73}
74
75// Verify that the actual proof size matches COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
76TEST_F(AvmVerifierTests, ProofSizeMatchesComputedConstant)
77{
78 auto [proof, public_inputs_cols] = create_proof();
79
80 const size_t actual_proof_size = proof.size();
81 const size_t computed_proof_size = AvmFlavor::COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS;
82
83 EXPECT_EQ(actual_proof_size, computed_proof_size)
84 << "Actual proof size (" << actual_proof_size << ") does not match COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS ("
85 << computed_proof_size << "). The formula in flavor.hpp needs to be updated.";
86}
87
88} // namespace bb::avm2::constraining
static constexpr size_t COMPUTED_AVM_PROOF_LENGTH_IN_FIELDS
Definition flavor.hpp:99
Proof prove(tracegen::TraceContainer &&trace)
static NativeProofResult create_proof()
TestTraceContainer trace
TEST_F(AvmRecursiveTests, TwoLayerAvmRecursionFailsWithWrongPIs)
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)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13