Skip to content

Commit

Permalink
CR's fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniy-scherbina committed Apr 26, 2024
1 parent 4dbf483 commit 91a9a53
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,29 @@ func (evm *EVM) precompile(addr common.Address) (contract.StatefulPrecompiledCon
precompiles = PrecompiledContractsHomestead
}

// Check the existing precompiles first
// Check the native stateless precompiles first
p, ok := precompiles[addr]
if ok {
return p, true
}

// Otherwise, check for the additionally configured precompiles.
module, ok := modules.GetPrecompileModuleByAddress(addr)
if !ok {
// Otherwise, check for the additionally configured stateful precompiles
if !evm.isStatefulPrecompileEnabled(addr) {
return nil, false
}
// Precompile is registered, check if it's enabled at this block height
if !slices.Contains(evm.enabledPrecompiles, addr) {
module, ok := modules.GetPrecompileModuleByAddress(addr)
if !ok {
return nil, false
}

return module.Contract, true
}

// isStatefulPrecompileEnabled checks if stateful precompile is enabled at current block height
func (evm *EVM) isStatefulPrecompileEnabled(addr common.Address) bool {
return slices.Contains(evm.enabledPrecompiles, addr)
}

// BlockContext provides the EVM with auxiliary information. Once provided
// it shouldn't be modified.
type BlockContext struct {
Expand Down

0 comments on commit 91a9a53

Please sign in to comment.