Skip to content

Commit 2d11726

Browse files
committed
fix(tests): Rebase updates
1 parent 9902b8d commit 2d11726

1 file changed

Lines changed: 50 additions & 43 deletions

File tree

tests/benchmark/stateful/bloatnet/depth_benchmarks/test_deep_branch.py

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929

3030
import pytest
3131
from execution_testing import (
32-
DETERMINISTIC_DEPLOYMENT_CONTRACT_ADDRESS,
32+
DETERMINISTIC_FACTORY_ADDRESS,
3333
EOA,
3434
Account,
3535
Address,
3636
Alloc,
3737
Block,
3838
BlockchainTestFiller,
39+
Bytecode,
3940
Bytes,
4041
Fork,
4142
Hash,
@@ -143,46 +144,51 @@ def load(cls, storage_depth: int, account_depth: int) -> Self:
143144
return cls.model_validate_json(get_mined_asset(json_filename))
144145

145146

146-
ATTACK_ORCHESTRATOR_BYTECODE = (
147-
# - Prepare CREATE2 Address Keccak, Mem[0:85]
148-
# Mem[0:21] = 0xff + DETERMINISTIC_DEPLOYMENT_CONTRACT_ADDRESS
149-
Op.MSTORE(
150-
0,
151-
Hash(
152-
b"\xff" + DETERMINISTIC_DEPLOYMENT_CONTRACT_ADDRESS,
153-
right_padding=True,
154-
),
155-
)
156-
# Mem[21:53] = salt (Batch start)
157-
+ Op.MSTORE(1 + 20, Op.CALLDATALOAD(32))
158-
# Mem[53:85] = Initcode hash
159-
+ Op.MSTORE(1 + 20 + 32, Op.CALLDATALOAD(96))
160-
# - Prepare ERC20 Calldata, Mem[85:121]
161-
# Mem[85:89] = 0x64dd891a (ABI `attack(uint256)`)
162-
+ Op.MSTORE(
163-
1 + 20 + 32 + 32,
164-
Hash(bytes.fromhex("64dd891a"), right_padding=True),
147+
def attack_orchestrator_bytecode(fork: Fork) -> Bytecode:
148+
"""
149+
Return the bytecode of the attack orchestrator, depending on the fork.
150+
"""
151+
factory_address = (
152+
fork.deterministic_factory_predeploy_address()
153+
or DETERMINISTIC_FACTORY_ADDRESS
165154
)
166-
# Mem[89:121] = value
167-
+ Op.MSTORE(1 + 20 + 32 + 32 + 4, Op.CALLDATALOAD(0))
168-
+ While(
169-
body=Op.POP(
170-
Op.CALL(
171-
address=Op.AND(2 ** (20 * 8) - 1, Op.SHA3(0, 85)),
172-
args_offset=1 + 20 + 32 + 32,
173-
args_size=4 + 32,
155+
return (
156+
# - Prepare CREATE2 Address Keccak, Mem[0:85]
157+
# Mem[0:21] = 0xff + DETERMINISTIC_FACTORY_ADDRESS
158+
Op.MSTORE(
159+
0,
160+
Hash(
161+
b"\xff" + factory_address,
162+
right_padding=True,
163+
),
164+
)
165+
# Mem[21:53] = salt (Batch start)
166+
+ Op.MSTORE(1 + 20, Op.CALLDATALOAD(32))
167+
# Mem[53:85] = Initcode hash
168+
+ Op.MSTORE(1 + 20 + 32, Op.CALLDATALOAD(96))
169+
# - Prepare ERC20 Calldata, Mem[85:121]
170+
# Mem[85:89] = 0x64dd891a (ABI `attack(uint256)`)
171+
+ Op.MSTORE(
172+
1 + 20 + 32 + 32,
173+
Hash(bytes.fromhex("64dd891a"), right_padding=True),
174+
)
175+
# Mem[89:121] = value
176+
+ Op.MSTORE(1 + 20 + 32 + 32 + 4, Op.CALLDATALOAD(0))
177+
+ While(
178+
body=Op.POP(
179+
Op.CALL(
180+
address=Op.AND(2 ** (20 * 8) - 1, Op.SHA3(0, 85)),
181+
args_offset=1 + 20 + 32 + 32,
182+
args_size=4 + 32,
183+
)
174184
)
185+
# Increment salt in memory by one
186+
+ Op.MSTORE(1 + 20, Op.ADD(1, Op.MLOAD(1 + 20))),
187+
# Check that current salt is less than or equal to batch end
188+
condition=Op.LT(Op.MLOAD(1 + 20), Op.ADD(1, Op.CALLDATALOAD(64))),
175189
)
176-
# Increment salt in memory by one
177-
+ Op.MSTORE(1 + 20, Op.ADD(1, Op.MLOAD(1 + 20))),
178-
# Check that current salt is less than or equal to batch end
179-
condition=Op.LT(Op.MLOAD(1 + 20), Op.ADD(1, Op.CALLDATALOAD(64))),
190+
+ Op.STOP
180191
)
181-
+ Op.STOP
182-
)
183-
ATTACK_ORCHESTRATOR_ADDRESS = compute_deterministic_create2_address(
184-
Hash(0), Initcode(deploy_code=ATTACK_ORCHESTRATOR_BYTECODE)
185-
)
186192

187193

188194
class Attack(BaseModel):
@@ -285,8 +291,13 @@ def calculate_tx_gas_limit(self, fork: Fork) -> int:
285291

286292
def generate_transaction(self, fork: Fork, sender: EOA) -> Transaction:
287293
"""Generate the transaction to perform the attack."""
294+
attack_orchestrator_address = compute_deterministic_create2_address(
295+
salt=Hash(0),
296+
initcode=Initcode(deploy_code=attack_orchestrator_bytecode(fork)),
297+
fork=fork,
298+
)
288299
return Transaction(
289-
to=ATTACK_ORCHESTRATOR_ADDRESS,
300+
to=attack_orchestrator_address,
290301
gas_limit=self.calculate_tx_gas_limit(fork),
291302
sender=sender,
292303
data=self.calldata(),
@@ -357,11 +368,7 @@ def test_worst_depth_stateroot_recomp(
357368

358369
# Deploy orchestrator to deterministic address
359370
orchestrator_address = pre.deterministic_deploy_contract(
360-
deploy_code=ATTACK_ORCHESTRATOR_BYTECODE
361-
)
362-
assert orchestrator_address == ATTACK_ORCHESTRATOR_ADDRESS, (
363-
f"Orchestrator address mismatch: {orchestrator_address} != "
364-
f"{ATTACK_ORCHESTRATOR_ADDRESS}"
371+
deploy_code=attack_orchestrator_bytecode(fork)
365372
)
366373
print(f" Orchestrator will be deployed at: {orchestrator_address}")
367374

0 commit comments

Comments
 (0)