Skip to content

Commit ac4a22d

Browse files
committed
adjustments
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent 3ee68fc commit ac4a22d

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,25 @@ def test_worst_keccak(
114114
36_000_000,
115115
],
116116
)
117-
@pytest.mark.parametrize(
118-
"base_mod_length, exp_length",
119-
[
120-
(32, 32),
121-
],
122-
)
123117
def test_worst_modexp(
124118
blockchain_test: BlockchainTestFiller,
125119
pre: Alloc,
126120
fork: Fork,
127121
gas_limit: int,
128-
base_mod_length: int,
129-
exp_length: int,
122+
130123
):
131124
"""Test running a block with as many MODEXP calls as possible."""
132125
env = Environment(gas_limit=gas_limit)
133126

127+
base_mod_length = 32
128+
exp_length = 32
129+
134130
base = 2 ** (8 * base_mod_length) - 1
135-
mod = 2 ** (8 * base_mod_length) - 1
131+
mod = 2 ** (8 * base_mod_length) - 2 # Prevnts base == mod
136132
exp = 2 ** (8 * exp_length) - 1
137133

138-
# EIP-7883 (TODO: generalize)
139-
mul_complexity = math.ceil(base_mod_length / 8) ** 2
140-
iter_complexity = exp.bit_length() - 1
141-
gas_cost = math.floor((mul_complexity * iter_complexity) / 3)
142-
143-
mem_prep = (
134+
# MODEXP calldata
135+
calldata = (
144136
Op.MSTORE(0 * 32, 32)
145137
+ Op.MSTORE(1 * 32, 32)
146138
+ Op.MSTORE(2 * 32, 32)
@@ -149,14 +141,19 @@ def test_worst_modexp(
149141
+ Op.MSTORE(5 * 32, mod)
150142
)
151143

144+
# EIP-2565
145+
mul_complexity = math.ceil(base_mod_length / 8) ** 2
146+
iter_complexity = exp.bit_length() - 1
147+
gas_cost = math.floor((mul_complexity * iter_complexity) / 3)
152148
attack_block = Op.STATICCALL(gas_cost, 0x5, 0, 32 * 6, 0, 0) + Op.POP
153149

150+
# The attack contract is: JUMPDEST + [attack_block]* + PUSH0 + JUMP
154151
jumpdest = Op.JUMPDEST
155-
jump_back = Op.JUMP(len(mem_prep))
156-
max_iters_loop = (MAX_CODE_SIZE - len(mem_prep) - len(jumpdest) - len(jump_back)) // len(
152+
jump_back = Op.JUMP(len(calldata))
153+
max_iters_loop = (MAX_CODE_SIZE - len(calldata) - len(jumpdest) - len(jump_back)) // len(
157154
attack_block
158155
)
159-
code = mem_prep + jumpdest + sum([attack_block] * max_iters_loop) + jump_back
156+
code = calldata + jumpdest + sum([attack_block] * max_iters_loop) + jump_back
160157
if len(code) > MAX_CODE_SIZE:
161158
# Must never happen, but keep it as a sanity check.
162159
raise ValueError(f"Code size {len(code)} exceeds maximum code size {MAX_CODE_SIZE}")

0 commit comments

Comments
 (0)