Skip to content

precompiles: Add expmod benchmarks #1196

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 1 commit into from
Apr 17, 2025
Merged
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
36 changes: 35 additions & 1 deletion test/precompiles_bench/precompiles_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <array>
#include <memory>

#ifdef EVMONE_PRECOMPILES_GMP
#include <state/precompiles_gmp.hpp>
#endif

#ifdef EVMONE_PRECOMPILES_SILKPRE
#include <state/precompiles_silkpre.hpp>
#endif
Expand All @@ -28,11 +32,13 @@
template <>
constexpr auto analyze<PrecompileId::ecrecover> = ecrecover_analyze;
template <>
[[maybe_unused]] constexpr auto analyze<PrecompileId::expmod> = expmod_analyze;
template <>
constexpr auto analyze<PrecompileId::ecadd> = ecadd_analyze;
template <>
constexpr auto analyze<PrecompileId::ecmul> = ecmul_analyze;
template <>
[[maybe_unused]] constexpr auto analyze<PrecompileId::ecpairing> = ecpairing_analyze;
constexpr auto analyze<PrecompileId::ecpairing> = ecpairing_analyze;
template <>
constexpr auto analyze<PrecompileId::point_evaluation> = point_evaluation_analyze;

Expand Down Expand Up @@ -65,6 +71,22 @@

};

template <>
const inline std::array inputs<PrecompileId::expmod>{
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000203038f57abc91abff7dcbc5b55cd6aa454503850ce62e941f81273ba6008e82a530644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffffff30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"_hex,
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020239ea33f993130afd678f591cd1685d44779b7717156f2a715220955e10a234830644e72e131a029b85045b68181585d2833e84879b9709143e1f593efffffff30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"_hex,
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000203914aeddf3af39bd5e0e231d09a8438cf38c7d0274a5aa61bd9a2bbcd77fd2c7ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254fffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"_hex,
"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002027c816cec3d048eaae22d948c42f9d803d765d0827a7b49e01273031566eed92ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc63254fffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"_hex,
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200cf7d1e109b5b8f6a682be51e152d3668acc1b4d762ecbf5cdca7a807cc5fe4cffffffff00000001000000000000000000000000fffffffffffffffffffffffdffffffff00000001000000000000000000000000ffffffffffffffffffffffff"_hex,
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000203a122fd889a09d3a19c587ab486d5a6a2b39836d6d665c6ebad2a68a615e6736ffffffff00000001000000000000000000000000fffffffffffffffffffffffdffffffff00000001000000000000000000000000ffffffffffffffffffffffff"_hex,
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020161455250ee1d7ff76e4eb2f6a16a636a4bc69dd20416f6ea5647b7fb311e9320000000000000000000000000000000000000000000000000000000000ffffff30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"_hex,
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200d96428856df2f1b728ce955f28f50befa405a61e8984acbaf678af9be0e0dfd000000000000000000000000000000000000000000000000000000000100000030644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000001"_hex,
"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000202369f74b39dddb516bb17d20f24ba72c8f0ec09bea7d7f38ad54dbc3cfd4b4760c19139cb84c680a6e14116da060561765e05aa45a1c72a34f082305b61f3f5230644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"_hex,
"00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002019b01e88eb4a62d7df2da453deb859f6113004675370b6f54ff9f20499cfc4cf0c19139cb84c680a6e14116da060561765e05aa45a1c72a34f082305b61f3f5230644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47"_hex,
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020c943d0f2b95b88d8a3ad7782221659f05cb697047a9793a65ec7db59439afb0a3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0cfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"_hex,
"000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020307c38188f3b804fc399b7195579269fd60fddbe7e6d8174b3ad38b64b1bb2fa3fffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffff0cfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"_hex,
};

Comment on lines +74 to +89
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see any case with even and power of 2 modulus.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because they don't happen on mainnet

Copy link
Contributor

Choose a reason for hiding this comment

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

What's on mainnet stays on mainnet.

Copy link
Contributor

Choose a reason for hiding this comment

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

Decided on chat to add these cases later.

template <>
const inline std::array inputs<PrecompileId::ecadd>{
"0f25929bcb43d5a57391564615c9e70a992b10eafa4db109709649cf48c50dd2"
Expand Down Expand Up @@ -184,6 +206,18 @@
#endif
} // namespace bench_ecrecovery

namespace bench_expmod
{
#ifdef EVMONE_PRECOMPILES_GMP
constexpr auto gmp = expmod_execute;

Check warning on line 212 in test/precompiles_bench/precompiles_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/precompiles_bench/precompiles_bench.cpp#L212

Added line #L212 was not covered by tests
BENCHMARK(precompile<PrecompileId::expmod, gmp>);
#endif
#ifdef EVMONE_PRECOMPILES_SILKPRE
constexpr auto silkpre = silkpre_expmod_execute;

Check warning on line 216 in test/precompiles_bench/precompiles_bench.cpp

View check run for this annotation

Codecov / codecov/patch

test/precompiles_bench/precompiles_bench.cpp#L216

Added line #L216 was not covered by tests
BENCHMARK(precompile<PrecompileId::expmod, silkpre>);
#endif
} // namespace bench_expmod

namespace bench_ecadd
{
constexpr auto evmmax_cpp = ecadd_execute;
Expand Down
2 changes: 1 addition & 1 deletion test/state/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ option(EVMONE_PRECOMPILES_GMP "Enable precompiles implementations via the GMP/MP
if(EVMONE_PRECOMPILES_GMP)
find_package(GMP REQUIRED)
target_link_libraries(evmone-state PRIVATE GMP::gmp)
target_compile_definitions(evmone-state PRIVATE EVMONE_PRECOMPILES_GMP=1)
target_compile_definitions(evmone-state PUBLIC EVMONE_PRECOMPILES_GMP=1)
target_sources(
evmone-state PRIVATE
precompiles_gmp.hpp
Expand Down