@@ -3487,3 +3487,82 @@ def test_authorization_reusing_nonce(
3487
3487
sender : Account (nonce = 1 ),
3488
3488
},
3489
3489
)
3490
+
3491
+
3492
+ @pytest .mark .parametrize (
3493
+ "set_code_type" ,
3494
+ list (AddressType ),
3495
+ ids = lambda address_type : address_type .name ,
3496
+ )
3497
+ @pytest .mark .parametrize (
3498
+ "self_sponsored" ,
3499
+ [True , False ],
3500
+ )
3501
+ @pytest .mark .execute (pytest .mark .skip (reason = "Requires contract-eoa address collision" ))
3502
+ def test_set_code_from_account_with_non_delegating_code (
3503
+ state_test : StateTestFiller ,
3504
+ pre : Alloc ,
3505
+ set_code_type : AddressType ,
3506
+ self_sponsored : bool ,
3507
+ ):
3508
+ """
3509
+ Test that a transaction is correctly rejected,
3510
+ if the sender account has a non-delegating code set.
3511
+
3512
+ The auth transaction is sent from sender which has contract code (not delegating)
3513
+ But at the same time it has auth tuple that will point this sender account
3514
+ To be eoa, delegation, contract .. etc
3515
+ """
3516
+ sender = pre .fund_eoa ()
3517
+ random_address = pre .fund_eoa (0 )
3518
+
3519
+ set_code_to_address : Address
3520
+ match set_code_type :
3521
+ case AddressType .EMPTY_ACCOUNT :
3522
+ set_code_to_address = pre .fund_eoa (0 )
3523
+ case AddressType .EOA :
3524
+ set_code_to_address = pre .fund_eoa (1 )
3525
+ case AddressType .EOA_WITH_SET_CODE :
3526
+ set_code_account = pre .fund_eoa (0 )
3527
+ set_code_to_address = pre .fund_eoa (1 , delegation = set_code_account )
3528
+ case AddressType .CONTRACT :
3529
+ set_code_to_address = pre .deploy_contract (Op .STOP )
3530
+ case _:
3531
+ raise ValueError (f"Unsupported set code type: { set_code_type } " )
3532
+ callee_address = pre .deploy_contract (Op .SSTORE (0 , 1 ) + Op .STOP )
3533
+
3534
+ # Set the sender account to have some code, that is specifically not a delegation.
3535
+ sender_account = pre [sender ]
3536
+ assert sender_account is not None
3537
+ sender_account .code = Bytes (Op .STOP )
3538
+
3539
+ tx = Transaction (
3540
+ gas_limit = 100_000 ,
3541
+ to = callee_address ,
3542
+ authorization_list = [
3543
+ AuthorizationTuple (
3544
+ address = set_code_to_address ,
3545
+ nonce = 1 if self_sponsored else 0 ,
3546
+ signer = sender if self_sponsored else random_address ,
3547
+ ),
3548
+ ],
3549
+ sender = sender ,
3550
+ error = TransactionException .SENDER_NOT_EOA ,
3551
+ )
3552
+
3553
+ state_test (
3554
+ env = Environment (),
3555
+ pre = pre ,
3556
+ tx = tx ,
3557
+ post = {
3558
+ set_code_to_address : (
3559
+ Account .NONEXISTENT
3560
+ if set_code_type == AddressType .EMPTY_ACCOUNT
3561
+ else Account (storage = {})
3562
+ ),
3563
+ random_address : Account .NONEXISTENT
3564
+ if not self_sponsored
3565
+ else Account (code = Bytes (Op .STOP )),
3566
+ callee_address : Account (storage = {0 : 0 }),
3567
+ },
3568
+ )
0 commit comments