Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Unit tests for EC arithmetics cost change
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jul 30, 2019
1 parent 7ce66c4 commit 81d273c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
4 changes: 2 additions & 2 deletions libethashseal/genesis/test/istanbulTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ R"E(
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add" } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul" } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product" } }
}
}
Expand Down
4 changes: 2 additions & 2 deletions libethashseal/genesis/test/istanbulTransitionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ R"E(
"0000000000000000000000000000000000000003": { "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
"0000000000000000000000000000000000000004": { "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
"0000000000000000000000000000000000000005": { "precompiled": { "name": "modexp" } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add", "linear": { "base": 500, "word": 0 } } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul", "linear": { "base": 40000, "word": 0 } } },
"0000000000000000000000000000000000000006": { "precompiled": { "name": "alt_bn128_G1_add" } },
"0000000000000000000000000000000000000007": { "precompiled": { "name": "alt_bn128_G1_mul" } },
"0000000000000000000000000000000000000008": { "precompiled": { "name": "alt_bn128_pairing_product"} }
}
}
Expand Down
68 changes: 68 additions & 0 deletions test/unittests/libethcore/PrecompiledTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,72 @@ BOOST_AUTO_TEST_CASE(bench_bn256Pairing, *ut::label("bench"))
benchmarkPrecompiled("alt_bn128_pairing_product", tests, 1000);
}

BOOST_AUTO_TEST_CASE(ecaddCostBeforeIstanbul)
{
PrecompiledPricer cost = PrecompiledRegistrar::pricer("alt_bn128_G1_add");

ChainParams chainParams{genesisInfo(eth::Network::IstanbulTransitionTest)};

auto res = cost({}, chainParams, 1);

BOOST_REQUIRE_EQUAL(static_cast<int>(res), 500);
}

BOOST_AUTO_TEST_CASE(ecaddCostIstanbul)
{
PrecompiledPricer cost = PrecompiledRegistrar::pricer("alt_bn128_G1_add");

ChainParams chainParams{genesisInfo(eth::Network::IstanbulTransitionTest)};

auto res = cost({}, chainParams, 2);

BOOST_REQUIRE_EQUAL(static_cast<int>(res), 150);
}

BOOST_AUTO_TEST_CASE(ecmulBeforeIstanbul)
{
PrecompiledPricer cost = PrecompiledRegistrar::pricer("alt_bn128_G1_mul");

ChainParams chainParams{genesisInfo(eth::Network::IstanbulTransitionTest)};

auto res = cost({}, chainParams, 1);

BOOST_REQUIRE_EQUAL(static_cast<int>(res), 40000);
}

BOOST_AUTO_TEST_CASE(ecmulCostIstanbul)
{
PrecompiledPricer cost = PrecompiledRegistrar::pricer("alt_bn128_G1_mul");

ChainParams chainParams{genesisInfo(eth::Network::IstanbulTransitionTest)};

auto res = cost({}, chainParams, 2);

BOOST_REQUIRE_EQUAL(static_cast<int>(res), 6000);
}

BOOST_AUTO_TEST_CASE(ecpairingCost)
{
PrecompiledPricer cost = PrecompiledRegistrar::pricer("alt_bn128_pairing_product");

ChainParams chainParams{genesisInfo(eth::Network::IstanbulTransitionTest)};

bytes in{fromHex(
"0x1c76476f4def4bb94541d57ebba1193381ffa7aa76ada664dd31c16024c43f593034dd2920f673e204fee281"
"1c678745fc819b55d3e9d294e45c9b03a76aef41209dd15ebff5d46c4bd888e51a93cf99a7329636c63514396b"
"4a452003a35bf704bf11ca01483bfa8b34b43561848d28905960114c8ac04049af4b6315a416782bb8324af6cf"
"c93537a2ad1a445cfd0ca2a71acd7ac41fadbf933c2a51be344d120a2a4cf30c1bf9845f20c6fe39e07ea2cce6"
"1f0c9bb048165fe5e4de877550111e129f1cf1097710d41c4ac70fcdfa5ba2023c6ff1cbeac322de49d1b6df7c"
"2032c61a830e3c17286de9462bf242fca2883585b93870a73853face6a6bf411198e9393920d483a7260bfb731"
"fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46de"
"bd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6d"
"eb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa")};

auto costBeforeIstanbul = cost(ref(in), chainParams, 1);
BOOST_CHECK_EQUAL(static_cast<int>(costBeforeIstanbul), in.size() / 192 * 80000 + 100000);

auto costIstanbul = cost(ref(in), chainParams, 2);
BOOST_CHECK_EQUAL(static_cast<int>(costIstanbul), in.size() / 192 * 34000 + 45000);
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 81d273c

Please sign in to comment.