mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
core,eth: skip EIP-7702 authorization validation for gas estimation
This commit is contained in:
parent
b373d797d8
commit
9b1d7f6253
5 changed files with 19 additions and 14 deletions
|
|
@ -575,16 +575,18 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
|
||||||
|
|
||||||
// validateAuthorization validates an EIP-7702 authorization against the state.
|
// validateAuthorization validates an EIP-7702 authorization against the state.
|
||||||
func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
|
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.
|
// 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
|
return authority, ErrAuthorizationWrongChainID
|
||||||
}
|
}
|
||||||
// Limit nonce to 2^64-1 per EIP-2681.
|
// 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
|
return authority, ErrAuthorizationNonceOverflow
|
||||||
}
|
}
|
||||||
// Validate signature values and recover authority.
|
// Validate signature values and recover authority.
|
||||||
authority, err = auth.Authority()
|
authority, err = auth.Authority(!skipValidation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return authority, fmt.Errorf("%w: %v", ErrAuthorizationInvalidSignature, err)
|
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.
|
// Note it is added to the access list even if the authorization is invalid.
|
||||||
st.state.AddAddressToAccessList(authority)
|
st.state.AddAddressToAccessList(authority)
|
||||||
code := st.state.GetCode(authority)
|
// Skip state checks during gas estimation
|
||||||
if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok {
|
if !skipValidation {
|
||||||
return authority, ErrAuthorizationDestinationHasCode
|
code := st.state.GetCode(authority)
|
||||||
}
|
if _, ok := types.ParseDelegation(code); len(code) != 0 && !ok {
|
||||||
if have := st.state.GetNonce(authority); have != auth.Nonce {
|
return authority, ErrAuthorizationDestinationHasCode
|
||||||
return authority, ErrAuthorizationNonceMismatch
|
}
|
||||||
|
if have := st.state.GetNonce(authority); have != auth.Nonce {
|
||||||
|
return authority, ErrAuthorizationNonceMismatch
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return authority, nil
|
return authority, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -525,7 +525,7 @@ func (tx *Transaction) SetCodeAuthorities() []common.Address {
|
||||||
auths = make([]common.Address, 0, len(setcodetx.AuthList))
|
auths = make([]common.Address, 0, len(setcodetx.AuthList))
|
||||||
)
|
)
|
||||||
for _, auth := range 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] {
|
if marks[addr] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,9 +115,9 @@ func (a *SetCodeAuthorization) SigHash() common.Hash {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authority recovers the the authorizing account of an authorization.
|
// 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()
|
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
|
return common.Address{}, ErrInvalidSig
|
||||||
}
|
}
|
||||||
// encode the signature in uncompressed format
|
// encode the signature in uncompressed format
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Add accounts with authorizations to the prestate before they get applied.
|
||||||
for _, auth := range tx.SetCodeAuthorizations() {
|
for _, auth := range tx.SetCodeAuthorizations() {
|
||||||
addr, err := auth.Authority()
|
addr, err := auth.Authority(true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1296,7 +1296,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if authority, err := auth.Authority(); err == nil {
|
if authority, err := auth.Authority(true); err == nil {
|
||||||
addressesToExclude[authority] = struct{}{}
|
addressesToExclude[authority] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue