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.
14
15#include <gtest/gtest.h>
16
17using namespace bb;
18
19namespace {
24template <typename VK> auto compute_stdlib_vk_hash(const VK& vk)
25{
26 using FF = typename VK::FF;
27 using Builder = typename VK::Builder;
28 using Codec = stdlib::StdlibCodec<FF>;
29
30 auto serialize_to_field_buffer = []<typename T>(const T& input, std::vector<FF>& buffer) {
31 std::vector<FF> input_fields = Codec::template serialize_to_fields<T>(input);
32 buffer.insert(buffer.end(), input_fields.begin(), input_fields.end());
33 };
34
35 std::vector<FF> elements;
36 serialize_to_field_buffer(vk.log_circuit_size, elements);
37 serialize_to_field_buffer(vk.num_public_inputs, elements);
38 serialize_to_field_buffer(vk.pub_inputs_offset, elements);
39
40 for (const auto& commitment : vk.get_all()) {
41 serialize_to_field_buffer(commitment, elements);
42 }
43
44 return stdlib::poseidon2<Builder>::hash(elements);
45}
46} // namespace
47
48template <typename Flavor> class StdlibVerificationKeyTests : public ::testing::Test {
49 public:
50 using NativeFlavor = typename Flavor::NativeFlavor;
51
52 protected:
54};
55
56using FlavorTypes = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>,
63
69{
70 using Flavor = TypeParam;
71 using NativeFlavor = typename Flavor::NativeFlavor;
72 using NativeVerificationKey = typename NativeFlavor::VerificationKey;
73 using StdlibTranscript = typename Flavor::Transcript;
74 using StdlibVerificationKey = typename Flavor::VerificationKey;
75 using OuterBuilder = typename Flavor::CircuitBuilder;
77
78 // Create random circuit to create a vk.
80 if constexpr (IsAnyOf<Flavor, TranslatorRecursiveFlavor, ECCVMRecursiveFlavor>) {
82 } else {
84 using InnerBuilder = typename NativeFlavor::CircuitBuilder;
85
86 InnerBuilder builder;
87 if constexpr (HasIPAAccumulator<NativeFlavor>) {
89 } else {
91 }
92 auto prover_instance = std::make_shared<ProverInstance>(builder);
93 native_vk = std::make_shared<NativeVerificationKey>(prover_instance->get_precomputed());
94 }
95
96 OuterBuilder outer_builder;
97 StdlibVerificationKey vk(&outer_builder, native_vk);
98
99 // First method of hashing: serialize to fields and hash with poseidon2.
100 FF vk_hash_1 = compute_stdlib_vk_hash(vk);
101
102 // Second method of hashing: using hash_with_origin_tagging.
103 // (ECCVM and Translator recursive flavors don't support hash_with_origin_tagging as their VKs are hardcoded)
104 if constexpr (!IsAnyOf<Flavor, TranslatorRecursiveFlavor, ECCVMRecursiveFlavor>) {
105 StdlibTranscript transcript;
106 FF vk_hash_2 = vk.hash_with_origin_tagging(transcript);
107 EXPECT_EQ(vk_hash_1.get_value(), vk_hash_2.get_value());
108 }
109}
typename Flavor::NativeFlavor NativeFlavor
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
ECCVMCircuitBuilder CircuitBuilder
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 of the native Translator flavor.
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(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13