|
12 | 12 | AccessList,
|
13 | 13 | Address,
|
14 | 14 | Alloc,
|
| 15 | + AuthorizationTuple, |
15 | 16 | Block,
|
16 | 17 | BlockchainTestFiller,
|
17 | 18 | Environment,
|
18 | 19 | Hash,
|
19 | 20 | StateTestFiller,
|
20 | 21 | Transaction,
|
21 | 22 | )
|
| 23 | +from ethereum_test_vm import Opcodes as Op |
22 | 24 |
|
23 | 25 |
|
24 | 26 | @pytest.fixture
|
@@ -330,3 +332,59 @@ def test_block_full_access_list_and_data(
|
330 | 332 | access_list=access_list,
|
331 | 333 | ),
|
332 | 334 | )
|
| 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