mirror of
https://github.com/luxfi/evm.git
synced 2026-09-24 00:27:44 +00:00
Updates dependencies: - github.com/luxfi/vm v1.0.22 → v1.0.23 (adds ZAP transport Serve) - github.com/luxfi/log v1.3.0 → v1.4.1 (fixes module path declaration) - github.com/luxfi/consensus v1.22.53 → v1.22.56 - github.com/luxfi/crypto v1.17.39 → v1.17.40 - github.com/luxfi/database v1.17.38 → v1.17.39 - github.com/luxfi/geth v1.16.69 → v1.16.73 - github.com/luxfi/p2p v1.18.7 → v1.18.8 - github.com/luxfi/warp v1.18.4 → v1.18.5 The vm package now provides a ZAP-based Serve function by default, eliminating the need for the grpc build tag for VM plugins. Also includes various improvements to validators, warp service, and precompile interfaces.
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Defines the interface for the configuration and execution of a precompile contract
|
|
package contract
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
|
|
"github.com/holiman/uint256"
|
|
"github.com/luxfi/evm/precompile/precompileconfig"
|
|
"github.com/luxfi/geth/common"
|
|
ethtypes "github.com/luxfi/geth/core/types"
|
|
)
|
|
|
|
// StatefulPrecompiledContract is the interface for executing a precompiled contract
|
|
type StatefulPrecompiledContract interface {
|
|
// Run executes the precompiled contract.
|
|
Run(accessibleState AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error)
|
|
}
|
|
|
|
type StateReader interface {
|
|
GetState(common.Address, common.Hash) common.Hash
|
|
}
|
|
|
|
// StateDB is the interface for accessing EVM state
|
|
type StateDB interface {
|
|
StateReader
|
|
SetState(common.Address, common.Hash, common.Hash)
|
|
|
|
SetNonce(common.Address, uint64)
|
|
GetNonce(common.Address) uint64
|
|
|
|
GetBalance(common.Address) *uint256.Int
|
|
AddBalance(common.Address, *uint256.Int)
|
|
|
|
CreateAccount(common.Address)
|
|
Exist(common.Address) bool
|
|
|
|
AddLog(*ethtypes.Log)
|
|
GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool)
|
|
|
|
GetTxHash() common.Hash
|
|
|
|
Snapshot() int
|
|
RevertToSnapshot(int)
|
|
}
|
|
|
|
// AccessibleState defines the interface exposed to stateful precompile contracts
|
|
type AccessibleState interface {
|
|
GetStateDB() StateDB
|
|
GetBlockContext() BlockContext
|
|
GetConsensusContext() context.Context
|
|
GetChainConfig() precompileconfig.ChainConfig
|
|
}
|
|
|
|
// ConfigurationBlockContext defines the interface required to configure a precompile.
|
|
type ConfigurationBlockContext interface {
|
|
Number() *big.Int
|
|
Timestamp() uint64
|
|
}
|
|
|
|
type BlockContext interface {
|
|
ConfigurationBlockContext
|
|
// GetPredicateResults returns the result of verifying the predicates of the
|
|
// given transaction, precompile address pair as a byte array.
|
|
GetPredicateResults(txHash common.Hash, precompileAddress common.Address) []byte
|
|
}
|
|
|
|
type Configurator interface {
|
|
// MakeConfig returns a new empty precompile config instance.
|
|
// This is required to Marshal/Unmarshal the precompile config.
|
|
MakeConfig() precompileconfig.Config
|
|
// MakeGenesisConfig returns a precompile config for genesis activation (timestamp = 0).
|
|
// This is used by AllGenesisPrecompiles() to enumerate all precompiles with default configs.
|
|
MakeGenesisConfig() precompileconfig.Config
|
|
// Configure is called when the precompile is activated.
|
|
Configure(
|
|
chainConfig precompileconfig.ChainConfig,
|
|
precompileconfig precompileconfig.Config,
|
|
state StateDB,
|
|
blockContext ConfigurationBlockContext,
|
|
) error
|
|
}
|