Skip to content

Commit 0af9e4e

Browse files
gurukamathSamWilsn
authored andcommitted
Implement EIP-7883
1 parent 7f4fc84 commit 0af9e4e

File tree

1 file changed

+7
-3
lines changed
  • src/ethereum/osaka/vm/precompiled_contracts

1 file changed

+7
-3
lines changed

src/ethereum/osaka/vm/precompiled_contracts/modexp.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def complexity(base_length: U256, modulus_length: U256) -> Uint:
9595
"""
9696
max_length = max(Uint(base_length), Uint(modulus_length))
9797
words = (max_length + Uint(7)) // Uint(8)
98-
return words ** Uint(2)
98+
complexity = words ** Uint(2)
99+
if max_length <= Uint(32):
100+
return complexity
101+
else:
102+
return Uint(2) * complexity
99103

100104

101105
def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
@@ -129,7 +133,7 @@ def iterations(exponent_length: U256, exponent_head: U256) -> Uint:
129133

130134
count = bit_length
131135
else:
132-
length_part = Uint(8) * (Uint(exponent_length) - Uint(32))
136+
length_part = Uint(16) * (Uint(exponent_length) - Uint(32))
133137
bits_part = exponent_head.bit_length()
134138

135139
if bits_part > Uint(0):
@@ -175,4 +179,4 @@ def gas_cost(
175179
iteration_count = iterations(exponent_length, exponent_head)
176180
cost = multiplication_complexity * iteration_count
177181
cost //= GQUADDIVISOR
178-
return max(Uint(200), cost)
182+
return max(Uint(500), cost)

0 commit comments

Comments
 (0)