215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311 | @EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize(
"invalidity",
[
pytest.param("invalid_nonce", id="invalid_nonce"),
pytest.param("invalid_chain_id", id="invalid_chain_id"),
pytest.param("repeated_nonce", id="repeated_nonce"),
pytest.param("authority_is_contract", id="authority_is_contract"),
],
)
@pytest.mark.pre_alloc_mutable
def test_invalid_auth_charged_intrinsic(
state_test: StateTestFiller,
env: Environment,
pre: Alloc,
fork: Fork,
invalidity: str,
) -> None:
"""
A skipped (invalid) authorization is still charged the full
intrinsic, and the invalid authority's account is left unchanged.
Each invalidity kind (``INVALID_NONCE``, ``INVALID_CHAIN_ID``,
``REPEATED_NONCE``, ``AUTHORITY_IS_CONTRACT``) makes the
authorization invalid during processing, so it is silently skipped,
but its execution + state intrinsic gas is still paid. The transaction
succeeds.
"""
contract = pre.deploy_contract(code=Op.STOP)
# Build a (possibly multi-element) authorization list where the
# authority that *should* end up untouched is the invalid one.
authorization_list: List[AuthorizationTuple] = []
if invalidity == "invalid_nonce":
authority = pre.fund_eoa()
authorization_list.append(
AuthorizationTuple(
address=contract,
nonce=99, # wrong nonce -> skipped
signer=authority,
)
)
expected_code: bytes | Bytecode = b""
elif invalidity == "invalid_chain_id":
authority = pre.fund_eoa()
authorization_list.append(
AuthorizationTuple(
address=contract,
nonce=0,
chain_id=9999, # wrong chain id -> skipped
signer=authority,
)
)
expected_code = b""
elif invalidity == "repeated_nonce":
# First auth is valid and consumes nonce 0; the second reuses
# nonce 0 and is therefore skipped. The (single) signer ends up
# delegated by the first auth, so assert that delegation.
authority = pre.fund_eoa()
authorization_list.append(
AuthorizationTuple(address=contract, nonce=0, signer=authority)
)
authorization_list.append(
AuthorizationTuple(address=contract, nonce=0, signer=authority)
)
expected_code = Spec7702.delegation_designation(contract)
elif invalidity == "authority_is_contract":
# An authority that is already a (non-delegation) contract is an
# invalid authority; the authorization is skipped and the
# contract code is left intact.
authority = pre.fund_eoa(code=Op.STOP)
authorization_list.append(
AuthorizationTuple(address=contract, nonce=0, signer=authority)
)
expected_code = Op.STOP
else:
raise ValueError(f"unknown invalidity: {invalidity!r}")
# The full intrinsic (execution + state) is charged regardless of
# validity. Provide a comfortable gas limit and let the receipt
# accounting be verified by the framework; the key assertion is the
# untouched-authority post state.
full_intrinsic = fork.transaction_intrinsic_cost_calculator()(
authorization_list_or_count=authorization_list,
)
assert full_intrinsic > 0
sender = pre.fund_eoa()
tx = Transaction(
to=contract,
authorization_list=authorization_list,
sender=sender,
)
post = {authority: Account(code=expected_code)}
state_test(env=env, pre=pre, post=post, tx=tx)
|