Skip to content

fix(evm): load delegation code during balance check in CallCode#1277

Merged
Thegaram merged 1 commit into
developfrom
fix-load-delegated-account-during-balance-check
Mar 10, 2026
Merged

fix(evm): load delegation code during balance check in CallCode#1277
Thegaram merged 1 commit into
developfrom
fix-load-delegated-account-during-balance-check

Conversation

@Thegaram
Copy link
Copy Markdown

@Thegaram Thegaram commented Mar 9, 2026

1. Purpose or design rationale of this PR

Make sure delegated code is loaded, even if CallCode fails with balance insufficient error (same as in #1270). This ensures that revm can process the produced execution witness.

2. PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • fix: A bug fix

3. Deployment tag versioning

Has the version in params/version.go been updated?

  • This PR doesn't involve a new deployment, git tag, docker image tag, and it doesn't affect traces
  • Yes

4. Breaking change label

Does this PR have the breaking-change label?

  • This PR is not a breaking change
  • Yes

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency in delegated code handling during balance validation scenarios.
  • Chores

    • Updated patch version.

@Thegaram Thegaram requested review from georgehao and noel2004 March 9, 2026 14:37
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

CallCode now loads delegated code into the witness when balance checks fail, mirroring Call behavior for consistency. Version patch constant incremented from 4 to 5, updating derived version strings accordingly.

Changes

Cohort / File(s) Summary
CallCode Witness Loading
core/vm/evm.go
Loads delegated code into witness before returning ErrInsufficientBalance in CallCode, ensuring consistent behavior with Call when balance check fails.
Version Bump
params/version.go
Increments VersionPatch constant from 4 to 5; affects all derived version strings (VersionWithMeta, ArchiveVersion, VersionWithCommit).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit hops through witness gates,
Where delegated code now waits,
Balance checks and versions rise,
Consistency blooms, to our surprise! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: loading delegation code during balance checks in CallCode, which matches the primary modification in the changeset.
Description check ✅ Passed The pull request description follows the required template with all mandatory sections completed: purpose/rationale explained, conventional commits format confirmed, version update acknowledged, and breaking change status clarified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-load-delegated-account-during-balance-check

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 OpenGrep (1.16.2)
core/vm/evm.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m

params/version.go

┌──────────────┐
│ Opengrep CLI │
└──────────────┘

�[32m✔�[39m �[1mOpengrep OSS�[0m
�[32m✔�[39m Basic security coverage for first-party code vulnerabilities.

�[1m Loading rules from local config...�[0m


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
core/vm/evm.go (1)

292-298: Extract the delegation witness warm-up into a helper.

This GetCode(addr) -> ParseDelegation(code) -> GetCode(target) sequence now exists in both the Call and CallCode insufficient-balance branches. Pulling it behind one helper would keep the two paths from drifting again the next time the EIP-7702 witness behavior changes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/vm/evm.go` around lines 292 - 298, Extract the delegation witness
warm-up logic into a single helper to avoid duplication: create a function
(e.g., ensureDelegationWitness or warmDelegationForAddr) that accepts the
StateDB and an address, performs evm.StateDB.GetCode(addr), calls
types.ParseDelegation(code) and if ParseDelegation returns (target, true) calls
evm.StateDB.GetCode(target); then replace the duplicated sequences in the
insufficient-balance branches inside Call and CallCode with a call to this
helper (passing the same evm.StateDB and addr) so both paths share the same
implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@core/vm/evm.go`:
- Around line 292-298: Extract the delegation witness warm-up logic into a
single helper to avoid duplication: create a function (e.g.,
ensureDelegationWitness or warmDelegationForAddr) that accepts the StateDB and
an address, performs evm.StateDB.GetCode(addr), calls
types.ParseDelegation(code) and if ParseDelegation returns (target, true) calls
evm.StateDB.GetCode(target); then replace the duplicated sequences in the
insufficient-balance branches inside Call and CallCode with a call to this
helper (passing the same evm.StateDB and addr) so both paths share the same
implementation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aca6748e-9e93-4408-bd7a-c9ab76dae168

📥 Commits

Reviewing files that changed from the base of the PR and between 7363921 and b0b743a.

📒 Files selected for processing (2)
  • core/vm/evm.go
  • params/version.go

@Thegaram Thegaram merged commit 7354a17 into develop Mar 10, 2026
14 checks passed
@Thegaram Thegaram deleted the fix-load-delegated-account-during-balance-check branch March 10, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants