core/txpool: check authoirization nonce is not stale

This commit is contained in:
lightclient 2025-02-07 13:12:29 -07:00
parent 0c0d6b33ab
commit 2dc72d52f7
No known key found for this signature in database
GPG key ID: 657913021EF45A6A
2 changed files with 13 additions and 0 deletions

View file

@ -65,4 +65,8 @@ var (
// signed by an address which already has in-flight transactions known to the // signed by an address which already has in-flight transactions known to the
// pool. // pool.
ErrAuthorityReserved = errors.New("authority already reserved") ErrAuthorityReserved = errors.New("authority already reserved")
// ErrAuthorityNonce is returned if a transaction has an authorization with
// a nonce that is not currently valid for the authority.
ErrAuthorityNonceTooLow = errors.New("authority nonce too low")
) )

View file

@ -284,6 +284,15 @@ func ValidateTransactionWithState(tx *types.Transaction, signer types.Signer, op
return fmt.Errorf("%w: authorization conflicts with other known tx", ErrAuthorityReserved) return fmt.Errorf("%w: authorization conflicts with other known tx", ErrAuthorityReserved)
} }
} }
// Verify the every authorization's nonce is not stale. This check is expensive.
for _, auth := range tx.SetCodeAuthorizations() {
if addr, err := auth.Authority(); err == nil {
next := opts.State.GetNonce(addr)
if auth.Nonce < next {
return fmt.Errorf("%w: next nonce %d, auth nonce %d", ErrAuthorityNonceTooLow, next, auth.Nonce)
}
}
}
} }
return nil return nil
} }