core: prevent no-op code change when clearing a 7702 delegation on an account that wasn't previously delegated, re-delegating to the same contract that was previously-delegated.

This commit is contained in:
Jared Wasinger 2025-10-15 15:32:30 +08:00
parent f6064f32c4
commit 4ad3f6148e

View file

@ -19,9 +19,6 @@ package core
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"math"
"math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -29,6 +26,8 @@ import (
"github.com/ethereum/go-ethereum/crypto/kzg4844" "github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"math"
"math/big"
) )
// ExecutionResult includes all output after executing given evm // ExecutionResult includes all output after executing given evm
@ -617,16 +616,22 @@ func (st *stateTransition) applyAuthorization(auth *types.SetCodeAuthorization)
st.state.AddRefund(params.CallNewAccountGas - params.TxAuthTupleGas) st.state.AddRefund(params.CallNewAccountGas - params.TxAuthTupleGas)
} }
prevDelegation, isDelegated := types.ParseDelegation(st.state.GetCode(authority))
// Update nonce and account code. // Update nonce and account code.
st.state.SetNonce(authority, auth.Nonce+1, tracing.NonceChangeAuthorization) st.state.SetNonce(authority, auth.Nonce+1, tracing.NonceChangeAuthorization)
if auth.Address == (common.Address{}) { if auth.Address == (common.Address{}) {
// Delegation to zero address means clear. // Delegation to zero address means clear.
st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear) if isDelegated {
st.state.SetCode(authority, nil, tracing.CodeChangeAuthorizationClear)
}
return nil return nil
} }
// Otherwise install delegation to auth.Address. // install delegation to auth.Address if the delegation changed
st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization) if !isDelegated || auth.Address != prevDelegation {
st.state.SetCode(authority, types.AddressToDelegation(auth.Address), tracing.CodeChangeAuthorization)
}
return nil return nil
} }