Skip to content

Commit 43e2e58

Browse files
authored
accounts, internal: fix funding check when estimating gas (#21346)
* internal, accounts: fix funding check when estimate gas * accounts, internal: address comments
1 parent 35ddf36 commit 43e2e58

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

accounts/abi/bind/backends/simulated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
448448
hi = b.pendingBlock.GasLimit()
449449
}
450450
// Recap the highest gas allowance with account's balance.
451-
if call.GasPrice != nil && call.GasPrice.Uint64() != 0 {
451+
if call.GasPrice != nil && call.GasPrice.BitLen() != 0 {
452452
balance := b.pendingState.GetBalance(call.From) // from can't be nil
453453
available := new(big.Int).Set(balance)
454454
if call.Value != nil {
@@ -458,7 +458,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
458458
available.Sub(available, call.Value)
459459
}
460460
allowance := new(big.Int).Div(available, call.GasPrice)
461-
if hi > allowance.Uint64() {
461+
if allowance.IsUint64() && hi > allowance.Uint64() {
462462
transfer := call.Value
463463
if transfer == nil {
464464
transfer = new(big.Int)

internal/ethapi/api.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
966966
hi = block.GasLimit()
967967
}
968968
// Recap the highest gas limit with account's available balance.
969-
if args.GasPrice != nil && args.GasPrice.ToInt().Uint64() != 0 {
969+
if args.GasPrice != nil && args.GasPrice.ToInt().BitLen() != 0 {
970970
state, _, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
971971
if err != nil {
972972
return 0, err
@@ -980,7 +980,9 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
980980
available.Sub(available, args.Value.ToInt())
981981
}
982982
allowance := new(big.Int).Div(available, args.GasPrice.ToInt())
983-
if hi > allowance.Uint64() {
983+
984+
// If the allowance is larger than maximum uint64, skip checking
985+
if allowance.IsUint64() && hi > allowance.Uint64() {
984986
transfer := args.Value
985987
if transfer == nil {
986988
transfer = new(hexutil.Big)

0 commit comments

Comments
 (0)