From 173980a19253532b2395fb58f5b8fc2ec6301f2b Mon Sep 17 00:00:00 2001 From: tigran-at-nil Date: Tue, 16 Jul 2024 19:01:45 +0400 Subject: [PATCH] Added tests of alt_bn128_254 in various suitest --- .../marshalling/zk/test/placeholder_proof.cpp | 102 ++++++++++-------- libs/zk/test/commitment/kzg.cpp | 61 ++++++++++- .../plonk/placeholder/placeholder_kzg.cpp | 11 +- 3 files changed, 124 insertions(+), 50 deletions(-) diff --git a/libs/marshalling/zk/test/placeholder_proof.cpp b/libs/marshalling/zk/test/placeholder_proof.cpp index 19bd0d939..65fab9231 100644 --- a/libs/marshalling/zk/test/placeholder_proof.cpp +++ b/libs/marshalling/zk/test/placeholder_proof.cpp @@ -58,10 +58,13 @@ #include #include #include -/* + +/**/ #include +#include #include -*/ +/**/ + #include #include #include @@ -1209,48 +1212,59 @@ struct placeholder_kzg_test_fixture_v2 : public test_tools::random_test_initiali BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2) using TestFixtures = boost::mpl::list< - placeholder_kzg_test_fixture_v2< - algebra::curves::bls12_381, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - /* - , placeholder_kzg_test_fixture< - algebra::curves::alt_bn128_254, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - 4, true> - */ - , placeholder_kzg_test_fixture_v2< - algebra::curves::mnt4_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> - , placeholder_kzg_test_fixture_v2< - algebra::curves::mnt6_298, - hashes::keccak_1600<256>, - hashes::keccak_1600<256>, - witness_columns_t, - public_columns_t, - constant_columns_t, - selector_columns_t, - usable_rows_t, - true> + placeholder_kzg_test_fixture_v2< + algebra::curves::bls12_381, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + + , placeholder_kzg_test_fixture_v2< + algebra::curves::alt_bn128_254, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + + /*, placeholder_kzg_test_fixture< + algebra::curves::alt_bn128_254, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + 4, true>*/ + + , placeholder_kzg_test_fixture_v2< + algebra::curves::mnt4_298, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> + , placeholder_kzg_test_fixture_v2< + algebra::curves::mnt6_298, + hashes::keccak_1600<256>, + hashes::keccak_1600<256>, + witness_columns_t, + public_columns_t, + constant_columns_t, + selector_columns_t, + usable_rows_t, + true> /*, -- Not yet implemented placeholder_kzg_test_fixture< algebra::curves::mnt6_298, diff --git a/libs/zk/test/commitment/kzg.cpp b/libs/zk/test/commitment/kzg.cpp index a543d4d0a..fa926e16f 100644 --- a/libs/zk/test/commitment/kzg.cpp +++ b/libs/zk/test/commitment/kzg.cpp @@ -57,6 +57,10 @@ #include #include +#include +#include +#include + #include #include @@ -108,7 +112,8 @@ struct kzg_basic_test_runner { using BasicTestFixtures = boost::mpl::list< kzg_basic_test_runner, kzg_basic_test_runner, - kzg_basic_test_runner + kzg_basic_test_runner, + kzg_basic_test_runner >; BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_basic_test, F, BasicTestFixtures) { @@ -144,7 +149,8 @@ struct kzg_random_test_runner { using RandomTestFixtures = boost::mpl::list< kzg_random_test_runner, kzg_random_test_runner, - kzg_random_test_runner + kzg_random_test_runner, + kzg_random_test_runner >; BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_random_test, F, RandomTestFixtures) { @@ -250,6 +256,51 @@ BOOST_AUTO_TEST_CASE(kzg_test_mnt6_accumulated) { } BOOST_AUTO_TEST_SUITE_END() +/*BOOST_AUTO_TEST_CASE(kzg_test_alt_bn128_254_accumulated) { + + typedef algebra::curves::alt_bn128_254 curve_type; + typedef typename curve_type::scalar_field_type::value_type scalar_value_type; + + typedef zk::commitments::kzg kzg_type; + + scalar_value_type alpha = 7u; + std::size_t n = 8; + scalar_value_type z = 2u; + const polynomial f = { + 0x0ed6fb07f52c1f1ef7952250702368474f20fd7af906ba3a5842cdb7946c69b603852bf1069_cppui_modular298, + 0x14db9efba58de09f8ccb1d73fefce45393856e6a7509006561fe67ea354ec69d791b44c1476_cppui_modular298, + 0x0e9fa83a6f8891bc7e6aa1afae85e11dd80cdef32dfcef7cedc12792cf74141c899c8fb1f98_cppui_modular298, + 0x101cc0b43782ca40ae5bf96aabf461e1a623ab9284acac3bb6d55bff4429356dad714ee0bd0_cppui_modular298, + 0x1310586a4d1ed251d1e4c95711fb9346a2b233649f5ce32fe1cf3aea423d131787187a13799_cppui_modular298, + 0x0d9ed064a24e83ac6134de7cca08bdc3e31ffd4db0a004b63039f76821ec2cc53b7e6a74735_cppui_modular298, + 0x2839e48822f55b4e487b817ddf06a6e32e0dcc0c2ced1e738d38fec15bd4717d7680dda90ec_cppui_modular298, + }; + + auto f_eval = f.evaluate(alpha); + + auto params = typename kzg_type::params_type(n, alpha); + auto commit = zk::algorithms::commit(params, f); + nil::marshalling::status_type status; + using endianness = nil::marshalling::option::big_endian; + std::vector single_commitment_bytes = + nil::marshalling::pack(commit, status); + dump_vector(single_commitment_bytes, "commitment"); + + BOOST_CHECK(curve_type::template g1_type<>::value_type::one() == params.commitment_key[0]); + BOOST_CHECK(alpha * curve_type::template g1_type<>::value_type::one() == params.commitment_key[1]); + BOOST_CHECK(alpha * alpha * curve_type::template g1_type<>::value_type::one() == params.commitment_key[2]); + BOOST_CHECK(alpha * alpha * alpha * curve_type::template g1_type<>::value_type::one() == params.commitment_key[3]); + BOOST_CHECK(alpha * curve_type::template g2_type<>::value_type::one() == params.verification_key); + + BOOST_CHECK(f_eval * curve_type::template g1_type<>::value_type::one() == commit); + + typename kzg_type::public_key_type pk = {commit, z, f.evaluate(z)}; + auto proof = zk::algorithms::proof_eval(params, f, pk); + + BOOST_CHECK(zk::algorithms::verify_eval(params, proof, pk)); +} +BOOST_AUTO_TEST_SUITE_END()*/ + BOOST_AUTO_TEST_SUITE(batched_kzg_test_suite) template @@ -298,7 +349,8 @@ struct batched_kzg_basic_test_runner { using BatchedBasicTestFixtures = boost::mpl::list< batched_kzg_basic_test_runner, batched_kzg_basic_test_runner, - batched_kzg_basic_test_runner + batched_kzg_basic_test_runner, + batched_kzg_basic_test_runner >; BOOST_AUTO_TEST_CASE_TEMPLATE(batched_kzg_basic_test, F, BatchedBasicTestFixtures) { @@ -360,7 +412,8 @@ struct batched_kzg_bigger_test_runner { using BatchedBiggerTestFixtures = boost::mpl::list< batched_kzg_bigger_test_runner, batched_kzg_bigger_test_runner, - batched_kzg_bigger_test_runner + batched_kzg_bigger_test_runner, + batched_kzg_bigger_test_runner >; BOOST_AUTO_TEST_CASE_TEMPLATE(batched_kzg_bigger_test, F, BatchedBiggerTestFixtures) { diff --git a/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp b/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp index 66ef6c6f7..23c5c3326 100644 --- a/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp +++ b/libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp @@ -41,6 +41,11 @@ #include #include #include +/**/ +#include +#include +#include +/**/ #include #include @@ -77,7 +82,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg) using TestRunners = boost::mpl::list< placeholder_kzg_test_runner, - placeholder_kzg_test_runner + placeholder_kzg_test_runner, + placeholder_kzg_test_runner >; BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_test, TestRunner, TestRunners) { @@ -99,7 +105,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2) using TestRunners = boost::mpl::list< placeholder_kzg_test_runner_v2, - placeholder_kzg_test_runner_v2 + placeholder_kzg_test_runner_v2, + placeholder_kzg_test_runner_v2 >; BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_v2_test, TestRunner, TestRunners) {