Skip to content

fix(eth): allow eth_call and eth_estimateGas from contract and non-existent senders - #7435

Open
sudo-shashank wants to merge 12 commits into
mainfrom
shashank/port-eth-changes
Open

fix(eth): allow eth_call and eth_estimateGas from contract and non-existent senders#7435
sudo-shashank wants to merge 12 commits into
mainfrom
shashank/port-eth-changes

Conversation

@sudo-shashank

@sudo-shashank sudo-shashank commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #7394

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_call and eth_estimateGas support for contract senders and accounts that do not yet exist on-chain.
    • Preserved execution-revert details while applying appropriate gas limits and validation behavior.
    • Improved sender validation consistency across gas estimation, message simulation, and trace calls.
  • Tests

    • Added parity coverage across API versions for existing, missing, and omitted senders, insufficient funds, contract creation, failures, and future block queries.
  • Documentation

    • Added the update to the unreleased changelog.

@sudo-shashank sudo-shashank added the RPC requires calibnet RPC checks to run on CI label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation and tests address sender-validation bypass, but no evidence shows the required performance benchmark against Lotus was completed [#7394]. Add benchmark results comparing Forest with Lotus and verify that Forest is at least as performant out of the box.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The code, tests, changelog, and Lotus image updates support the sender-validation changes and do not introduce unrelated scope.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: allowing eth_call and eth_estimateGas from contract and nonexistent senders.

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

@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.

Actionable comments posted: 2

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)

2109-2124: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

A zero msg.gas_limit makes the growth loop run forever.

If msg.gas_limit is 0 on entry, then high = 0 and low = 0. The condition high < BLOCK_GAS_LIMIT holds. can_succeed at limit 0 fails. Line 2123 then computes 0.saturating_mul(2).min(BLOCK_GAS_LIMIT), which is 0. high never grows and the loop never exits. Each iteration performs a full VM execution through call_with_gas, so the request thread hangs and consumes CPU without bound.

The new Skip path makes this reachable. eth_estimate_gas_skip_sender derives gas_limit from GasEstimateGasLimit::estimate_gas_limit, which returns -1 when the receipt is absent (src/rpc/methods/gas.rs Line 286). At Lines 1966-1967 the value becomes ((-1i64 as f64) * overestimation) as u64. A negative f64 to u64 cast saturates to 0 in Rust, so msg.set_gas_limit(0) runs and 0 reaches gas_search.

Fix the loop so it always makes progress. Also reject the -1 sentinel in eth_estimate_gas_skip_sender before you scale it.

🐛 Proposed fix
     let mut high = msg.gas_limit;
     let mut low = msg.gas_limit;
 
+    // A zero limit would make the doubling below stall at zero.
+    if high == 0 {
+        high = 1;
+    }
+

Apply this at Lines 1966-1968 so the sentinel never becomes a gas limit:

+    anyhow::ensure!(
+        gas_limit >= 0,
+        "gas estimation returned no receipt for a skipped-validation sender"
+    );
     let gas_limit =
         ((gas_limit as f64 * ctx.mpool.gas_limit_overestimation()) as u64).min(BLOCK_GAS_LIMIT);
     msg.set_gas_limit(gas_limit);
🤖 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 2109 - 2124, Prevent zero gas limits
from stalling gas search and reject the missing-receipt sentinel. In gas_search,
ensure the growth loop always advances when high is zero while preserving the
BLOCK_GAS_LIMIT cap; in eth_estimate_gas_skip_sender, detect the -1 result from
GasEstimateGasLimit::estimate_gas_limit before scaling or calling
msg.set_gas_limit, and return the existing appropriate error path instead.
🧹 Nitpick comments (1)
src/rpc/methods/eth.rs (1)

1988-2015: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Consider accepting the resolved policy as a parameter to avoid a wasted VM execution.

apply_message always attempts SenderValidation::Enforce first, then retries with Skip. Callers that already resolved the policy pay for the discarded first execution.

eth_estimate_gas_skip_sender is one such caller. It resolves the policy through resolve_sender_validation before it runs, then its error arm at Line 1956 calls apply_message, which repeats the Enforce attempt and retries. That is two full VM executions on a request already known to need Skip.

The PR objective includes benchmarking against Lotus. Adding a sender_validation: SenderValidation parameter removes the redundant execution on the known-skip path while keeping the detect-and-retry fallback for callers that pass Enforce.

♻️ Proposed refactor
 async fn apply_message(
     ctx: &Ctx,
     tipset: Option<Tipset>,
     msg: Message,
+    sender_validation: SenderValidation,
 ) -> Result<ApiInvocResult, Error> {
@@
     let result = ctx
         .state_manager
         .apply_on_state_with_gas(
             tipset.clone(),
             msg.clone(),
             VMFlush::Skip,
-            SenderValidation::Enforce,
+            sender_validation,
         )
         .await;
 
-    let needs_skip = match &result {
+    let needs_skip = sender_validation == SenderValidation::Enforce
+        && match &result {
         Err(e) => e
             .downcast_ref::<crate::state_manager::Error>()
             .is_some_and(|e| matches!(e, crate::state_manager::Error::SenderValidationFailed)),
         Ok((invoc_res, _)) => invoc_res
             .msg_rct
             .as_ref()
             .is_some_and(|rct| rct.exit_code() == fvm_shared4::error::ExitCode::SYS_SENDER_INVALID),
     };

Then pass SenderValidation::Skip at Line 1956 and SenderValidation::Enforce at Line 1893.

🤖 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 1988 - 2015, Update apply_message to
accept a SenderValidation parameter and use it for the initial
apply_on_state_with_gas call, while retaining the existing sender-validation
failure detection and retry with Skip when the initial policy is Enforce. Pass
SenderValidation::Skip from the resolved-policy error path in
eth_estimate_gas_skip_sender and SenderValidation::Enforce from the other
apply_message caller.
🤖 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.

Inline comments:
In `@src/rpc/methods/eth.rs`:
- Around line 1927-1934: Update resolve_sender_validation and
estimate_call_with_gas so sender validation uses the same tipset as execution:
either pass the execution tipset from data.mpool.current_tipset() into
resolve_sender_validation, or change execution to use the requested tipset.
Preserve the existing actor-based SenderValidation decisions once both paths
share the same state.

In `@src/tool/subcommands/api_cmd/api_compare_tests.rs`:
- Around line 1651-1669: Update the EthCall and EthEstimateGas cases in the
ApiPaths loop to use strict success assertions instead of
PolicyOnRejected::PassWithIdenticalError, and set msg calldata to a known
non-reverting contract method rather than relying on empty-calldata fallback
behavior. Keep the existing request construction and API-path coverage intact.

---

Outside diff comments:
In `@src/rpc/methods/eth.rs`:
- Around line 2109-2124: Prevent zero gas limits from stalling gas search and
reject the missing-receipt sentinel. In gas_search, ensure the growth loop
always advances when high is zero while preserving the BLOCK_GAS_LIMIT cap; in
eth_estimate_gas_skip_sender, detect the -1 result from
GasEstimateGasLimit::estimate_gas_limit before scaling or calling
msg.set_gas_limit, and return the existing appropriate error path instead.

---

Nitpick comments:
In `@src/rpc/methods/eth.rs`:
- Around line 1988-2015: Update apply_message to accept a SenderValidation
parameter and use it for the initial apply_on_state_with_gas call, while
retaining the existing sender-validation failure detection and retry with Skip
when the initial policy is Enforce. Pass SenderValidation::Skip from the
resolved-policy error path in eth_estimate_gas_skip_sender and
SenderValidation::Enforce from the other apply_message caller.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3ee698fe-9220-4a0c-b643-5281dbb964e6

📥 Commits

Reviewing files that changed from the base of the PR and between 81f6cba and 268ed8d.

📒 Files selected for processing (5)
  • src/rpc/methods/eth.rs
  • src/rpc/methods/gas.rs
  • src/state_manager/errors.rs
  • src/state_manager/message_simulation.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)

Comment thread src/rpc/methods/eth.rs
Comment thread src/tool/subcommands/api_cmd/api_compare_tests.rs
@sudo-shashank sudo-shashank added the Wallet Trigger wallet test on Calibnet label Aug 3, 2026

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/tests/api_compare/.env (1)

3-3: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pin the Lotus baseline consistently across all test environments.

All three files now use the mutable v1.36.2-calibnet tag. Docker tags can be retargeted, which can change parity and benchmark results without a source change. Use one verified immutable digest across all three files. (docs.docker.com)

  • scripts/tests/api_compare/.env#L3-L3: replace the tag with the pinned digest.
  • scripts/tests/bootstrapper/.env#L2-L2: use the same pinned digest.
  • scripts/tests/snapshot_parity/.env#L1-L1: use the same pinned digest.

Verify that the selected digest is the intended Lotus baseline for PR #13724.

🤖 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 `@scripts/tests/api_compare/.env` at line 3, Replace the mutable Lotus image
tag with the verified immutable digest for the intended PR `#13724` baseline in
scripts/tests/api_compare/.env:3-3, scripts/tests/bootstrapper/.env:2-2, and
scripts/tests/snapshot_parity/.env:1-1, using exactly the same digest in all
three files.
🤖 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.

Inline comments:
In `@CHANGELOG.md`:
- Around line 44-45: Update the changelog entry’s linked reference from pull
request `#7435` to issue `#7394`, preserving the existing description and
formatting.

---

Nitpick comments:
In `@scripts/tests/api_compare/.env`:
- Line 3: Replace the mutable Lotus image tag with the verified immutable digest
for the intended PR `#13724` baseline in scripts/tests/api_compare/.env:3-3,
scripts/tests/bootstrapper/.env:2-2, and scripts/tests/snapshot_parity/.env:1-1,
using exactly the same digest in all three files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0b2dff37-88ec-40c4-8e44-351eec8ca545

📥 Commits

Reviewing files that changed from the base of the PR and between 268ed8d and 34090e9.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • scripts/tests/api_compare/.env
  • scripts/tests/bootstrapper/.env
  • scripts/tests/snapshot_parity/.env
  • src/rpc/methods/eth.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.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 (2)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/rpc/methods/eth.rs

Comment thread CHANGELOG.md
@sudo-shashank
sudo-shashank marked this pull request as ready for review August 3, 2026 21:30
@sudo-shashank
sudo-shashank requested a review from a team as a code owner August 3, 2026 21:30
@sudo-shashank
sudo-shashank requested review from EclesioMeloJunior and hanabi1224 and removed request for a team August 3, 2026 21:30
@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.40331% with 59 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.19%. Comparing base (9c30523) to head (fa5325c).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 63.10% 33 Missing and 5 partials ⚠️
src/state_manager/message_simulation.rs 73.33% 6 Missing and 6 partials ⚠️
src/rpc/methods/gas.rs 72.72% 6 Missing and 3 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/state_manager/errors.rs 40.00% <ø> (ø)
src/rpc/methods/gas.rs 86.96% <72.72%> (+0.20%) ⬆️
src/state_manager/message_simulation.rs 78.99% <73.33%> (+0.49%) ⬆️
src/rpc/methods/eth.rs 69.35% <63.10%> (+0.75%) ⬆️

... and 12 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 9c30523...fa5325c. 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.

@sudo-shashank
sudo-shashank marked this pull request as draft August 4, 2026 06:50
@sudo-shashank
sudo-shashank marked this pull request as ready for review August 4, 2026 08:02
@sudo-shashank
sudo-shashank marked this pull request as draft August 5, 2026 09:29

@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.

🧹 Nitpick comments (2)
scripts/devnet/.env (1)

10-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Restore dotenv key order.

Move FOREST_P2P_PORT before FOREST_RPC_PORT. dotenv-linter reports UnorderedKey at Line 10.

🤖 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 `@scripts/devnet/.env` at line 10, Reorder the environment keys in the dotenv
configuration so FOREST_P2P_PORT appears before FOREST_RPC_PORT, preserving
their existing values.

Source: Linters/SAST tools

src/tool/subcommands/api_cmd/api_compare_tests.rs (1)

1651-1782: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add context to fallible test setup.

Import anyhow::Context and add .context(...) to the fallible address, calldata, initcode, and request-construction operations in these helpers. Include the affected test case or API method in each message.

🤖 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/tool/subcommands/api_cmd/api_compare_tests.rs` around lines 1651 - 1782,
Add anyhow::Context and annotate fallible setup operations in
eth_skip_sender_success_tests, eth_skip_sender_insufficient_funds_tests,
eth_skip_sender_create_reject_tests, and eth_skip_sender_block_param_tests with
contextual errors identifying the relevant test case or API method. Apply
context to address, calldata/initcode parsing, and EthCall/EthEstimateGas
request construction, including failures propagated through
eth_skip_sender_cases.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@scripts/devnet/.env`:
- Line 10: Reorder the environment keys in the dotenv configuration so
FOREST_P2P_PORT appears before FOREST_RPC_PORT, preserving their existing
values.

In `@src/tool/subcommands/api_cmd/api_compare_tests.rs`:
- Around line 1651-1782: Add anyhow::Context and annotate fallible setup
operations in eth_skip_sender_success_tests,
eth_skip_sender_insufficient_funds_tests, eth_skip_sender_create_reject_tests,
and eth_skip_sender_block_param_tests with contextual errors identifying the
relevant test case or API method. Apply context to address, calldata/initcode
parsing, and EthCall/EthEstimateGas request construction, including failures
propagated through eth_skip_sender_cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e5ed9cfb-df83-4111-8be2-8c41afd0b8df

📥 Commits

Reviewing files that changed from the base of the PR and between f606af7 and fa5325c.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • scripts/devnet/.env
  • src/rpc/methods/eth.rs
  • src/rpc/methods/gas.rs
  • src/state_manager/message_simulation.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt
🔗 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 (4)
  • CHANGELOG.md
  • src/rpc/methods/eth.rs
  • src/state_manager/message_simulation.rs
  • src/rpc/methods/gas.rs

@sudo-shashank
sudo-shashank marked this pull request as ready for review August 7, 2026 03:48

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. What's the grand total size of all new snapshots?
  2. What are those snapshots doing? Is each one of them testing something distinct or is there some overlap?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. Each file size is ~5 Mb so the total size of all the new snapshots is around 120 Mb.
  2. Yes, distinct test cases but the same set is executed for both v1 and v2 api paths. I'll add some tags to each file for better clarity.

@LesnyRumcajs LesnyRumcajs Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are v1/v2 paths any different in practice for these methods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, i'll keep one set and remove other

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 Wallet Trigger wallet test on Calibnet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow eth_call and eth_estimateGas from contract and non-existent senders

2 participants