Skip to content

Commit c1796f5

Browse files
update xen claimrank test
1 parent 21fdf9c commit c1796f5

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tests/benchmark/mainnet/test_state_xen.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def test_xen_approve_delete_existing_slots(blockchain_test: BlockchainTestFiller
319319
# attempt to bust the cache
320320
spam_tx = Transaction(
321321
to=usdt_approve_spammer_contract,
322-
gas_limit=attack_gas_limit,
322+
gas_limit=attack_gas_limit // 2,
323323
sender=sender,
324324
max_priority_fee_per_gas=100,
325325
max_fee_per_gas=10000,
@@ -534,14 +534,54 @@ def test_xen_claimrank_and_mint(
534534
# deployed_contract_addresses.append(deployed_contract_address)
535535

536536
blocks = []
537-
for _ in range(20):
537+
for _ in range(10): # Check how much of these we need
538538
contracts_deployment_tx = Transaction(
539539
to=factory_caller_address,
540540
gas_limit=attack_gas_limit,
541541
sender=sender,
542542
)
543543
blocks.append(Block(txs=[contracts_deployment_tx]))
544544

545+
fn_signature_approve = bytes.fromhex("095EA7B3")
546+
usdt_contract = 0xDAC17F958D2EE523A2206206994597C13D831EC7 # Used in intermediate blocks to attempt to bust te cache
547+
usdt_approve_spammer_code = (
548+
Om.MSTORE(fn_signature_approve)
549+
+ Op.MSTORE(4 + 32, 1)
550+
+ Op.SLOAD(0)
551+
+ While(
552+
body=Op.MSTORE(
553+
4, Op.DUP1
554+
) # Put a copy of the topmost stack item in memory (this is the target address)
555+
+ Op.CALL(address=usdt_contract, args_offset=0, args_size=4 + 32 + 32)
556+
+ Op.ADD, # Add the status of the CALL
557+
# (this should always be 1 unless the `gas_threshold` is too low) to the stack item
558+
# The address and thus target storage slot changes!
559+
# + Op.MSTORE(4 + 32, Op.SUB(Op.MLOAD(4 + 34), Op.GAS)),
560+
condition=Op.GT(Op.GAS, gas_threshold),
561+
)
562+
+ Op.PUSH1(0)
563+
+ Op.SSTORE
564+
)
565+
# Set storage to value 1 to avoid paying 20k on the update
566+
usdt_approve_spammer_contract = pre.deploy_contract(
567+
code=usdt_approve_spammer_code, storage={0: 1}
568+
)
569+
570+
spam_count = 100
571+
572+
for _ in range(spam_count):
573+
# NOTE: USDC does not allow changing the approval value. It first has to be
574+
# set to zero before it changes. We therefore flood USDC with approvals in an
575+
# attempt to bust the cache
576+
spam_tx = Transaction(
577+
to=usdt_approve_spammer_contract,
578+
gas_limit=attack_gas_limit // 2,
579+
sender=sender,
580+
max_priority_fee_per_gas=100,
581+
max_fee_per_gas=10000,
582+
)
583+
blocks.append(Block(txs=[spam_tx]))
584+
545585
# for _ in range(24*60*60):
546586
# blocks.append(Block(txs=[Transaction(sender=sender,to=sender, nonce=sender_nonce)]))
547587
# sender_nonce = sender_nonce + 1

0 commit comments

Comments
 (0)