core: clarify delegation deletion flow

This commit is contained in:
Felix Lange 2024-12-02 14:29:16 +01:00 committed by lightclient
parent ace3a3f12c
commit 1110fc5fc6
No known key found for this signature in database
GPG key ID: 75C916AFEE20183E

View file

@ -553,6 +553,7 @@ func (st *stateTransition) validateAuthorization(auth *types.Authorization) (aut
code := st.state.GetCode(authority) code := st.state.GetCode(authority)
if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok { if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok {
return authority, ErrAuthorizationDestinationHasCode return authority, ErrAuthorizationDestinationHasCode
} }
if have := st.state.GetNonce(authority); have != auth.Nonce { if have := st.state.GetNonce(authority); have != auth.Nonce {
return authority, ErrAuthorizationNonceMismatch return authority, ErrAuthorizationNonceMismatch
@ -575,21 +576,22 @@ func (st *stateTransition) applyAuthorization(msg *Message, auth *types.Authoriz
// Update nonce and account code. // Update nonce and account code.
st.state.SetNonce(authority, auth.Nonce+1) st.state.SetNonce(authority, auth.Nonce+1)
delegation := types.AddressToDelegation(auth.Address)
if auth.Address == (common.Address{}) { if auth.Address == (common.Address{}) {
// If the delegation is for the zero address, completely clear all // Delegation to zero address means clear.
// delegations from the account. st.state.SetCode(authority, nil)
delegation = []byte{} return nil
} }
st.state.SetCode(authority, delegation)
// Usually the transaction destination and delegation target are added to // Otherwise install delegation to auth.Address.
// the access list in statedb.Prepare(..), however if the delegation is in st.state.SetCode(authority, types.AddressToDelegation(auth.Address))
// the same transaction we need add here as Prepare already happened.
// Usually the delegation target is added to the access list in statedb.Prepare(..).
// However if the destination address of the transaction is an EOA, and the EOA gains
// a new delegation in the same transaction, we need to explicitly add the delegation
// address here since Prepare has already happened.
if *msg.To == authority { if *msg.To == authority {
st.state.AddAddressToAccessList(auth.Address) st.state.AddAddressToAccessList(auth.Address)
} }
return nil return nil
} }