-
Notifications
You must be signed in to change notification settings - Fork 130
test: more vk tests to compare circuit/native/vk_data #310
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b465581
align native and circuit vk hashing methods
iAmMichaelConnor 89249db
fix: pass hash_index to circuit vk function
iAmMichaelConnor 54e0216
add some of the composer_type/plookup toggling for vk compress. Add s…
16af1d8
rename key_witnesses->preimage_data and composer type compression to …
f43895f
some native verification_key_data tests
5b2dca0
Mc/hash vk (#306)
iAmMichaelConnor 5b88780
verification key tests
6c101be
inc num_generators_per_hash_index to 128. (#309)
suyash67 deccd39
merged in a3
df4d08d
revert bad changes to eval domain
313c803
add vk recursion tests to CI, remove old info in vk test
c6211df
merge in a3
10fd0d0
Remove new CI job in config.yml
dbanks12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 91 additions & 33 deletions
124
cpp/src/barretenberg/stdlib/recursion/verification_key/verification_key.test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,100 @@ | ||
| #include "verification_key.hpp" | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "barretenberg/ecc/curves/bn254/fr.hpp" | ||
| #include "barretenberg/ecc/curves/bn254/g1.hpp" | ||
| #include "barretenberg/common/test.hpp" | ||
| #include "barretenberg/proof_system/verification_key/verification_key.hpp" | ||
| #include "barretenberg/plonk/proof_system/constants.hpp" | ||
| #include "barretenberg/stdlib/types/types.hpp" | ||
|
|
||
| using namespace plonk; | ||
| #include "barretenberg/plonk/composer/standard_composer.hpp" | ||
| #include "barretenberg/plonk/composer/turbo_composer.hpp" | ||
| #include "barretenberg/plonk/composer/ultra_composer.hpp" | ||
| #include "verification_key.hpp" | ||
|
|
||
| namespace { | ||
| auto& engine = numeric::random::get_debug_engine(); | ||
| } | ||
| } // namespace | ||
|
|
||
| /** | ||
| * @brief A test fixture that will let us generate VK data and run tests | ||
| * for all composer types | ||
| * | ||
| * @tparam Composer | ||
| */ | ||
| template <typename Composer> class VerificationKeyFixture : public testing::Test { | ||
| public: | ||
| using Curve = stdlib::bn254<Composer>; | ||
| using RecursVk = plonk::stdlib::recursion::verification_key<Curve>; | ||
|
|
||
| static Composer init_composer() { | ||
| return Composer("../srs_db/ignition"); | ||
| } | ||
|
|
||
| /** | ||
| * @brief generate a random vk data for use in tests | ||
| * | ||
| * @return verification_key_data randomly generated | ||
| */ | ||
| static verification_key_data rand_vk_data() { | ||
| verification_key_data vk_data; | ||
| vk_data.composer_type = static_cast<uint32_t>(Composer::type); | ||
| vk_data.circuit_size = 1024; // not random - must be power of 2 | ||
| vk_data.num_public_inputs = engine.get_random_uint32(); | ||
| vk_data.commitments["test1"] = g1::element::random_element(); | ||
| vk_data.commitments["test2"] = g1::element::random_element(); | ||
| vk_data.commitments["foo1"] = g1::element::random_element(); | ||
| vk_data.commitments["foo2"] = g1::element::random_element(); | ||
| return vk_data; | ||
| } | ||
| }; | ||
|
|
||
| // Each test will run for all composer types | ||
| using ComposerTypes = testing::Types<plonk::StandardComposer, plonk::TurboComposer, plonk::UltraComposer, honk::StandardHonkComposer>; | ||
| TYPED_TEST_SUITE(VerificationKeyFixture, ComposerTypes); | ||
|
|
||
| verification_key_data rand_vk_data(plonk::ComposerType composer_type) | ||
| TYPED_TEST(VerificationKeyFixture, vk_data_vs_recursion_compress_native) | ||
| { | ||
| verification_key_data key_data; | ||
| key_data.composer_type = static_cast<uint32_t>(composer_type); | ||
| key_data.circuit_size = 1024; // not random - must be power of 2 | ||
| key_data.num_public_inputs = engine.get_random_uint16(); | ||
| key_data.commitments["test1"] = g1::element::random_element(); | ||
| key_data.commitments["test2"] = g1::element::random_element(); | ||
| key_data.commitments["foo1"] = g1::element::random_element(); | ||
| key_data.commitments["foo2"] = g1::element::random_element(); | ||
| return key_data; | ||
| using RecursVk = typename TestFixture::RecursVk; | ||
| auto composer = TestFixture::init_composer(); | ||
|
|
||
| verification_key_data vk_data = TestFixture::rand_vk_data(); | ||
| verification_key_data vk_data_copy = vk_data; | ||
|
|
||
| auto file_crs = std::make_unique<bonk::FileReferenceStringFactory>("../srs_db/ignition"); | ||
| auto file_verifier = file_crs->get_verifier_crs(); | ||
|
|
||
| auto native_vk = std::make_shared<bonk::verification_key>(std::move(vk_data_copy), file_verifier); | ||
| auto recurs_vk = RecursVk::from_witness(&composer, native_vk); | ||
|
|
||
| EXPECT_EQ(vk_data.compress_native(0), RecursVk::compress_native(native_vk, 0)); | ||
| EXPECT_EQ(vk_data.compress_native(15), RecursVk::compress_native(native_vk, 15)); | ||
| // ne hash indeces still lead to ne compressions | ||
| EXPECT_NE(vk_data.compress_native(0), RecursVk::compress_native(native_vk, 15)); | ||
| EXPECT_NE(vk_data.compress_native(14), RecursVk::compress_native(native_vk, 15)); | ||
| } | ||
|
|
||
| TEST(stdlib_verification_key, compress_native_comparison) | ||
| TYPED_TEST(VerificationKeyFixture, compress_vs_compress_native) | ||
| { | ||
| // Compute compression of native verification key (i.e. vk_data) | ||
| auto crs = std::make_unique<bonk::FileReferenceStringFactory>("../srs_db/ignition"); | ||
| verification_key_data vk_data = rand_vk_data(stdlib::types::Composer::type); | ||
| const size_t hash_idx = 10; | ||
| auto native_vk_compression = vk_data.compress_native(hash_idx); | ||
|
|
||
| // Compute compression of recursive verification key | ||
| auto verification_key = std::make_shared<bonk::verification_key>(std::move(vk_data), crs->get_verifier_crs()); | ||
| auto recursive_vk_compression = | ||
| stdlib::recursion::verification_key<stdlib::types::bn254>::compress_native(verification_key, hash_idx); | ||
| EXPECT_EQ(native_vk_compression, recursive_vk_compression); | ||
| } | ||
| using RecursVk = typename TestFixture::RecursVk; | ||
| auto composer = TestFixture::init_composer(); | ||
|
|
||
| verification_key_data vk_data = TestFixture::rand_vk_data(); | ||
|
|
||
| auto file_crs = std::make_unique<bonk::FileReferenceStringFactory>("../srs_db/ignition"); | ||
| auto file_verifier = file_crs->get_verifier_crs(); | ||
|
|
||
| auto native_vk = std::make_shared<bonk::verification_key>(std::move(vk_data), file_verifier); | ||
| auto recurs_vk = RecursVk::from_witness(&composer, native_vk); | ||
|
|
||
| EXPECT_EQ( | ||
| recurs_vk->compress(0).get_value(), | ||
| RecursVk::compress_native(native_vk, 0) | ||
| ); | ||
| EXPECT_EQ( | ||
| recurs_vk->compress(15).get_value(), | ||
| RecursVk::compress_native(native_vk, 15) | ||
| ); | ||
| // ne hash indeces still lead to ne compressions | ||
| EXPECT_NE( | ||
| recurs_vk->compress(0).get_value(), | ||
| RecursVk::compress_native(native_vk, 15) | ||
| ); | ||
| EXPECT_NE( | ||
| recurs_vk->compress(14).get_value(), | ||
| RecursVk::compress_native(native_vk, 15) | ||
| ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 suppose you've added a separate circleci trigger so that
ultra-recursiondoesn't exceed 20 minute limit? But this thing now would run twice: once while running{ stdlib_recursion_tests } - { *turbo* }and other would bestdlib-verification-key-tests.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.
Correct itll run in its own job so it shouldn't exceed the limit. Ah you're right about it running twice. Should I filter the ultra tests to omit the vk tests too? Could we filter on the word "ultra" instead?