-
Notifications
You must be signed in to change notification settings - Fork 597
feat: Verification key stuff #8431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0715947
9f03f14
46cbe66
4db1053
3f5e4a0
6bac4ee
db4f96f
7d6bc1d
bbfb330
61817ea
e910c5f
2287930
f588418
4b11491
4954154
d0f1073
e5a4f0b
29366ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,7 +93,7 @@ std::vector<bb::fr> convert_grumpkin_fr_to_bn254_frs(const grumpkin::fr& val); | |
| */ | ||
| template <typename T> std::vector<bb::fr> convert_to_bn254_frs(const T& val) | ||
| { | ||
| if constexpr (IsAnyOf<T, bool, uint32_t, uint64_t, bb::fr>) { | ||
| if constexpr (IsAnyOf<T, bool, uint32_t, uint64_t, size_t, bb::fr>) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does this come into use?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some of the databus_propagation_data components are
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size_t is pretty scary for serde though, so I expect this to lead to trouble when we try to do any sort of mega flavor verification key serde through wasm.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotcha - I'll make a TODO to try to change the databus data to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually was able to make this change pretty easily so its done |
||
| std::vector<bb::fr> fr_vec{ val }; | ||
| return fr_vec; | ||
| } else if constexpr (IsAnyOf<T, grumpkin::fr>) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,10 +93,10 @@ namespace bb { | |
| */ | ||
| class PrecomputedEntitiesBase { | ||
| public: | ||
| bool operator==(const PrecomputedEntitiesBase& other) const = default; | ||
| uint64_t circuit_size; | ||
| uint64_t log_circuit_size; | ||
| uint64_t num_public_inputs; | ||
| CircuitType circuit_type; // TODO(#392) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this was just unused huh
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah was pretty surprised myself - not a single thing broke when I deleted it |
||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -158,6 +158,7 @@ class VerificationKey_ : public PrecomputedCommitments { | |
| AggregationObjectPubInputIndices recursive_proof_public_input_indices = {}; | ||
| uint64_t pub_inputs_offset = 0; | ||
|
|
||
| bool operator==(const VerificationKey_&) const = default; | ||
| VerificationKey_() = default; | ||
| VerificationKey_(const size_t circuit_size, const size_t num_public_inputs) | ||
| { | ||
|
|
@@ -173,32 +174,25 @@ class VerificationKey_ : public PrecomputedCommitments { | |
| */ | ||
| std::vector<FF> to_field_elements() | ||
| { | ||
| using namespace bb::field_conversion; | ||
|
|
||
| auto serialize_to_field_buffer = [](const auto& input, std::vector<FF>& buffer) { | ||
| std::vector<FF> input_fields = convert_to_bn254_frs(input); | ||
| buffer.insert(buffer.end(), input_fields.begin(), input_fields.end()); | ||
| }; | ||
|
|
||
| std::vector<FF> elements; | ||
| std::vector<FF> circuit_size_elements = bb::field_conversion::convert_to_bn254_frs(this->circuit_size); | ||
| elements.insert(elements.end(), circuit_size_elements.begin(), circuit_size_elements.end()); | ||
| // do the same for the rest of the fields | ||
| std::vector<FF> num_public_inputs_elements = | ||
| bb::field_conversion::convert_to_bn254_frs(this->num_public_inputs); | ||
| elements.insert(elements.end(), num_public_inputs_elements.begin(), num_public_inputs_elements.end()); | ||
| std::vector<FF> pub_inputs_offset_elements = | ||
| bb::field_conversion::convert_to_bn254_frs(this->pub_inputs_offset); | ||
| elements.insert(elements.end(), pub_inputs_offset_elements.begin(), pub_inputs_offset_elements.end()); | ||
|
|
||
| std::vector<FF> contains_recursive_proof_elements = | ||
| bb::field_conversion::convert_to_bn254_frs(this->contains_recursive_proof); | ||
| elements.insert( | ||
| elements.end(), contains_recursive_proof_elements.begin(), contains_recursive_proof_elements.end()); | ||
|
|
||
| std::vector<FF> recursive_proof_public_input_indices_elements = | ||
| bb::field_conversion::convert_to_bn254_frs(this->recursive_proof_public_input_indices); | ||
| elements.insert(elements.end(), | ||
| recursive_proof_public_input_indices_elements.begin(), | ||
| recursive_proof_public_input_indices_elements.end()); | ||
|
|
||
| for (Commitment& comm : this->get_all()) { | ||
| std::vector<FF> comm_elements = bb::field_conversion::convert_to_bn254_frs(comm); | ||
| elements.insert(elements.end(), comm_elements.begin(), comm_elements.end()); | ||
|
|
||
| serialize_to_field_buffer(this->circuit_size, elements); | ||
| serialize_to_field_buffer(this->num_public_inputs, elements); | ||
| serialize_to_field_buffer(this->pub_inputs_offset, elements); | ||
| serialize_to_field_buffer(this->contains_recursive_proof, elements); | ||
| serialize_to_field_buffer(this->recursive_proof_public_input_indices, elements); | ||
|
|
||
| for (Commitment& commitment : this->get_all()) { | ||
| serialize_to_field_buffer(commitment, elements); | ||
| } | ||
|
|
||
| return elements; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ { | |
| using Builder = typename Flavor::CircuitBuilder; | ||
| using NativeFlavor = typename Flavor::NativeFlavor; | ||
| using DeciderVerificationKey = bb::DeciderVerificationKey_<NativeFlavor>; | ||
| using VerifierCommitmentKey = typename NativeFlavor::VerifierCommitmentKey; | ||
|
|
||
| Builder* builder; | ||
|
|
||
|
|
@@ -101,7 +102,9 @@ template <IsRecursiveFlavor Flavor> class RecursiveDeciderVerificationKey_ { | |
| { | ||
| auto native_honk_vk = std::make_shared<NativeVerificationKey>(verification_key->circuit_size, | ||
| verification_key->num_public_inputs); | ||
| native_honk_vk->pcs_verification_key = verification_key->pcs_verification_key; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. odd this worked before...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah it was indeed setting it to null in the previous usage but we just never ended up using it. It only came up for me in the verification of the AztecIvc proof |
||
| native_honk_vk->pcs_verification_key = verification_key->pcs_verification_key == nullptr | ||
| ? std::make_shared<VerifierCommitmentKey>() | ||
| : verification_key->pcs_verification_key; | ||
| native_honk_vk->pub_inputs_offset = verification_key->pub_inputs_offset; | ||
| native_honk_vk->contains_recursive_proof = verification_key->contains_recursive_proof; | ||
| native_honk_vk->recursive_proof_public_input_indices = verification_key->recursive_proof_public_input_indices; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #include "barretenberg/common/serialize.hpp" | ||
| #include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
| #include "barretenberg/numeric/uint256/uint256.hpp" | ||
| #include "barretenberg/plonk_honk_shared/library/grand_product_delta.hpp" | ||
| #include "barretenberg/relations/permutation_relation.hpp" | ||
| #include "barretenberg/relations/relation_parameters.hpp" | ||
| #include "barretenberg/stdlib_circuit_builders/mock_circuits.hpp" | ||
| #include "barretenberg/stdlib_circuit_builders/plookup_tables/fixed_base/fixed_base.hpp" | ||
| #include "barretenberg/stdlib_circuit_builders/plookup_tables/types.hpp" | ||
| #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
| #include "barretenberg/sumcheck/sumcheck_round.hpp" | ||
| #include "barretenberg/ultra_honk/ultra_prover.hpp" | ||
| #include "barretenberg/ultra_honk/ultra_verifier.hpp" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| using namespace bb; | ||
|
|
||
| template <typename Flavor> class FlavorSerializationTests : public ::testing::Test { | ||
| public: | ||
| using Builder = typename Flavor::CircuitBuilder; | ||
| using DeciderProvingKey = DeciderProvingKey_<Flavor>; | ||
| using VerificationKey = typename Flavor::VerificationKey; | ||
|
|
||
| protected: | ||
| static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } | ||
| }; | ||
|
|
||
| using FlavorTypes = testing::Types<UltraFlavor, UltraKeccakFlavor, MegaFlavor>; | ||
| TYPED_TEST_SUITE(FlavorSerializationTests, FlavorTypes); | ||
|
|
||
| // Test msgpack serialization/deserialization of verification keys | ||
| TYPED_TEST(FlavorSerializationTests, VerificationKeySerialization) | ||
| { | ||
| using Builder = typename TestFixture::Builder; | ||
| using DeciderProvingKey = typename TestFixture::DeciderProvingKey; | ||
| using VerificationKey = typename TestFixture::VerificationKey; | ||
|
|
||
| Builder builder; | ||
|
|
||
| // Add some arbitrary arithmetic gates that utilize public inputs | ||
| MockCircuits::add_arithmetic_gates_with_public_inputs(builder, /*num_gates=*/100); | ||
|
|
||
| auto proving_key = std::make_shared<DeciderProvingKey>(builder); | ||
| VerificationKey original_vkey{ proving_key->proving_key }; | ||
|
|
||
| // Set the pcs ptr to null since this will not be reconstructed correctly from buffer | ||
| original_vkey.pcs_verification_key = nullptr; | ||
|
|
||
| // Populate some non-zero values in the databus_propagation_data to ensure its being handled | ||
| if constexpr (IsMegaBuilder<Builder>) { | ||
| original_vkey.databus_propagation_data.contains_app_return_data_commitment = 1; | ||
| original_vkey.databus_propagation_data.contains_kernel_return_data_commitment = 1; | ||
| original_vkey.databus_propagation_data.app_return_data_public_input_idx = 2; | ||
| original_vkey.databus_propagation_data.kernel_return_data_public_input_idx = 4; | ||
| original_vkey.databus_propagation_data.is_kernel = 1; | ||
| } | ||
|
|
||
| // Serialize and deserialize the verification key | ||
| std::vector<uint8_t> vkey_buffer = to_buffer(original_vkey); | ||
| VerificationKey deserialized_vkey = from_buffer<VerificationKey>(vkey_buffer); | ||
|
|
||
| // Ensure the original is equal to the reconstructed | ||
| EXPECT_EQ(original_vkey, deserialized_vkey); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we still have this for the cases where we don't actually get stdlib vkeys. Will this eventually go away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess tests might not use stdlib vkeys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah exactly, I left this pathway for tests