Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
stdlib_verification_key.test.cpp
Go to the documentation of this file.
11
12#include <gtest/gtest.h>
13
14using namespace bb;
15
16namespace {
21template <typename VK> auto compute_stdlib_vk_hash(const VK& vk)
22{
23 using FF = typename VK::FF;
24 using Builder = typename VK::Builder;
25 using Codec = stdlib::StdlibCodec<FF>;
26
27 auto serialize_to_field_buffer = []<typename T>(const T& input, std::vector<FF>& buffer) {
28 std::vector<FF> input_fields = Codec::template serialize_to_fields<T>(input);
29 buffer.insert(buffer.end(), input_fields.begin(), input_fields.end());
30 };
31
32 std::vector<FF> elements;
33 serialize_to_field_buffer(vk.log_circuit_size, elements);
34 serialize_to_field_buffer(vk.num_public_inputs, elements);
35 serialize_to_field_buffer(vk.pub_inputs_offset, elements);
36
37 for (const auto& commitment : vk.get_all()) {
38 serialize_to_field_buffer(commitment, elements);
39 }
40
41 return stdlib::poseidon2<Builder>::hash(elements);
42}
43} // namespace
44
45template <typename Flavor> class StdlibVerificationKeyTests : public ::testing::Test {
46 public:
47 using NativeFlavor = typename Flavor::NativeFlavor;
48
49 protected:
51};
52
53using FlavorTypes = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>,
57
63{
64 using Flavor = TypeParam;
65 using NativeFlavor = typename Flavor::NativeFlavor;
66 using NativeVerificationKey = typename NativeFlavor::VerificationKey;
67 using StdlibTranscript = typename Flavor::Transcript;
68 using StdlibVerificationKey = typename Flavor::VerificationKey;
69 using OuterBuilder = typename Flavor::CircuitBuilder;
71
72 // Create random circuit to create a vk.
75 using InnerBuilder = typename NativeFlavor::CircuitBuilder;
76
77 InnerBuilder builder;
79 auto prover_instance = std::make_shared<ProverInstance>(builder);
80 native_vk = std::make_shared<NativeVerificationKey>(prover_instance->get_precomputed());
81
82 OuterBuilder outer_builder;
83 StdlibVerificationKey vk(&outer_builder, native_vk);
84
85 // First method of hashing: serialize to fields and hash with poseidon2.
86 FF vk_hash_1 = compute_stdlib_vk_hash(vk);
87
88 // Second method of hashing: using hash_with_origin_tagging.
89 StdlibTranscript transcript;
90 FF vk_hash_2 = vk.hash_with_origin_tagging(transcript);
91 EXPECT_EQ(vk_hash_1.get_value(), vk_hash_2.get_value());
92}
typename Flavor::NativeFlavor NativeFlavor
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
ECCVMCircuitBuilder CircuitBuilder
FixedVKAndHash_< PrecomputedEntities< Commitment >, BF, ECCVMHardcodedVKAndHash > VerificationKey
The verification key stores commitments to the precomputed polynomials used by the verifier.
BaseTranscript< Codec, HashFunction > Transcript
The recursive counterpart to the "native" Mega flavor.
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
The recursive counterpart to the "native" Ultra flavor.
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
AluTraceBuilder builder
Definition alu.test.cpp:124
std::unique_ptr< uint8_t[]> buffer
Definition engine.cpp:50
testing::Types< UltraFlavor, UltraKeccakFlavor, MegaFlavor > FlavorTypes
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
TYPED_TEST_SUITE(CommitmentKeyTest, Curves)
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
StdlibCodec for in-circuit (recursive) verification transcript handling.