From 2f96b908465a5700aa7cdd4c09b07e34376b8ddf Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 31 Jul 2025 17:40:10 +0200 Subject: [PATCH] core/vm: rename to JumpDestCache --- core/vm/contract.go | 6 +++--- core/vm/evm.go | 8 +++----- core/vm/jumpdests.go | 10 +++------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/core/vm/contract.go b/core/vm/contract.go index 6cc7d74df3..165ca833f8 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -31,8 +31,8 @@ type Contract struct { caller common.Address address common.Address - jumpDests JumpDests // Aggregated result of JUMPDEST analysis. - analysis BitVec // Locally cached result of JUMPDEST analysis + jumpDests JumpDestCache // Aggregated result of JUMPDEST analysis. + analysis BitVec // Locally cached result of JUMPDEST analysis Code []byte CodeHash common.Hash @@ -47,7 +47,7 @@ type Contract struct { } // NewContract returns a new contract environment for the execution of EVM. -func NewContract(caller common.Address, address common.Address, value *uint256.Int, gas uint64, jumpDests JumpDests) *Contract { +func NewContract(caller common.Address, address common.Address, value *uint256.Int, gas uint64, jumpDests JumpDestCache) *Contract { // Initialize the jump analysis cache if it's nil, mostly for tests if jumpDests == nil { jumpDests = newMapJumpDests() diff --git a/core/vm/evm.go b/core/vm/evm.go index cae2b47b98..143b7e08a2 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -123,7 +123,7 @@ type EVM struct { precompiles map[common.Address]PrecompiledContract // jumpDests stores results of JUMPDEST analysis. - jumpDests JumpDests + jumpDests JumpDestCache } // NewEVM constructs an EVM instance with the supplied block context, state @@ -151,10 +151,8 @@ func (evm *EVM) SetPrecompiles(precompiles PrecompiledContracts) { evm.precompiles = precompiles } -// SetJumpDests sets a custom JumpDests implementation for the EVM. -// This allows for flexible caching strategies, including global caches -// that can be shared across multiple EVM instances. -func (evm *EVM) SetJumpDests(jumpDests JumpDests) { +// SetJumpDestCache configures the analysis cache. +func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) { evm.jumpDests = jumpDests } diff --git a/core/vm/jumpdests.go b/core/vm/jumpdests.go index 9c228dade6..1a30c1943f 100644 --- a/core/vm/jumpdests.go +++ b/core/vm/jumpdests.go @@ -18,10 +18,8 @@ package vm import "github.com/ethereum/go-ethereum/common" -// JumpDests is an interface for managing the jumpdest analysis cache. -// It provides methods to store and retrieve the results of JUMPDEST analysis -// for contract bytecode, which is used to determine valid jump destinations. -type JumpDests interface { +// JumpDestCache represents the cache of jumpdest analysis results. +type JumpDestCache interface { // Load retrieves the cached jumpdest analysis for the given code hash. // Returns the BitVec and true if found, or nil and false if not cached. Load(codeHash common.Hash) (BitVec, bool) @@ -35,17 +33,15 @@ type JumpDests interface { type mapJumpDests map[common.Hash]BitVec // newMapJumpDests creates a new map-based JumpDests implementation. -func newMapJumpDests() JumpDests { +func newMapJumpDests() JumpDestCache { return make(mapJumpDests) } -// Load retrieves the cached jumpdest analysis for the given code hash. func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) { vec, ok := j[codeHash] return vec, ok } -// Store saves the jumpdest analysis for the given code hash. func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) { j[codeHash] = vec }