Skip to content
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
15 changes: 11 additions & 4 deletions test/state/precompiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,21 @@ PrecompileAnalysis expmod_analyze(bytes_view input, evmc_revision rev) noexcept
const auto exp_len256 = be::unsafe::load<uint256>(&input_header[32]);
const auto mod_len256 = be::unsafe::load<uint256>(&input_header[64]);

if (base_len256 == 0 && mod_len256 == 0)
return {min_gas, 0};

// Check the declared input lengths against the practical (2**32)
// or specified (EIP-7823: 2**10) limits.
const auto len_limit =
rev < EVMC_OSAKA ? std::numeric_limits<uint32_t>::max() : MODEXP_LEN_LIMIT_EIP7823;
if (base_len256 > len_limit || exp_len256 > len_limit || mod_len256 > len_limit)
if (base_len256 > len_limit || mod_len256 > len_limit)
return {GasCostMax, 0};

if (exp_len256 > len_limit)
{
// Before EIP-7823, the big exponent may be canceled with zero multiplication complexity.
if (rev < EVMC_OSAKA && base_len256 == 0 && mod_len256 == 0)
return {min_gas, 0};
return {GasCostMax, 0};
}

const auto base_len = static_cast<uint32_t>(base_len256);
const auto exp_len = static_cast<uint32_t>(exp_len256);
const auto mod_len = static_cast<uint32_t>(mod_len256);
Expand Down
3 changes: 3 additions & 0 deletions test/unittests/precompiles_expmod_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ TEST(expmod, incomplete_inputs)
{"0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000003 ba ee 000000 fe", "000000"},
{"0000000000000000000000000000000000000000000000000000000000000010 0000000000000000000000000000000000000000000000000000000000000010 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000001", "00"},
{"000000000000000000000000000000000000000000000000000000000000ffff 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000001 80", "00"},
{"0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000000", ""},
{"0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000000 80", ""},
{"0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000100000000 0000000000000000000000000000000000000000000000000000000000000000 80", ""},
// clang-format on
};

Expand Down