Skip to content

Commit

Permalink
Merge pull request #242 from ethereum-optimism/inphi/kzg-oracle
Browse files Browse the repository at this point in the history
core/vm: Allow precompiles to be overriden
  • Loading branch information
Inphi authored Feb 12, 2024
2 parents 11a890f + e965f15 commit b6d0732
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
precompiles = PrecompiledContractsHomestead
}
p, ok := precompiles[addr]
// Restrict overrides to known precompiles
if ok && evm.chainConfig.IsOptimism() && evm.Config.OptimismPrecompileOverrides != nil {
override, ok := evm.Config.OptimismPrecompileOverrides(evm.chainRules, addr)
if ok {
return override, ok
}
}
return p, ok
}

Expand Down
13 changes: 9 additions & 4 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ import (
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
)

// PrecompileOverrides is a function that can be used to override the default precompiled contracts
type PrecompileOverrides func(params.Rules, common.Address) (PrecompiledContract, bool)

// Config are the configuration options for the Interpreter
type Config struct {
Tracer EVMLogger // Opcode logger
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled
Tracer EVMLogger // Opcode logger
NoBaseFee bool // Forces the EIP-1559 baseFee to 0 (needed for 0 price calls)
EnablePreimageRecording bool // Enables recording of SHA3/keccak preimages
ExtraEips []int // Additional EIPS that are to be enabled
OptimismPrecompileOverrides PrecompileOverrides // Precompile overrides for Optimism
}

// ScopeContext contains the things that are per-call, such as stack and memory,
Expand Down

0 comments on commit b6d0732

Please sign in to comment.