core,eth: skip EIP-7702 authorization validation for gas estimation

This commit is contained in:
allen 2025-10-15 14:46:55 -04:00
parent b373d797d8
commit 9b1d7f6253
5 changed files with 19 additions and 14 deletions

View file

@ -575,16 +575,18 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
// validateAuthorization validates an EIP-7702 authorization against the state.
func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
skipValidation := st.msg.SkipTransactionChecks
// Verify chain ID is null or equal to current chain ID.
if !auth.ChainID.IsZero() && auth.ChainID.CmpBig(st.evm.ChainConfig().ChainID) != 0 {
if !skipValidation && !auth.ChainID.IsZero() && auth.ChainID.CmpBig(st.evm.ChainConfig().ChainID) != 0 {
return authority, ErrAuthorizationWrongChainID
}
// Limit nonce to 2^64-1 per EIP-2681.
if auth.Nonce+1 < auth.Nonce {
if !skipValidation && auth.Nonce+1 < auth.Nonce {
return authority, ErrAuthorizationNonceOverflow
}
// Validate signature values and recover authority.
authority, err = auth.Authority()
authority, err = auth.Authority(!skipValidation)
if err != nil {
return authority, fmt.Errorf("%w: %v", ErrAuthorizationInvalidSignature, err)
}
@ -594,12 +596,15 @@ func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorizatio
//
// Note it is added to the access list even if the authorization is invalid.
st.state.AddAddressToAccessList(authority)
code := st.state.GetCode(authority)
if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok {
return authority, ErrAuthorizationDestinationHasCode
}
if have := st.state.GetNonce(authority); have != auth.Nonce {
return authority, ErrAuthorizationNonceMismatch
// Skip state checks during gas estimation
if !skipValidation {
code := st.state.GetCode(authority)
if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok {
return authority, ErrAuthorizationDestinationHasCode
}
if have := st.state.GetNonce(authority); have != auth.Nonce {
return authority, ErrAuthorizationNonceMismatch
}
}
return authority, nil
}

View file

@ -525,7 +525,7 @@ func (tx *Transaction) SetCodeAuthorities() []common.Address {
auths = make([]common.Address, 0, len(setcodetx.AuthList))
)
for _, auth := range setcodetx.AuthList {
if addr, err := auth.Authority(); err == nil {
if addr, err := auth.Authority(true); err == nil {
if marks[addr] {
continue
}

View file

@ -115,9 +115,9 @@ func (a *SetCodeAuthorization) SigHash() common.Hash {
}
// Authority recovers the the authorizing account of an authorization.
func (a *SetCodeAuthorization) Authority() (common.Address, error) {
func (a *SetCodeAuthorization) Authority(validateSig bool) (common.Address, error) {
sighash := a.SigHash()
if !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) {
if validateSig && !crypto.ValidateSignatureValues(a.V, a.R.ToBig(), a.S.ToBig(), true) {
return common.Address{}, ErrInvalidSig
}
// encode the signature in uncompressed format

View file

@ -186,7 +186,7 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction
// Add accounts with authorizations to the prestate before they get applied.
for _, auth := range tx.SetCodeAuthorizations() {
addr, err := auth.Authority()
addr, err := auth.Authority(true)
if err != nil {
continue
}

View file

@ -1296,7 +1296,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
continue
}
if authority, err := auth.Authority(); err == nil {
if authority, err := auth.Authority(true); err == nil {
addressesToExclude[authority] = struct{}{}
}
}