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.
12
13#include <gtest/gtest.h>
14
15using namespace bb;
16
17namespace {
22template <typename VK> auto compute_stdlib_vk_hash(const VK& vk)
23{
24 using FF = typename VK::FF;
25 using Builder = typename VK::Builder;
26 using Codec = stdlib::StdlibCodec<FF>;
27
28 auto serialize_to_field_buffer = []<typename T>(const T& input, std::vector<FF>& buffer) {
29 std::vector<FF> input_fields = Codec::template serialize_to_fields<T>(input);
30 buffer.insert(buffer.end(), input_fields.begin(), input_fields.end());
31 };
32
33 std::vector<FF> elements;
34 serialize_to_field_buffer(vk.log_circuit_size, elements);
35 serialize_to_field_buffer(vk.num_public_inputs, elements);
36 serialize_to_field_buffer(vk.pub_inputs_offset, elements);
37
38 for (const auto& commitment : vk.get_all()) {
39 serialize_to_field_buffer(commitment, elements);
40 }
41
42 return stdlib::poseidon2<Builder>::hash(elements);
43}
44} // namespace
45
46template <typename Flavor> class StdlibVerificationKeyTests : public ::testing::Test {
47 public:
48 using NativeFlavor = typename Flavor::NativeFlavor;
49
50 protected:
52};
53
54using FlavorTypes = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>,
59
65{
66 using Flavor = TypeParam;
67 using NativeFlavor = typename Flavor::NativeFlavor;
68 using NativeVerificationKey = typename NativeFlavor::VerificationKey;
69 using StdlibTranscript = typename Flavor::Transcript;
70 using StdlibVerificationKey = typename Flavor::VerificationKey;
71 using OuterBuilder = typename Flavor::CircuitBuilder;
73
74 // Create random circuit to create a vk.
77 using InnerBuilder = typename NativeFlavor::CircuitBuilder;
78
79 InnerBuilder builder;
80 if constexpr (HasIPAAccumulator<NativeFlavor>) {
82 } else {
84 }
85 auto prover_instance = std::make_shared<ProverInstance>(builder);
86 native_vk = std::make_shared<NativeVerificationKey>(prover_instance->get_precomputed());
87
88 OuterBuilder outer_builder;
89 StdlibVerificationKey vk(&outer_builder, native_vk);
90
91 // First method of hashing: serialize to fields and hash with poseidon2.
92 FF vk_hash_1 = compute_stdlib_vk_hash(vk);
93
94 // Second method of hashing: using hash_with_origin_tagging.
95 StdlibTranscript transcript;
96 FF vk_hash_2 = vk.hash_with_origin_tagging(transcript);
97 EXPECT_EQ(vk_hash_1.get_value(), vk_hash_2.get_value());
98}
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.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The recursive counterpart to the "native" Ultra flavor.
The recursive counterpart to the "native" UltraRollupFlavor.
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.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
AluTraceBuilder builder
Definition alu.test.cpp:124
uint8_t buffer[RANDOM_BUFFER_SIZE]
Definition engine.cpp:34
testing::Types< MegaFlavor, UltraFlavor, UltraZKFlavor, UltraRollupFlavor > 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