Skip to content

eth/gasestimator: check ErrGasLimitTooHigh conditions #32268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

mininny
Copy link
Contributor

@mininny mininny commented Jul 24, 2025

This PR makes 2 changes to how EIP-7825 behaves.

When eth_estimateGas or eth_createAccessList is called without any gas limit in the payload, geth will choose the block's gas limit or the RPCGasCap, which can be larger than the maxTxGas.

When this happens for estimateGas, the gas estimation just errors out and ends, when it should continue doing binary search to find the lowest possible gas limit.

This PR will:

  • Add a check to see if hi is larger than maxTxGas and cap it to maxTxGas if it's larger. And add a special case handling for gas estimation execute when it errs with ErrGasLimitTooHigh

  • Decrease the RPCGasCap to 30M (== maxTxGas) to make createAccessList choose 30M as the highest gas cap for the tx. This can also be fixed by adding a check like this to use maxTxGas when the specified RPCGasCap is larger than maxTxGas. I'd be glad to fix it either way!

gasCap :=b.RPCGasCap()  
if gasCap > params.MaxTxGas { 
    gasCap = params.MaxTxGas
}

I've created this PR for fusaka-devnet-3 first, and will open another pr to master (or there is some periodic merges to master) if needed.

reallesee and others added 3 commits July 22, 2025 23:06
Replace manual byte-by-byte XOR implementation with the optimized
bitutil.XORBytes function. This improves performance by using word-sized
operations on supported architectures while maintaining the same
functionality. The optimized version processes data in bulk rather than
one byte at a time

---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Improve binary search, preventing the potential overflow in certain L2 cases
Seems the `signal.result` was not sent back in shorten case, this will
cause a deadlock.

---------

Signed-off-by: jsvisa <delweng@gmail.com>
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
@mininny mininny requested a review from rjl493456442 as a code owner July 24, 2025 07:48
Adds the heal time and snap sync time to grafana

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
@@ -62,6 +62,9 @@ func Estimate(ctx context.Context, call *core.Message, opts *Options, gasCap uin
if call.GasLimit >= params.TxGas {
hi = call.GasLimit
}
if hi >= params.MaxTxGas {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might break L2 projects whose transactions potentially consume more gas in order to amortize L1 costs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have misunderstood the code, but even if the L2s specified gas higher than MaxTxGas, wouldn't it err with ErrGasLimitTooHigh and return error for the estimateGas call anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right!

I will ask L2 forks how they plan to integrate the EIP-7825 first, but generally your changes look good to me.

Copy link
Member

@rjl493456442 rjl493456442 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gas capping should only be applied for Osaka

	// Cap the maximum gas allowance according to EIP-7825 if the estimation targets Osaka
	if hi > params.MaxTxGas {
		blockNumber, blockTime := opts.Header.Number, opts.Header.Time
		if opts.BlockOverrides != nil {
			if opts.BlockOverrides.Number != nil {
				blockNumber = opts.BlockOverrides.Number.ToInt()
			}
			if opts.BlockOverrides.Time != nil {
				blockTime = uint64(*opts.BlockOverrides.Time)
			}
		}
		if opts.Config.IsOsaka(blockNumber, blockTime) {
			hi = params.MaxTxGas
		}
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood, thank you! I've updated the code to your suggestion 🙏

nthumann and others added 2 commits July 28, 2025 09:13
The `errors.new` function does not require string formatting, so its
performance is better than that of `fmt.Errorf`.
…m#32269)

Correct the error message in the ExecuteStatelessPayloadV4 function to
reference newPayloadV4 and the Prague fork, instead of incorrectly
referencing newPayloadV3 and Cancun. 

This improves clarity during debugging and aligns the error message with 
the actual function and fork being validated. No logic is changed.

---------

Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
rjl493456442 and others added 5 commits July 28, 2025 14:57
The errors.new function does not require string formatting, so its
performance is better than that of fmt.Errorf.
This PR addresses a flakiness in the rollback test discussed in
ethereum#32252

I found `nonce` collision caused transactions occasionally fail to send.
I tried to change error message in the failed test like:

```
	if err = client.SendTransaction(ctx, signedTx); err != nil {
		t.Fatalf("failed to send transaction: %v, nonce: %d", err, signedTx.Nonce())
	}
```

and I occasionally got test failure with this message:

```
=== CONT  TestFlakyFunction/Run_#100
    rollback_test.go:44: failed to send transaction: already known, nonce: 0
--- FAIL: TestFlakyFunction/Run_#100 (0.07s)
```

Although `nonces` are obtained via `PendingNonceAt`, we observed that,
in rare cases (approximately 1 in 1000), two transactions from the same
sender end up with the same nonce. This likely happens because `tx0` has
not yet propagated to the transaction pool before `tx1` requests its
nonce. When the test succeeds, `tx0` and `tx1` have nonces `0` and `1`,
respectively. However, in rare failures, both transactions end up with
nonce `0`.

We modified the test to explicitly assign nonces to each transaction. By
controlling the nonce values manually, we eliminated the race condition
and ensured consistent behavior. After several thousand runs, the
flakiness was no longer reproducible in my local environment.

Reduced internal polling interval in `pendingStateHasTx()` to speed up
test execution without impacting stability. It reduces test time for
`TestTransactionRollbackBehavior` from about 7 seconds to 2 seconds.
Improvement: preallocate capacity for `logs` at first to avoid
reallocating multi times.
@rjl493456442 rjl493456442 changed the title fix: ErrGasLimitTooHigh conditions for estimateGas and createAccessList eth/gasestimator: check ErrGasLimitTooHigh conditions Jul 29, 2025
@rjl493456442
Copy link
Member

Oops, the compilation is failing

: # github.com/ethereum/go-ethereum/internal/ethapi/override [github.com/ethereum/go-ethereum/internal/ethapi/override.test]
internal/ethapi/override/override_test.go:45:39: cannot use &precompileContract{} (value of type *precompileContract) as vm.PrecompiledContract value in map literal: *precompileContract does not implement vm.PrecompiledContract (missing method Name)
internal/ethapi/override/override_test.go:46:39: cannot use &precompileContract{} (value of type *precompileContract) as vm.PrecompiledContract value in map literal: *precompileContract does not implement vm.PrecompiledContract (missing method Name)

fjl and others added 4 commits July 31, 2025 12:13
This adds a cross-client protocol test for a recently discovered bug in Nethermind.
This pull request optimizes trie hashing by reducing memory allocation
overhead. Specifically:

- define a fullNodeEncoder pool to reuse encoders and avoid memory
allocations.

- simplify the encoding logic for shortNode and fullNode by getting rid
of the Go interfaces.
This adds a method on vm.EVM to set the jumpdest cache implementation.
It can be used to maintain an analysis cache across VM invocations, to improve
performance by skipping the analysis for already known contracts.

---------

Co-authored-by: lmittmann <lmittmann@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
@rjl493456442 rjl493456442 force-pushed the feat/mininny/allow-gaslimit-errors-in-estimateGas branch from 8121be4 to b58e83f Compare August 1, 2025 12:31
@rjl493456442 rjl493456442 force-pushed the feat/mininny/allow-gaslimit-errors-in-estimateGas branch from b58e83f to 5ef01bb Compare August 1, 2025 12:37
@rjl493456442
Copy link
Member

Just realized you are opening the PR against [ethereum:fusaka-devnet-3](https://github.com/ethereum/go-ethereum/tree/fusaka-devnet-3). Any particular reason?

Sorry I messed your branch, I thought it's against master

@mininny
Copy link
Contributor Author

mininny commented Aug 5, 2025

@rjl493456442 Hi, sorry for taking a while to check back on this.
I originally created this against fusaka-devnet-3 because I was working on testing the latest fusaka spec.

I just created another PR to master with clean commit history since this isn't necessarily for fusaka specific. #32348

@rjl493456442
Copy link
Member

Implemented in the #32348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.