Skip to content

fix(rpc): raise eth_estimateGas until the message succeeds + tests - #7473

Open
LesnyRumcajs wants to merge 1 commit into
mainfrom
fix-eth-gas-search
Open

fix(rpc): raise eth_estimateGas until the message succeeds + tests#7473
LesnyRumcajs wants to merge 1 commit into
mainfrom
fix-eth-gas-search

Conversation

@LesnyRumcajs

@LesnyRumcajs LesnyRumcajs commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary of changes

Changes introduced in this pull request:

  • eth_estimateGas now probes at the caller's gas limit (not block max), so it searches upward when EIP-150's 63/64 rule makes a nested call need more.
  • better OOG checks - actually fixes one of the issues reported by CC in fix(eth): allow eth_call and eth_estimateGas from contract and non-existent senders #7435
  • new forest-dev devnet eth-gas - the forest-dev devnet * is supposed to be run strictly on a devnet, due to some docker calls inside and expectations about the environment. It does parity checks with Lotus and proper contract checks, without relying on calibnet. I feel we can use this approach more; no need to overengineer it for now, once we have more use-cases we could give it more form.
  • moved things around a bit - we might want to move wallet tests into forest-dev devnet * as well, but I'd make it a separate PR.

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes

    • Improved eth_estimateGas handling for nested calls and gas-limit scenarios.
    • Correctly reports execution reverts with standard error codes, decoded reasons, and return data.
    • Improved compatibility with Lotus responses and sender-specific execution behavior.
  • New Features

    • Added a devnet command for validating Ethereum gas-estimation parity.
    • Added support for VM traces during state execution and gas estimation.
  • Documentation

    • Updated the changelog and devnet testing guidance with the expanded test workflow.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a6fe0ecc-009a-4cbd-b404-183c1777b07a

📥 Commits

Reviewing files that changed from the base of the PR and between 98c7163 and c2292b3.

📒 Files selected for processing (2)
  • src/rpc/methods/eth/errors.rs
  • src/shim/executor.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/rpc/methods/eth/errors.rs

Walkthrough

The PR adds a forest-dev devnet eth-gas integration test, expands shared devnet harness support, and updates Ethereum gas estimation to use VM traces and decoded execution-revert errors. It also adds nested-gas contract fixtures, Lotus configuration, workflow wiring, and release metadata.

Changes

Ethereum gas estimation parity

Layer / File(s) Summary
Gas estimation tracing and revert handling
src/state_manager/message_simulation.rs, src/shim/executor.rs, src/rpc/methods/gas.rs, src/rpc/methods/eth.rs, src/rpc/methods/eth/errors.rs
Gas simulation accepts trace modes. Gas probing preserves message parameters. Revert errors include decoded data, exit codes, and VM error context.
Devnet Ethereum gas test flow
src/dev/subcommands/mod.rs, src/dev/subcommands/devnet_cmd.rs, src/dev/subcommands/devnet_cmd/eth_gas.rs, src/dev/subcommands/devnet_cmd/contracts/*
The new command performs devnet preflight checks, deploys a nested-call contract, compares Forest and Lotus estimates, submits a transaction, and validates revert errors.
Shared devnet test integration
src/dev/subcommands/tests_cmd.rs, src/dev/subcommands/tests_cmd/helpers.rs, scripts/devnet/*, mise.toml, .github/workflows/forest.yml
Shared command, RPC, Docker, and retry helpers support wallet, mpool, and eth-gas tests. The harness and workflow use the consolidated devnet task.
Release and dictionary updates
CHANGELOG.md, .config/forest.dic
The changelog records the gas estimation fixes. The dictionary entry changes from 294 to 295 and ABI.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant forest_dev
  participant DevnetCommand
  participant EthGasTestCommand
  participant ForestRPC
  participant LotusRPC
  forest_dev->>DevnetCommand: run eth-gas
  DevnetCommand->>ForestRPC: preflight block-number request
  DevnetCommand->>LotusRPC: preflight block-number request
  DevnetCommand->>EthGasTestCommand: run parity tests
  EthGasTestCommand->>ForestRPC: eth_estimateGas
  EthGasTestCommand->>LotusRPC: eth_estimateGas
  EthGasTestCommand->>ForestRPC: submit estimated transaction
Loading

Possibly related PRs

  • ChainSafe/forest#7435: Both PRs modify Ethereum gas estimation probing, sender validation, and revert/error handling.

Suggested reviewers: sudo-shashank, akaladarshi, eclesiomelojunior

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary eth_estimateGas behavior change and the added tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-eth-gas-search
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix-eth-gas-search

Comment @coderabbitai help to get the list of available commands.

@LesnyRumcajs LesnyRumcajs added the RPC requires calibnet RPC checks to run on CI label Aug 10, 2026
@LesnyRumcajs
LesnyRumcajs force-pushed the fix-eth-gas-search branch 5 times, most recently from abed524 to fda49f2 Compare August 10, 2026 16:40
@LesnyRumcajs
LesnyRumcajs force-pushed the fix-eth-gas-search branch 5 times, most recently from 4beeb1e to 98c7163 Compare August 11, 2026 13:05
@LesnyRumcajs
LesnyRumcajs marked this pull request as ready for review August 11, 2026 14:01
@LesnyRumcajs
LesnyRumcajs requested a review from a team as a code owner August 11, 2026 14:01
@LesnyRumcajs
LesnyRumcajs requested review from akaladarshi and sudo-shashank and removed request for a team August 11, 2026 14:01

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/rpc/methods/eth.rs (1)

2010-2036: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

gas_search can return a limit it never verified.

high starts at msg.gas_limit.max(1). If msg.gas_limit >= BLOCK_GAS_LIMIT, the while high < BLOCK_GAS_LIMIT loop never runs and the binary loop is skipped because high == low. The function then returns msg.gas_limit, which the caller already proved fails in eth_gas_search.

Clamp the start to below the block limit so the search still runs:

🐛 Proposed fix
-    // `max(1)` keeps the doubling below able to make progress.
-    let mut high = msg.gas_limit.max(1);
+    // `max(1)` keeps the doubling below able to make progress. The clamp keeps a caller-supplied
+    // limit at or above the block maximum from skipping the search entirely.
+    let mut high = msg.gas_limit.clamp(1, BLOCK_GAS_LIMIT - 1);
     let mut low = high;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/rpc/methods/eth.rs` around lines 2010 - 2036, Clamp the initial `high`
value in gas_search to a value below BLOCK_GAS_LIMIT while preserving the
minimum of 1, so the expansion loop runs even when msg.gas_limit is at or above
the block limit. Keep low initialized from this clamped high value and preserve
the existing search behavior.
🧹 Nitpick comments (1)
src/dev/subcommands/devnet_cmd/eth_gas.rs (1)

195-203: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

The pinned block can precede the deploy on one node.

common_block_number takes the lower of the two heads. That guarantees both nodes have executed the block. It does not guarantee the block is at or after the height where the contract and the sender landed. If Forest lags Lotus after lotus evm deploy, the pinned block can sit below the deploy height. The contract then does not exist at that block and the estimate fails for a reason unrelated to gas parity.

The funding poll usually absorbs the skew, so this is an intermittent risk rather than a certain failure. Consider polling until both nodes return non-empty code for the deployed address before you pin the block.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/dev/subcommands/devnet_cmd/eth_gas.rs` around lines 195 - 203, Update
pinned_common_block to wait until both forest_c and lotus_c report non-empty
code for the deployed contract address before calling common_block_number. Reuse
the existing deployed-address and polling utilities where available, preserving
the final pinned block selection only after both nodes have observed the
contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/rpc/methods/eth.rs`:
- Around line 2010-2036: Clamp the initial `high` value in gas_search to a value
below BLOCK_GAS_LIMIT while preserving the minimum of 1, so the expansion loop
runs even when msg.gas_limit is at or above the block limit. Keep low
initialized from this clamped high value and preserve the existing search
behavior.

---

Nitpick comments:
In `@src/dev/subcommands/devnet_cmd/eth_gas.rs`:
- Around line 195-203: Update pinned_common_block to wait until both forest_c
and lotus_c report non-empty code for the deployed contract address before
calling common_block_number. Reuse the existing deployed-address and polling
utilities where available, preserving the final pinned block selection only
after both nodes have observed the contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64363bca-fa46-4b0f-9d4e-74bbe2ec9e51

📥 Commits

Reviewing files that changed from the base of the PR and between f6ebc6a and 98c7163.

📒 Files selected for processing (20)
  • .config/forest.dic
  • .github/workflows/forest.yml
  • CHANGELOG.md
  • mise.toml
  • scripts/devnet/README.md
  • scripts/devnet/lotus.env
  • scripts/devnet/test_harness.sh
  • src/dev/subcommands/devnet_cmd.rs
  • src/dev/subcommands/devnet_cmd/contracts/compile.sh
  • src/dev/subcommands/devnet_cmd/contracts/nested_gas/nested_gas.hex
  • src/dev/subcommands/devnet_cmd/contracts/nested_gas/nested_gas.sol
  • src/dev/subcommands/devnet_cmd/eth_gas.rs
  • src/dev/subcommands/mod.rs
  • src/dev/subcommands/tests_cmd.rs
  • src/dev/subcommands/tests_cmd/helpers.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/errors.rs
  • src/rpc/methods/gas.rs
  • src/shim/executor.rs
  • src/state_manager/message_simulation.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 25.28474% with 328 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.06%. Comparing base (0b42ef6) to head (c2292b3).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/dev/subcommands/devnet_cmd/eth_gas.rs 0.00% 207 Missing ⚠️
src/rpc/methods/eth.rs 35.89% 50 Missing ⚠️
src/dev/subcommands/tests_cmd/helpers.rs 0.00% 40 Missing ⚠️
src/dev/subcommands/devnet_cmd.rs 0.00% 25 Missing ⚠️
src/shim/executor.rs 89.18% 3 Missing and 1 partial ⚠️
src/dev/subcommands/mod.rs 0.00% 1 Missing ⚠️
src/rpc/methods/eth/errors.rs 96.29% 0 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/dev/subcommands/tests_cmd.rs 0.00% <ø> (ø)
src/rpc/methods/gas.rs 88.23% <100.00%> (+1.47%) ⬆️
src/state_manager/message_simulation.rs 78.92% <100.00%> (+0.42%) ⬆️
src/dev/subcommands/mod.rs 71.42% <0.00%> (-1.04%) ⬇️
src/rpc/methods/eth/errors.rs 98.14% <96.29%> (+16.66%) ⬆️
src/shim/executor.rs 87.24% <89.18%> (+0.34%) ⬆️
src/dev/subcommands/devnet_cmd.rs 0.00% <0.00%> (ø)
src/dev/subcommands/tests_cmd/helpers.rs 0.00% <0.00%> (ø)
src/rpc/methods/eth.rs 68.79% <35.89%> (+0.22%) ⬆️
src/dev/subcommands/devnet_cmd/eth_gas.rs 0.00% <0.00%> (ø)

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f6ebc6a...c2292b3. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant