mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
core/vm: rename to JumpDestCache
This commit is contained in:
parent
fd6d6d7fb3
commit
2f96b90846
3 changed files with 9 additions and 15 deletions
|
|
@ -31,7 +31,7 @@ type Contract struct {
|
||||||
caller common.Address
|
caller common.Address
|
||||||
address common.Address
|
address common.Address
|
||||||
|
|
||||||
jumpDests JumpDests // Aggregated result of JUMPDEST analysis.
|
jumpDests JumpDestCache // Aggregated result of JUMPDEST analysis.
|
||||||
analysis BitVec // Locally cached result of JUMPDEST analysis
|
analysis BitVec // Locally cached result of JUMPDEST analysis
|
||||||
|
|
||||||
Code []byte
|
Code []byte
|
||||||
|
|
@ -47,7 +47,7 @@ type Contract struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContract returns a new contract environment for the execution of EVM.
|
// 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
|
// Initialize the jump analysis cache if it's nil, mostly for tests
|
||||||
if jumpDests == nil {
|
if jumpDests == nil {
|
||||||
jumpDests = newMapJumpDests()
|
jumpDests = newMapJumpDests()
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ type EVM struct {
|
||||||
precompiles map[common.Address]PrecompiledContract
|
precompiles map[common.Address]PrecompiledContract
|
||||||
|
|
||||||
// jumpDests stores results of JUMPDEST analysis.
|
// jumpDests stores results of JUMPDEST analysis.
|
||||||
jumpDests JumpDests
|
jumpDests JumpDestCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEVM constructs an EVM instance with the supplied block context, state
|
// NewEVM constructs an EVM instance with the supplied block context, state
|
||||||
|
|
@ -151,10 +151,8 @@ func (evm *EVM) SetPrecompiles(precompiles PrecompiledContracts) {
|
||||||
evm.precompiles = precompiles
|
evm.precompiles = precompiles
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetJumpDests sets a custom JumpDests implementation for the EVM.
|
// SetJumpDestCache configures the analysis cache.
|
||||||
// This allows for flexible caching strategies, including global caches
|
func (evm *EVM) SetJumpDestCache(jumpDests JumpDestCache) {
|
||||||
// that can be shared across multiple EVM instances.
|
|
||||||
func (evm *EVM) SetJumpDests(jumpDests JumpDests) {
|
|
||||||
evm.jumpDests = jumpDests
|
evm.jumpDests = jumpDests
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,8 @@ package vm
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/common"
|
import "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
// JumpDests is an interface for managing the jumpdest analysis cache.
|
// JumpDestCache represents the cache of jumpdest analysis results.
|
||||||
// It provides methods to store and retrieve the results of JUMPDEST analysis
|
type JumpDestCache interface {
|
||||||
// for contract bytecode, which is used to determine valid jump destinations.
|
|
||||||
type JumpDests interface {
|
|
||||||
// Load retrieves the cached jumpdest analysis for the given code hash.
|
// 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.
|
// Returns the BitVec and true if found, or nil and false if not cached.
|
||||||
Load(codeHash common.Hash) (BitVec, bool)
|
Load(codeHash common.Hash) (BitVec, bool)
|
||||||
|
|
@ -35,17 +33,15 @@ type JumpDests interface {
|
||||||
type mapJumpDests map[common.Hash]BitVec
|
type mapJumpDests map[common.Hash]BitVec
|
||||||
|
|
||||||
// newMapJumpDests creates a new map-based JumpDests implementation.
|
// newMapJumpDests creates a new map-based JumpDests implementation.
|
||||||
func newMapJumpDests() JumpDests {
|
func newMapJumpDests() JumpDestCache {
|
||||||
return make(mapJumpDests)
|
return make(mapJumpDests)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load retrieves the cached jumpdest analysis for the given code hash.
|
|
||||||
func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) {
|
func (j mapJumpDests) Load(codeHash common.Hash) (BitVec, bool) {
|
||||||
vec, ok := j[codeHash]
|
vec, ok := j[codeHash]
|
||||||
return vec, ok
|
return vec, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store saves the jumpdest analysis for the given code hash.
|
|
||||||
func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) {
|
func (j mapJumpDests) Store(codeHash common.Hash, vec BitVec) {
|
||||||
j[codeHash] = vec
|
j[codeHash] = vec
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue