Skip to content

test_modexp_fork_transition()

Documentation for tests/osaka/eip7883_modexp_gas_increase/test_modexp_thresholds_transition.py::test_modexp_fork_transition@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7883_modexp_gas_increase/test_modexp_thresholds_transition.py::test_modexp_fork_transition --fork Osaka

Test ModExp gas cost transition from EIP-7883 before and after the Osaka hard fork.

Source code in tests/osaka/eip7883_modexp_gas_increase/test_modexp_thresholds_transition.py
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
@pytest.mark.parametrize(
    "modexp_input,modexp_expected,gas_old,gas_new",
    [
        pytest.param(Spec.modexp_input, Spec.modexp_expected, 200, 1200),
    ],
    ids=[""],
)
@EIPChecklist.GasCostChanges.Test.ForkTransition.Before()
@EIPChecklist.GasCostChanges.Test.ForkTransition.After()
@EIPChecklist.Precompile.Test.ForkTransition.After.Warm()
@EIPChecklist.GasCostChanges.Test.ForkTransition.Before()
@EIPChecklist.GasCostChanges.Test.ForkTransition.After()
def test_modexp_fork_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
    gas_old: int,
    gas_new: int,
    tx_gas_limit: int,
    modexp_input: ModExpInput,
    modexp_expected: bytes,
) -> None:
    """
    Test ModExp gas cost transition from EIP-7883 before and after the Osaka
    hard fork.
    """
    call_code = Op.CALL(
        address=Spec.MODEXP_ADDRESS,
        args_size=Op.CALLDATASIZE,
    )

    gas_costs = fork.gas_costs()
    extra_gas = (
        gas_costs.G_WARM_ACCOUNT_ACCESS
        + (gas_costs.G_VERY_LOW * (len(Op.CALL.kwargs) - 2))
        + (gas_costs.G_BASE * 3)
    )
    code = (
        Op.CALLDATACOPY(dest_offset=0, offset=0, size=Op.CALLDATASIZE)
        + Op.GAS  # [gas_start]
        + call_code  # [gas_start, call_result]
        + Op.GAS  # [gas_start, call_result, gas_end]
        + Op.SWAP1  # [gas_start, gas_end, call_result]
        + Op.POP  # [gas_start, gas_end]
        + Op.PUSH2[extra_gas]  # [gas_start, gas_end, extra_gas]
        + Op.ADD  # [gas_start, gas_end + extra_gas]
        + Op.SWAP1  # [gas_end + extra_gas, gas_start]
        + Op.SUB  # [gas_start - (gas_end + extra_gas)]
        + Op.TIMESTAMP  # [gas_start - (gas_end + extra_gas), TIMESTAMP]
        + Op.SSTORE  # []
    )

    # Verification the precompile call result
    code += Op.RETURNDATACOPY(dest_offset=0, offset=0, size=Op.RETURNDATASIZE()) + Op.SSTORE(
        Op.AND(Op.TIMESTAMP, 0xFF),
        Op.SHA3(0, Op.RETURNDATASIZE()),
    )

    senders = [pre.fund_eoa() for _ in range(3)]
    contracts = [pre.deploy_contract(code) for _ in range(3)]
    timestamps = [14_999, 15_000, 15_001]
    gas_values = [gas_old, gas_new, gas_new]

    blocks = [
        Block(
            timestamp=ts,
            txs=[
                Transaction(
                    to=contract,
                    data=modexp_input,
                    sender=sender,
                    gas_limit=tx_gas_limit,
                )
            ],
        )
        for ts, contract, sender in zip(timestamps, contracts, senders, strict=False)
    ]

    post = {
        contract: Account(storage={ts: gas, ts & 0xFF: keccak256(bytes(modexp_expected))})
        for contract, ts, gas in zip(contracts, timestamps, gas_values, strict=False)
    }

    blockchain_test(
        pre=pre,
        blocks=blocks,
        post=post,
    )

Parametrized Test Cases

This test case is only parametrized by fork.

Test ID (Abbreviated) modexp_input modexp_expected gas_old gas_new
...fork_PragueToOsakaAtTime15k-blockchain_test- base=b'\xe8\xe7v&Xos\xb9U6L{K\xbf\x0b\xb7\xf7h^\xbd@\xe8R\xb1dc:J\xcb\xd3$L\x00\x01\x02\x03\x04\x05\x06\x07' exponent=b'\x01\xff\xff\xff' modulus=b'\xf0\x16\x81\xd2"\x0b\xfe\xa4\xbb\x88\x8aUC\xdb\x8c\t\x16\'M\xdb\x1e\xa9;\x14L\x04,\x01\xd8\x16L\x95\x00\x01\x02\x03\x04\x05\x06\x07' extra_data=b'' raw_input=None declared_base_length=None declared_exponent_length=None declared_modulus_length=None 1abce71dc2205cce4eb6934397a88136 f94641342e283cbcd30e929e85605c67 18ed67f475192ffd 200 1200