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
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 | @pytest.mark.with_all_call_opcodes()
def test_call_to_pre_authorized_oog(
state_test: StateTestFiller,
pre: Alloc,
fork: Fork,
call_opcode: Op,
) -> None:
"""
Test additional cost of delegation contract access in call instructions.
"""
# Delegation contract. It should never be reached by a call.
delegation_code = Op.SSTORE(0, 1)
delegation = pre.deploy_contract(delegation_code)
# Delegate to the delegation contract.
auth_signer = pre.fund_eoa(0, delegation=delegation)
# Callee tries to call the auth_signer which delegates
# to the delegation contract. The call instruction should out-of-gas
# because of the addition cost of the delegation account access.
callee_code = Op.SSTORE(0, call_opcode(gas=0, address=auth_signer))
callee_storage = Storage()
callee_storage[0] = 0xFF # Value other than 0 or 1. Should not be changed.
callee_address = pre.deploy_contract(callee_code, storage=callee_storage)
intrinsic_gas_cost_calculator = (
fork.transaction_intrinsic_cost_calculator()
)
tx_gas_limit = (
intrinsic_gas_cost_calculator()
+ (
Op.PUSH1(0) * len(call_opcode.kwargs)
+ call_opcode(address_warm=False, delegated_address=True)
).gas_cost(fork)
- 1
)
tx = Transaction(
gas_limit=tx_gas_limit, # Specific gas to trigger CALL out-of-gas.
to=callee_address,
sender=pre.fund_eoa(),
)
expected_block_access_list = None
if fork.is_eip_enabled(7928):
# Sender nonce changes, callee is accessed but storage unchanged (OOG)
# auth_signer is tracked (we read its code to check delegation)
# delegation is NOT tracked (OOG before reading it)
account_expectations = {
tx.sender: BalAccountExpectation(
nonce_changes=[
BalNonceChange(block_access_index=1, post_nonce=1)
],
),
callee_address: BalAccountExpectation.empty(),
# read for calculating delegation access cost:
auth_signer: BalAccountExpectation.empty(),
# OOG - not enough gas for delegation access:
delegation: None,
}
expected_block_access_list = BlockAccessListExpectation(
account_expectations=account_expectations
)
state_test(
pre=pre,
tx=tx,
post={
callee_address: Account(storage=callee_storage),
auth_signer: Account(code=Spec.delegation_designation(delegation)),
delegation: Account(storage=Storage()),
},
expected_block_access_list=expected_block_access_list,
)
|