Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
avm_fixed_vk.test.cpp
Go to the documentation of this file.
5
6#include <gtest/gtest.h>
7
8namespace {
9
10using namespace bb::avm2;
11
16bb::avm2::AvmVerifier::VerificationKey from_proving_key_for_testing(const AvmProver::ProvingKey& proving_key)
17{
19 for (auto [polynomial, commitment] : zip_view(proving_key.get_precomputed(), vk.get_all())) {
20 commitment = proving_key.commitment_key.commit(polynomial);
21 }
22 return vk;
23}
24
30{
32 // Serialize commitments using the Codec
33 for (const auto& commitment : commitments) {
34 auto frs = AvmFlavor::Transcript::Codec::serialize_to_fields(commitment);
35 for (const auto& fr : frs) {
36 elements.push_back(fr);
37 }
38 }
39 return AvmFlavor::Transcript::HashFunction::hash(elements);
40}
41
42} // namespace
43
44namespace bb::avm2::constraining {
45
52TEST(AvmFixedVKTests, FixedVKCommitments)
53{
55 AvmTraceGenHelper tracegen_helper;
56 auto trace = tracegen_helper.generate_precomputed_columns();
57
58 auto polynomials = compute_polynomials(trace);
59 auto proving_key = proving_key_from_polynomials(polynomials);
60
61 auto vk_computed = from_proving_key_for_testing(*proving_key);
62 auto vk_computed_commitments = vk_computed.get_all();
63
64 // Get the fixed VK commitments
66
67 // Check that sizes match
68 EXPECT_EQ(vk_computed_commitments.size(), fixed_vk.get_all().size())
69 << "VK commitments size mismatch: computed has " << vk_computed_commitments.size() << " commitments, fixed has "
70 << fixed_vk.get_all().size();
71
72 // Compare each commitment
73 auto labels = vk_computed.get_labels();
74 for (size_t i = 0; i < vk_computed_commitments.size(); ++i) {
75 EXPECT_EQ(vk_computed_commitments[i], fixed_vk.get_all()[i])
76 << "Mismatch at index " << i << " (label: " << labels[i] << ")";
77 }
78
79 // Compare VK hashes
80 FF vk_computed_hash = compute_vk_hash(vk_computed_commitments);
81 FF fixed_vk_hash = AvmHardCodedVKAndHash::vk_hash();
82 EXPECT_EQ(vk_computed_hash, fixed_vk_hash) << "VK hash mismatch";
83
84 // Uncomment to print the commitments formatted for easy copy-paste into avm_fixed_vk.hpp
85 // std::cout << "// Copy these commitments into AvmFixedVKCommitments::get_all():\n";
86 // for (size_t i = 0; i < vk_computed_commitments.size(); ++i) {
87 // const auto& commitment = vk_computed_commitments[i];
88 // if (commitment.is_point_at_infinity()) {
89 // std::cout << "Commitment::infinity()";
90 // } else {
91 // std::cout << "Commitment(uint256_t(\"" << uint256_t(commitment.x) << "\"), uint256_t(\""
92 // << uint256_t(commitment.y) << "\"))";
93 // }
94 // if (i < vk_computed_commitments.size() - 1) {
95 // std::cout << ",";
96 // }
97 // std::cout << " // " << labels[i] << "\n";
98 // }
99}
100
101} // namespace bb::avm2::constraining
Commitment commit(PolynomialSpan< const Fr > polynomial) const
Uses the ProverSRS to create a commitment to p(X)
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
Definition flavor.hpp:101
AvmFlavorSettings::FF FF
Definition flavor.hpp:43
tracegen::TraceContainer generate_precomputed_columns()
TestTraceContainer trace
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer &trace)
std::shared_ptr< AvmProver::ProvingKey > proving_key_from_polynomials(AvmProver::ProverPolynomials &polynomials)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
AvmFlavorSettings::FF FF
Definition field.hpp:10
uint256_t compute_vk_hash(const Builder &circuit_in)
Compute the hash of the verification key that results from constructing a proving key from the given ...
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