Skip to content

test_worst_depth_stateroot_recomp()

Documentation for tests/benchmark/stateful/bloatnet/depth_benchmarks/test_deep_branch.py::test_worst_depth_stateroot_recomp@892e6d1e.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/benchmark/stateful/bloatnet/depth_benchmarks/test_deep_branch.py::test_worst_depth_stateroot_recomp --gas-benchmark-values 1

BloatNet worst-case SSTORE attack benchmark with pre-deployed contracts.

This test: 1. Derives CREATE2 addresses from initcode_hash + Nick's deployer 2. Deploys AttackOrchestrator that calls attack() on each target 3. Fills blocks with 16M gas transactions attacking contracts 4. Verifies the deepest-slot update through post-state assertions

Parameters:

Name Type Description Default
benchmark_test BenchmarkTestFiller

The benchmark test filler

required
fork Fork

The fork to test on

required
pre Alloc

Pre-state allocation

required
gas_benchmark_value int

Gas budget for benchmark

required
storage_depth int

Depth of storage slots in the contract (e.g., 9)

required
account_depth int

Depth of account address prefix sharing (e.g., 5)

required
attack_value int

The value to be written to storage in each attack

required
Source code in tests/benchmark/stateful/bloatnet/depth_benchmarks/test_deep_branch.py
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
@pytest.mark.parametrize(
    "storage_depth,account_depth",
    DEPTH_BENCHMARK_CASES,
)
def test_worst_depth_stateroot_recomp(
    benchmark_test: BenchmarkTestFiller,
    fork: Fork,
    pre: Alloc,
    gas_benchmark_value: int,
    storage_depth: int,
    account_depth: int,
    attack_value: int,
) -> None:
    """
    BloatNet worst-case SSTORE attack benchmark with pre-deployed contracts.

    This test:
    1. Derives CREATE2 addresses from initcode_hash + Nick's deployer
    2. Deploys AttackOrchestrator that calls attack() on each target
    3. Fills blocks with 16M gas transactions attacking contracts
    4. Verifies the deepest-slot update through post-state assertions

    Args:
        benchmark_test: The benchmark test filler
        fork: The fork to test on
        pre: Pre-state allocation
        gas_benchmark_value: Gas budget for benchmark
        storage_depth: Depth of storage slots in the contract (e.g., 9)
        account_depth: Depth of account address prefix sharing (e.g., 5)
        attack_value: The value to be written to storage in each attack

    """
    mined_contract_file = MinedContractFile.load(storage_depth, account_depth)
    attack_orchestrator_bytecode = build_attack_orchestrator_bytecode(
        get_factory_address(fork)
    )

    # Deploy orchestrator to deterministic address
    attack_orchestrator_address = pre.deterministic_deploy_contract(
        deploy_code=attack_orchestrator_bytecode
    )
    print(f"  Orchestrator will be deployed at: {attack_orchestrator_address}")

    # Calldata generator for each transaction of the iterating bytecode.
    def calldata(iteration_count: int, start_iteration: int) -> bytes:
        end_iteration = start_iteration + iteration_count
        return (
            Hash(attack_value)
            + Hash(start_iteration)
            + Hash(end_iteration)
            + mined_contract_file.initcode_hash
        )

    # Get the number of contracts to deploy
    contracts_required = sum(
        attack_orchestrator_bytecode.tx_iterations_by_gas_limit(
            fork=fork,
            gas_limit=gas_benchmark_value,
            start_iteration=0,
            calldata=calldata,
        )
    )

    post = deploy_required_mined_contracts(
        pre=pre,
        mined_contract_file=mined_contract_file,
        contracts_required=contracts_required,
        storage_depth=storage_depth,
        account_depth=account_depth,
        attacked_storage_value=attack_value,
    )

    # Create an EOA with funds for the deployer
    sender = pre.fund_eoa()

    # Build attack transactions
    attack_txs: list[TransactionWithCost] = list(
        attack_orchestrator_bytecode.transactions_by_gas_limit(
            fork=fork,
            gas_limit=gas_benchmark_value,
            start_iteration=0,
            sender=sender,
            to=attack_orchestrator_address,
            calldata=calldata,
        )
    )

    total_gas_cost = sum(tx.gas_cost for tx in attack_txs)

    benchmark_test(
        pre=pre,
        blocks=[Block(txs=attack_txs)],
        post=post,
        expected_benchmark_gas_used=total_gas_cost,
    )

Parametrized Test Cases

This test generates 13 parametrized test cases across 3 forks.