Skip to content
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

Added tests of alt_bn128_254 in various suitest #292

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 58 additions & 44 deletions libs/marshalling/zk/test/placeholder_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@
#include <nil/crypto3/algebra/curves/mnt6.hpp>
#include <nil/crypto3/algebra/pairing/mnt6.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt6.hpp>
/*

/**/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty comments

#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/pairing/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>
*/
/**/

#include <nil/crypto3/algebra/curves/pallas.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/pallas.hpp>
#include <nil/crypto3/algebra/random_element.hpp>
Expand Down Expand Up @@ -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,
Expand Down
61 changes: 57 additions & 4 deletions libs/zk/test/commitment/kzg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
#include <nil/crypto3/algebra/pairing/mnt4.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt4.hpp>

#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/pairing/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>

#include <nil/crypto3/zk/commitments/polynomial/kzg.hpp>
#include <nil/crypto3/zk/commitments/polynomial/kzg_v2.hpp>

Expand Down Expand Up @@ -108,7 +112,8 @@ struct kzg_basic_test_runner {
using BasicTestFixtures = boost::mpl::list<
kzg_basic_test_runner<algebra::curves::bls12_381>,
kzg_basic_test_runner<algebra::curves::mnt4_298>,
kzg_basic_test_runner<algebra::curves::mnt6_298>
kzg_basic_test_runner<algebra::curves::mnt6_298>,
kzg_basic_test_runner<algebra::curves::alt_bn128_254>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_basic_test, F, BasicTestFixtures) {
Expand Down Expand Up @@ -144,7 +149,8 @@ struct kzg_random_test_runner {
using RandomTestFixtures = boost::mpl::list<
kzg_random_test_runner<algebra::curves::bls12_381>,
kzg_random_test_runner<algebra::curves::mnt4_298>,
kzg_random_test_runner<algebra::curves::mnt6_298>
kzg_random_test_runner<algebra::curves::mnt6_298>,
kzg_random_test_runner<algebra::curves::alt_bn128_254>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_random_test, F, RandomTestFixtures) {
Expand Down Expand Up @@ -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<curve_type> kzg_type;

scalar_value_type alpha = 7u;
std::size_t n = 8;
scalar_value_type z = 2u;
const polynomial<scalar_value_type> 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<kzg_type>(params, f);
nil::marshalling::status_type status;
using endianness = nil::marshalling::option::big_endian;
std::vector<uint8_t> single_commitment_bytes =
nil::marshalling::pack<endianness>(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<kzg_type>(params, f, pk);

BOOST_CHECK(zk::algorithms::verify_eval<kzg_type>(params, proof, pk));
}
BOOST_AUTO_TEST_SUITE_END()*/

BOOST_AUTO_TEST_SUITE(batched_kzg_test_suite)

template<typename curve_type>
Expand Down Expand Up @@ -298,7 +349,8 @@ struct batched_kzg_basic_test_runner {
using BatchedBasicTestFixtures = boost::mpl::list<
batched_kzg_basic_test_runner<algebra::curves::bls12_381>,
batched_kzg_basic_test_runner<algebra::curves::mnt4_298>,
batched_kzg_basic_test_runner<algebra::curves::mnt6_298>
batched_kzg_basic_test_runner<algebra::curves::mnt6_298>,
batched_kzg_basic_test_runner<algebra::curves::alt_bn128_254>
>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add alt_bn128_254 test


BOOST_AUTO_TEST_CASE_TEMPLATE(batched_kzg_basic_test, F, BatchedBasicTestFixtures) {
Expand Down Expand Up @@ -360,7 +412,8 @@ struct batched_kzg_bigger_test_runner {
using BatchedBiggerTestFixtures = boost::mpl::list<
batched_kzg_bigger_test_runner<algebra::curves::bls12_381>,
batched_kzg_bigger_test_runner<algebra::curves::mnt4_298>,
batched_kzg_bigger_test_runner<algebra::curves::mnt6_298>
batched_kzg_bigger_test_runner<algebra::curves::mnt6_298>,
batched_kzg_bigger_test_runner<algebra::curves::alt_bn128_254>
>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add alt_bn128_254 test


BOOST_AUTO_TEST_CASE_TEMPLATE(batched_kzg_bigger_test, F, BatchedBiggerTestFixtures) {
Expand Down
11 changes: 9 additions & 2 deletions libs/zk/test/systems/plonk/placeholder/placeholder_kzg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
#include <nil/crypto3/algebra/curves/mnt6.hpp>
#include <nil/crypto3/algebra/pairing/mnt6.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/mnt6.hpp>
/**/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove empty comments

#include <nil/crypto3/algebra/curves/alt_bn128.hpp>
#include <nil/crypto3/algebra/pairing/alt_bn128.hpp>
#include <nil/crypto3/algebra/fields/arithmetic_params/alt_bn128.hpp>
/**/

#include <nil/crypto3/random/algebraic_engine.hpp>
#include <nil/crypto3/random/algebraic_random_device.hpp>
Expand Down Expand Up @@ -77,7 +82,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg)

using TestRunners = boost::mpl::list<
placeholder_kzg_test_runner<algebra::curves::mnt4_298, hash_type>,
placeholder_kzg_test_runner<algebra::curves::mnt6_298, hash_type>
placeholder_kzg_test_runner<algebra::curves::mnt6_298, hash_type>,
placeholder_kzg_test_runner<algebra::curves::alt_bn128_254, hash_type>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_test, TestRunner, TestRunners) {
Expand All @@ -99,7 +105,8 @@ BOOST_AUTO_TEST_SUITE(placeholder_circuit2_kzg_v2)

using TestRunners = boost::mpl::list<
placeholder_kzg_test_runner_v2<algebra::curves::mnt4_298, hash_type>,
placeholder_kzg_test_runner_v2<algebra::curves::mnt6_298, hash_type>
placeholder_kzg_test_runner_v2<algebra::curves::mnt6_298, hash_type>,
placeholder_kzg_test_runner_v2<algebra::curves::alt_bn128_254, hash_type>
>;

BOOST_AUTO_TEST_CASE_TEMPLATE(kzg_v2_test, TestRunner, TestRunners) {
Expand Down
Loading