Skip to content

Commit 7582d85

Browse files
feat(benchmark): add eip7702 case (#2227)
* feat(benchmark): add eip7702 case * refactor: update nonce management * refactor: consider gas refund logic
1 parent 689e489 commit 7582d85

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

benchmark/test_worst_blocks.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
AccessList,
1313
Address,
1414
Alloc,
15+
AuthorizationTuple,
1516
Block,
1617
BlockchainTestFiller,
1718
Environment,
1819
Hash,
1920
StateTestFiller,
2021
Transaction,
2122
)
23+
from ethereum_test_vm import Opcodes as Op
2224

2325

2426
@pytest.fixture
@@ -330,3 +332,59 @@ def test_block_full_access_list_and_data(
330332
access_list=access_list,
331333
),
332334
)
335+
336+
337+
@pytest.mark.parametrize("empty_authority", [True, False])
338+
@pytest.mark.parametrize("zero_delegation", [True, False])
339+
def test_worst_case_auth_block(
340+
blockchain_test: BlockchainTestFiller,
341+
pre: Alloc,
342+
intrinsic_cost: int,
343+
gas_benchmark_value: int,
344+
fork: Fork,
345+
empty_authority: bool,
346+
zero_delegation: bool,
347+
):
348+
"""Test an auth block."""
349+
gas_costs = fork.gas_costs()
350+
351+
iteration_count = (gas_benchmark_value - intrinsic_cost) // gas_costs.G_AUTHORIZATION
352+
353+
code = Op.STOP * fork.max_code_size()
354+
auth_target = Address(0) if zero_delegation else pre.deploy_contract(code=code)
355+
356+
auth_tuples = []
357+
for _ in range(iteration_count):
358+
signer = (
359+
pre.fund_eoa(amount=0, delegation=None)
360+
if empty_authority
361+
else pre.fund_eoa(amount=0, delegation=auth_target)
362+
)
363+
auth_tuple = AuthorizationTuple(address=auth_target, nonce=signer.nonce, signer=signer)
364+
auth_tuples.append(auth_tuple)
365+
366+
tx = Transaction(
367+
to=pre.empty_account(),
368+
gas_limit=gas_benchmark_value,
369+
sender=pre.fund_eoa(),
370+
authorization_list=auth_tuples,
371+
)
372+
373+
gas_used = fork.transaction_intrinsic_cost_calculator()(
374+
authorization_list_or_count=auth_tuples
375+
)
376+
377+
refund = 0
378+
if not empty_authority:
379+
refund = min(
380+
gas_used // 5,
381+
(gas_costs.G_AUTHORIZATION - gas_costs.R_AUTHORIZATION_EXISTING_AUTHORITY)
382+
* iteration_count,
383+
)
384+
385+
blockchain_test(
386+
pre=pre,
387+
post={},
388+
blocks=[Block(txs=[tx])],
389+
expected_benchmark_gas_used=gas_used - refund,
390+
)

0 commit comments

Comments
 (0)