Skip to content

test_set_code_address_and_authority_warm_state()

Documentation for tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_address_and_authority_warm_state@21fb11c8.

Generate fixtures for these test cases for Prague with:

fill -v tests/prague/eip7702_set_code_tx/test_set_code_txs.py::test_set_code_address_and_authority_warm_state --fork Prague

Test set to code address and authority warm status after a call to authority address, or viceversa.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
@pytest.mark.with_all_evm_code_types()
@pytest.mark.parametrize(
    "set_code_address_first",
    [
        pytest.param(True, id="call_set_code_address_first_then_authority"),
        pytest.param(False, id="call_authority_first_then_set_code_address"),
    ],
)
def test_set_code_address_and_authority_warm_state(
    state_test: StateTestFiller,
    pre: Alloc,
    set_code_address_first: bool,
):
    """
    Test set to code address and authority warm status after a call to
    authority address, or viceversa.
    """
    auth_signer = pre.fund_eoa(auth_account_start_balance)

    slot = count(1)
    slot_call_success = next(slot)
    slot_set_code_to_warm_state = next(slot)
    slot_authority_warm_state = next(slot)

    set_code = Op.STOP
    set_code_to_address = pre.deploy_contract(set_code)

    call_opcode = Op.CALL
    overhead_cost = 3 * len(call_opcode.kwargs)  # type: ignore
    if call_opcode == Op.CALL:
        overhead_cost -= 1  # GAS opcode is less expensive than a PUSH

    code_gas_measure_set_code = CodeGasMeasure(
        code=call_opcode(address=set_code_to_address),
        overhead_cost=overhead_cost,
        extra_stack_items=1,
        sstore_key=slot_set_code_to_warm_state,
        stop=False,
    )
    code_gas_measure_authority = CodeGasMeasure(
        code=call_opcode(address=auth_signer),
        overhead_cost=overhead_cost,
        extra_stack_items=1,
        sstore_key=slot_authority_warm_state,
        stop=False,
    )

    callee_code = Bytecode()
    if set_code_address_first:
        callee_code += code_gas_measure_set_code + code_gas_measure_authority
    else:
        callee_code += code_gas_measure_authority + code_gas_measure_set_code
    callee_code += Op.SSTORE(slot_call_success, 1) + Op.STOP

    callee_address = pre.deploy_contract(callee_code, evm_code_type=EVMCodeType.LEGACY)
    callee_storage = Storage()
    callee_storage[slot_call_success] = 1
    callee_storage[slot_set_code_to_warm_state] = 2_600 if set_code_address_first else 100
    callee_storage[slot_authority_warm_state] = 200 if set_code_address_first else 2_700

    tx = Transaction(
        gas_limit=1_000_000,
        to=callee_address,
        authorization_list=[
            AuthorizationTuple(
                address=set_code_to_address,
                nonce=0,
                signer=auth_signer,
            ),
        ],
        sender=pre.fund_eoa(),
    )

    state_test(
        env=Environment(),
        pre=pre,
        tx=tx,
        post={
            callee_address: Account(storage=callee_storage),
            auth_signer: Account(
                nonce=1,
                code=Spec.delegation_designation(set_code_to_address),
                balance=auth_account_start_balance,
            ),
        },
    )

Parametrized Test Cases

The interactive table below is also available as a standalone page.

Test ID (Abbreviated) evm_code_type set_code_address_first
...fork_Prague-evm_code_type_LEGACY-state_test-call_set_code_address_first_then_authority LEGACY True
...fork_Prague-evm_code_type_LEGACY-state_test-call_authority_first_then_set_code_address LEGACY False
...fork_Prague-evm_code_type_LEGACY-blockchain_test_from_state_test-call_set_code_address_first_then_authority LEGACY True
...fork_Prague-evm_code_type_LEGACY-blockchain_test_from_state_test-call_authority_first_then_set_code_address LEGACY False
...fork_Osaka-evm_code_type_LEGACY-state_test-call_set_code_address_first_then_authority LEGACY True
...fork_Osaka-evm_code_type_LEGACY-state_test-call_authority_first_then_set_code_address LEGACY False
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-call_set_code_address_first_then_authority LEGACY True
...fork_Osaka-evm_code_type_LEGACY-blockchain_test_from_state_test-call_authority_first_then_set_code_address LEGACY False
...fork_Osaka-evm_code_type_EOF_V1-state_test-call_set_code_address_first_then_authority EOF_V1 True
...fork_Osaka-evm_code_type_EOF_V1-state_test-call_authority_first_then_set_code_address EOF_V1 False
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-call_set_code_address_first_then_authority EOF_V1 True
...fork_Osaka-evm_code_type_EOF_V1-blockchain_test_from_state_test-call_authority_first_then_set_code_address EOF_V1 False