From f83fe44326c469874dab3c6c4b1f0b85e60dcd7a Mon Sep 17 00:00:00 2001 From: Nicolas Deschildre Date: Fri, 3 May 2024 21:04:14 +0200 Subject: [PATCH 1/4] Fix: eth_estimateGas with blobs fails when capped by limited funds --- eth/gasestimator/gasestimator.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index f07f98956e3c..9d33212fefa5 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -80,6 +80,11 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin } available.Sub(available, call.Value) } + if opts.Config.IsCancun(opts.Header.Number, opts.Header.Time) && len(call.BlobHashes) > 0 { + blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes) * params.BlobTxBlobGasPerBlob)) + blobBalanceUsage.Mul(blobBalanceUsage, call.BlobGasFeeCap) + available.Sub(available, blobBalanceUsage) + } allowance := new(big.Int).Div(available, feeCap) // If the allowance is larger than maximum uint64, skip checking From fcee52406ed6e0ee25db6be67e90dd1892237204 Mon Sep 17 00:00:00 2001 From: Nicolas Deschildre Date: Tue, 7 May 2024 07:43:40 +0200 Subject: [PATCH 2/4] blobBalanceUsage: Adding check for balance. --- eth/gasestimator/gasestimator.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index 9d33212fefa5..8e1bb58cbca9 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -83,6 +83,9 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin if opts.Config.IsCancun(opts.Header.Number, opts.Header.Time) && len(call.BlobHashes) > 0 { blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes) * params.BlobTxBlobGasPerBlob)) blobBalanceUsage.Mul(blobBalanceUsage, call.BlobGasFeeCap) + if blobBalanceUsage.Cmp(available) >= 0 { + return 0, nil, core.ErrInsufficientFunds + } available.Sub(available, blobBalanceUsage) } allowance := new(big.Int).Div(available, feeCap) From a976688c1e161950e825128fc614f69e1ad16540 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 May 2024 13:43:04 +0200 Subject: [PATCH 3/4] Update gasestimator.go --- eth/gasestimator/gasestimator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index 8e1bb58cbca9..46796595e592 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -81,7 +81,7 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin available.Sub(available, call.Value) } if opts.Config.IsCancun(opts.Header.Number, opts.Header.Time) && len(call.BlobHashes) > 0 { - blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes) * params.BlobTxBlobGasPerBlob)) + blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes)) * params.BlobTxBlobGasPerBlob) blobBalanceUsage.Mul(blobBalanceUsage, call.BlobGasFeeCap) if blobBalanceUsage.Cmp(available) >= 0 { return 0, nil, core.ErrInsufficientFunds From e41244d7d15e53e7e4518d48096a040965525705 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 7 May 2024 13:56:55 +0200 Subject: [PATCH 4/4] Update gasestimator.go --- eth/gasestimator/gasestimator.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/eth/gasestimator/gasestimator.go b/eth/gasestimator/gasestimator.go index 46796595e592..ac3b59e97e8b 100644 --- a/eth/gasestimator/gasestimator.go +++ b/eth/gasestimator/gasestimator.go @@ -81,7 +81,9 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin available.Sub(available, call.Value) } if opts.Config.IsCancun(opts.Header.Number, opts.Header.Time) && len(call.BlobHashes) > 0 { - blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes)) * params.BlobTxBlobGasPerBlob) + blobGasPerBlob := new(big.Int).SetInt64(params.BlobTxBlobGasPerBlob) + blobBalanceUsage := new(big.Int).SetInt64(int64(len(call.BlobHashes))) + blobBalanceUsage.Mul(blobBalanceUsage, blobGasPerBlob) blobBalanceUsage.Mul(blobBalanceUsage, call.BlobGasFeeCap) if blobBalanceUsage.Cmp(available) >= 0 { return 0, nil, core.ErrInsufficientFunds