Skip to content

feat(core/vm): add configurable jumpdest analysis cache #32143#2321

Open
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-issue-32137
Open

feat(core/vm): add configurable jumpdest analysis cache #32143#2321
gzliudan wants to merge 1 commit intoXinFinOrg:dev-upgradefrom
gzliudan:fix-issue-32137

Conversation

@gzliudan
Copy link
Copy Markdown
Collaborator

Proposed changes

Ref: ethereum#32143

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Changes that don't change source code or tests
  • docs: Documentation only changes
  • feat: A new feature
  • fix: A bug fix
  • perf: A code change that improves performance
  • refactor: A code change that neither fixes a bug nor adds a feature
  • revert: Revert something
  • style: Changes that do not affect the meaning of the code
  • test: Adding missing tests or correcting existing tests

Impacted Components

Which parts of the codebase does this PR touch?
Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Tested on a private network from the genesis block and monitored the chain operating correctly for multiple epochs.
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Copilot AI review requested due to automatic review settings April 20, 2026 10:08
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dba6ab8e-109d-453c-b899-9ee5c07ae299

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a configurable cache abstraction for EVM JUMPDEST analysis results so callers can plug in alternative caching strategies.

Changes:

  • Introduces a JumpDestCache interface plus a default per-EVM map-backed implementation.
  • Wires the cache through EVM and Contract (including a new SetJumpDestCache setter).
  • Renames internal bitvec type to exported BitVec and updates benchmarks accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
core/vm/jumpdests.go Adds JumpDestCache interface and default map-backed implementation.
core/vm/evm.go Stores jumpdest cache behind the interface and adds SetJumpDestCache.
core/vm/contract.go Uses JumpDestCache for jumpdest lookups/stores during execution.
core/vm/analysis_legacy.go Exports BitVec type and updates bitmap helpers’ signatures.
core/vm/analysis_legacy_test.go Updates benchmark to use BitVec.
Comments suppressed due to low confidence (1)

core/vm/analysis_legacy.go:75

  • codeBitmapInternal now takes code as BitVec, but all call sites pass a []byte (e.g. codeBitmap(code []byte) and the benchmark). This will not compile because []byte is not assignable to the named slice type BitVec without conversion. Change the first parameter back to []byte (or explicitly convert at the call sites) so the function remains usable from codeBitmap and tests/benchmarks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/vm/evm.go
}

// SetJumpDestCache configures the analysis cache.
func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) {
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

SetJumpDestCache allows setting evm.jumpDests to nil. If a caller accidentally passes nil, subsequent NewContract(..., evm.jumpDests) calls will fall back to creating a fresh map-based cache per contract (via NewContract's nil check) instead of sharing one cache per EVM instance, which is a surprising semantic change and can increase allocations. Consider treating nil as “reset to default” (e.g. set to newMapJumpDests()), or explicitly document/rename if nil is intended to disable shared caching.

Suggested change
func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) {
func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) {
if jumpDests == nil {
evm.jumpDests = newMapJumpDests()
return
}

Copilot uses AI. Check for mistakes.
Comment thread core/vm/jumpdests.go
Comment on lines +33 to +37
// mapJumpDests is the default implementation of JumpDests using a map.
// This implementation is not thread-safe and is meant to be used per EVM instance.
type mapJumpDests map[common.Hash]BitVec

// newMapJumpDests creates a new map-based JumpDests implementation.
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The comments refer to “JumpDests” even though the introduced type is JumpDestCache (e.g. “default implementation of JumpDests” / “new map-based JumpDests implementation”). Please align the wording with JumpDestCache to avoid confusion for future readers.

Suggested change
// mapJumpDests is the default implementation of JumpDests using a map.
// This implementation is not thread-safe and is meant to be used per EVM instance.
type mapJumpDests map[common.Hash]BitVec
// newMapJumpDests creates a new map-based JumpDests implementation.
// mapJumpDests is the default implementation of JumpDestCache using a map.
// This implementation is not thread-safe and is meant to be used per EVM instance.
type mapJumpDests map[common.Hash]BitVec
// newMapJumpDests creates a new map-based JumpDestCache implementation.

Copilot uses AI. Check for mistakes.
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.

5 participants