Skip to content

Commit ee3bd9e

Browse files
committed
adjustments
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent 23e355f commit ee3bd9e

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
@@ -115,33 +115,25 @@ def test_worst_keccak(
115115
36_000_000,
116116
],
117117
)
118-
@pytest.mark.parametrize(
119-
"base_mod_length, exp_length",
120-
[
121-
(32, 32),
122-
],
123-
)
124118
def test_worst_modexp(
125119
blockchain_test: BlockchainTestFiller,
126120
pre: Alloc,
127121
fork: Fork,
128122
gas_limit: int,
129-
base_mod_length: int,
130-
exp_length: int,
123+
131124
):
132125
"""Test running a block with as many MODEXP calls as possible."""
133126
env = Environment(gas_limit=gas_limit)
134127

128+
base_mod_length = 32
129+
exp_length = 32
130+
135131
base = 2 ** (8 * base_mod_length) - 1
136-
mod = 2 ** (8 * base_mod_length) - 1
132+
mod = 2 ** (8 * base_mod_length) - 2 # Prevnts base == mod
137133
exp = 2 ** (8 * exp_length) - 1
138134

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

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

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

0 commit comments

Comments
 (0)