Skip to content

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

Draft
sudo-shashank wants to merge 6 commits into
mainfrom
shashank/port-eth-changes
Draft

fix(eth): allow eth_call and eth_estimateGas from contract and non-existent senders#7435
sudo-shashank wants to merge 6 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

  • New Features

    • eth_call and eth_estimateGas now support EVM contract addresses and nonexistent accounts as senders.
    • Gas estimation handles sender validation more reliably while preserving execution errors and applying appropriate limits.
    • Trace calls continue to enforce sender validation where required.
  • Bug Fixes

    • Improved compatibility with Lotus and Geth sender-handling behavior.
  • Tests

    • Added parity coverage for valid and random sender addresses across API versions.
  • Documentation

    • Updated the changelog with the sender-support improvements.

@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 (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
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.
Linked Issues check ❓ Inconclusive The implementation and parity tests address sender validation for eth_call and eth_estimateGas, but no benchmark evidence confirms the Lotus performance criterion [#7394]. Add or link benchmark results that compare Forest with Lotus and confirm that performance is at least equivalent out of the box.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The changelog, parity tests, and Lotus image updates support the sender-validation implementation and the linked issue objectives.
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 30.93923% with 125 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.04%. Comparing base (81f6cba) to head (f606af7).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 13.59% 88 Missing and 1 partial ⚠️
src/state_manager/message_simulation.rs 42.22% 24 Missing and 2 partials ⚠️
src/rpc/methods/gas.rs 69.69% 7 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 85.48% <69.69%> (-1.11%) ⬇️
src/state_manager/message_simulation.rs 73.06% <42.22%> (-6.17%) ⬇️
src/rpc/methods/eth.rs 66.64% <13.59%> (-1.80%) ⬇️

... 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 81f6cba...f606af7. 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
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

1 participant