Skip to content

Commit 9e02305

Browse files
committed
precompiles: Split "evmone" and "gmp" modexp implementations
1 parent a2c7483 commit 9e02305

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

test/precompiles_bench/precompiles_bench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void modexp(benchmark::State& state)
310310
->Args({128 * 8, 8, 2048}) \
311311
->Args({128 * 8, 4096, 2048}) \
312312
->Args({128 * 8, 8190, 2048})
313-
BENCHMARK(modexp<expmod_execute>) MODEXP_ARGS;
313+
BENCHMARK(modexp<expmod_execute_evmone>) MODEXP_ARGS;
314314
#ifdef EVMONE_PRECOMPILES_GMP
315315
BENCHMARK(modexp<expmod_execute_gmp>) MODEXP_ARGS;
316316
#endif
@@ -334,7 +334,7 @@ BENCHMARK_TEMPLATE(precompile, PrecompileId::ecrecover, silkpre_libsecp256k1);
334334

335335
namespace bench_expmod
336336
{
337-
constexpr auto evmone = expmod_execute;
337+
constexpr auto evmone = expmod_execute_evmone;
338338
BENCHMARK(precompile<PrecompileId::expmod, evmone>);
339339
#ifdef EVMONE_PRECOMPILES_GMP
340340
constexpr auto gmp = expmod_execute_gmp;

test/state/precompiles.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,18 +451,14 @@ expmod_parse_input(
451451
return {base, exp, mod};
452452
}
453453

454-
ExecutionResult expmod_execute(
454+
ExecutionResult expmod_execute_evmone(
455455
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept
456456
{
457457
const auto [base, exp, mod] = expmod_parse_input(input, input_size, output, output_size);
458458
if (mod.empty())
459459
return {EVMC_SUCCESS, output_size};
460460

461-
#ifdef EVMONE_PRECOMPILES_GMP
462-
expmod_gmp(base, exp, mod, output);
463-
#else
464461
crypto::modexp(base, exp, mod, output);
465-
#endif
466462
return {EVMC_SUCCESS, output_size};
467463
}
468464

@@ -475,10 +471,20 @@ ExecutionResult expmod_execute_gmp(
475471
return {EVMC_SUCCESS, output_size};
476472

477473
expmod_gmp(base, exp, mod, output);
478-
return {EVMC_SUCCESS, mod.size()};
474+
return {EVMC_SUCCESS, output_size};
479475
}
480476
#endif
481477

478+
ExecutionResult expmod_execute(
479+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept
480+
{
481+
#ifdef EVMONE_PRECOMPILES_GMP
482+
return expmod_execute_gmp(input, input_size, output, output_size);
483+
#else
484+
return expmod_execute_evmone(input, input_size, output, output_size);
485+
#endif
486+
}
487+
482488
ExecutionResult ecadd_execute(const uint8_t* input, size_t input_size, uint8_t* output,
483489
[[maybe_unused]] size_t output_size) noexcept
484490
{

test/state/precompiles_internal.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ ExecutionResult identity_execute(
5050
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
5151
ExecutionResult expmod_execute(
5252
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
53+
ExecutionResult expmod_execute_evmone(
54+
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
5355
ExecutionResult ecadd_execute(
5456
const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) noexcept;
5557
ExecutionResult ecmul_execute(

0 commit comments

Comments
 (0)