Skip to content

Commit 7752f05

Browse files
committed
eth/precompiles/modexp: fix complexity calc (length^2, not 2^2).
There was a typo in the "complexity" calculation function, a special interim value from EIP-198 used to determine total gas use. The code path was never previously exercised. NOTE: previous-commit "fixtures bump" was to commit: 9b1f07c58a70d1b17c4489c49eb9bebf4a27d290 Squashed commit: tests: update "very big number" in test_modexp_gas_fee_calculation(). ... and also fix that test's name, from "calculTation". The very-big-number is not actually in EIP-198; the latter has this to say: > it’s not possible to provide enough gas to make that computation. That's a bit cryptic, but the gist is that the most that can be represented in a 256-bit number is 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff which is 115792089237316195423570985008687907853269984665640564039457584007913129639935 and that's less than the 10684346944173007063723051170445283632835119638284563472873463025465780712173320789629146724657549280936306536701227228889744512638312451529980055895215896 required by this vector, or even the (erroneous) 708647586132375115992254428253169996062012306153720251921480414128428353393856280 that was in the test previously.
1 parent b11a7b8 commit 7752f05

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

eth/precompiles/modexp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _compute_complexity(length):
3535
length ** 2 // 4 + 96 * length - 3072
3636
)
3737
else:
38-
return 2 ** 2 // 16 + 480 * length - 199680
38+
return length ** 2 // 16 + 480 * length - 199680
3939

4040

4141
def _extract_lengths(data):

tests/core/vm/test_modexp_precompile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
(EIP198_VECTOR_A, 13056),
4242
(
4343
EIP198_VECTOR_C,
44-
708647586132375115992254428253169996062012306153720251921480414128428353393856280,
44+
10684346944173007063723051170445283632835119638284563472873463025465780712173320789629146724657549280936306536701227228889744512638312451529980055895215896, # noqa: E501
4545
),
4646
),
4747
)
48-
def test_modexp_gas_fee_calcultation(data, expected):
48+
def test_modexp_gas_fee_calculation(data, expected):
4949
actual = _compute_modexp_gas_fee(data)
5050
assert actual == expected
5151

tests/json-fixtures/test_state.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ def expand_fixtures_forks(all_fixtures):
138138
# Ideally, this list should be empty.
139139
# WHEN ADDING ENTRIES, ALWAYS PROVIDE AN EXPLANATION!
140140
INCORRECT_UPSTREAM_TESTS = {
141-
# Upstream seems to specify that the precompile call fails, but `py-evm`
142-
# handles it just fine.
143-
# * https://github.com/ethereum/py-evm/pull/1224#issuecomment-417351843
144-
# * https://github.com/ethereum/tests/pull/405#issuecomment-417855812
145-
('stReturnDataTest/modexp_modsize0_returndatasize.json', 'modexp_modsize0_returndatasize', 'Byzantium', 4), # noqa: E501
146141
}
147142

148143

0 commit comments

Comments
 (0)