all: fix panic

This commit is contained in:
Gary Rong 2026-06-24 14:16:28 +08:00 committed by MariusVanDerWijden
parent 7d5b36f86c
commit 271b6c8d03
No known key found for this signature in database
3 changed files with 18 additions and 3 deletions

View file

@ -133,8 +133,14 @@ func Transaction(ctx *cli.Context) error {
r.Address = sender r.Address = sender
} }
// Check intrinsic gas // Check intrinsic gas
value, overflow := uint256.FromBig(tx.Value())
if overflow {
// A 256-bit overflow is reported by the field validation below; use a
// non-zero placeholder so intrinsic gas is still computed and reported.
value = uint256.NewInt(1)
}
rules := chainConfig.Rules(common.Big0, true, 0) rules := chainConfig.Rules(common.Big0, true, 0)
cost, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), r.Address, tx.To(), uint256.MustFromBig(tx.Value()), rules, params.CostPerStateByte) cost, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), r.Address, tx.To(), value, rules, params.CostPerStateByte)
if err != nil { if err != nil {
r.Error = err r.Error = err
results = append(results, r) results = append(results, r)

View file

@ -125,9 +125,14 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
if tx.Nonce()+1 < tx.Nonce() { if tx.Nonce()+1 < tx.Nonce() {
return core.ErrNonceMax return core.ErrNonceMax
} }
// Sanity check for extremely large numbers (supported by RLP or RPC)
value, overflow := uint256.FromBig(tx.Value())
if overflow {
return core.ErrInsufficientFunds
}
// Ensure the transaction has more gas than the bare minimum needed to cover // Ensure the transaction has more gas than the bare minimum needed to cover
// the transaction metadata // the transaction metadata
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), from, tx.To(), uint256.MustFromBig(tx.Value()), rules, params.CostPerStateByte) intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), from, tx.To(), value, rules, params.CostPerStateByte)
if err != nil { if err != nil {
return err return err
} }

View file

@ -82,7 +82,11 @@ func (tt *TransactionTest) Run() error {
return return
} }
// Intrinsic cost // Intrinsic cost
cost, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), sender, tx.To(), uint256.MustFromBig(tx.Value()), rules, params.CostPerStateByte) value, overflow := uint256.FromBig(tx.Value())
if overflow {
return sender, hash, 0, errors.New("value exceeds 256 bits")
}
cost, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.SetCodeAuthorizations(), sender, tx.To(), value, rules, params.CostPerStateByte)
if err != nil { if err != nil {
return return
} }