@@ -553,6 +553,7 @@ func (st *stateTransition) validateAuthorization(auth *types.Authorization) (aut
553553 code := st .state .GetCode (authority )
554554 if _ , ok := types .ParseDelegation (code ); len (code ) != 0 && ! ok {
555555 return authority , ErrAuthorizationDestinationHasCode
556+
556557 }
557558 if have := st .state .GetNonce (authority ); have != auth .Nonce {
558559 return authority , ErrAuthorizationNonceMismatch
@@ -575,21 +576,22 @@ func (st *stateTransition) applyAuthorization(msg *Message, auth *types.Authoriz
575576
576577 // Update nonce and account code.
577578 st .state .SetNonce (authority , auth .Nonce + 1 )
578- delegation := types .AddressToDelegation (auth .Address )
579579 if auth .Address == (common.Address {}) {
580- // If the delegation is for the zero address, completely clear all
581- // delegations from the account.
582- delegation = [] byte {}
580+ // Delegation to zero address means clear.
581+ st . state . SetCode ( authority , nil )
582+ return nil
583583 }
584- st .state .SetCode (authority , delegation )
585584
586- // Usually the transaction destination and delegation target are added to
587- // the access list in statedb.Prepare(..), however if the delegation is in
588- // the same transaction we need add here as Prepare already happened.
585+ // Otherwise install delegation to auth.Address.
586+ st .state .SetCode (authority , types .AddressToDelegation (auth .Address ))
587+
588+ // Usually the delegation target is added to the access list in statedb.Prepare(..).
589+ // However if the destination address of the transaction is an EOA, and the EOA gains
590+ // a new delegation in the same transaction, we need to explicitly add the delegation
591+ // address here since Prepare has already happened.
589592 if * msg .To == authority {
590593 st .state .AddAddressToAccessList (auth .Address )
591594 }
592-
593595 return nil
594596}
595597
0 commit comments