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@88e9fb8f.

Generate fixtures for these test cases for Osaka with:

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

Test set to code address and authority warm status after a call to authority address, or vice-versa.

Source code in tests/prague/eip7702_set_code_tx/test_set_code_txs.py
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
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
@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,
) -> None:
    """
    Test set to code address and authority warm status after a call to
    authority address, or vice-versa.
    """
    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)
    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