Files
zeekay acd2aaf533 feat: rename module to github.com/luxfi/precompile
BREAKING CHANGE: Module renamed from precompiles to precompile (singular)

- Remove lattice/v6 indirect dependency
- Exclude lattice/v6 versions to prevent transitive imports
- Only lattice/v7 is used now
2025-12-31 06:28:04 +00:00

93 lines
3.1 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/geth/common"
"github.com/luxfi/geth/core/tracing"
ethtypes "github.com/luxfi/geth/core/types"
"github.com/luxfi/precompile/precompileconfig"
)
// 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)
}
// StateDB is the interface for accessing EVM state
// This matches geth's vm.StateDB interface for compatibility
type StateDB interface {
GetState(common.Address, common.Hash) common.Hash
SetState(common.Address, common.Hash, common.Hash) common.Hash
SetNonce(common.Address, uint64, tracing.NonceChangeReason)
GetNonce(common.Address) uint64
GetBalance(common.Address) *uint256.Int
AddBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int
SubBalance(common.Address, *uint256.Int, tracing.BalanceChangeReason) uint256.Int
GetBalanceMultiCoin(common.Address, common.Hash) *big.Int
AddBalanceMultiCoin(common.Address, common.Hash, *big.Int)
SubBalanceMultiCoin(common.Address, common.Hash, *big.Int)
CreateAccount(common.Address)
Exist(common.Address) bool
AddLog(*ethtypes.Log)
Logs() []*ethtypes.Log
GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool)
TxHash() common.Hash
Snapshot() int
RevertToSnapshot(int)
}
// PrecompileEnvironment provides the execution environment for a precompile
// This interface is defined locally to avoid import cycles with geth/core/vm.
// It mirrors the key methods from geth's PrecompileEnvironment without creating
// a hard dependency.
type PrecompileEnvironment interface {
// ReadOnly returns whether the execution is read-only
ReadOnly() bool
}
// AccessibleState defines the interface exposed to stateful precompile contracts
type AccessibleState interface {
GetStateDB() StateDB
GetBlockContext() BlockContext
GetConsensusContext() context.Context
GetChainConfig() precompileconfig.ChainConfig
GetPrecompileEnv() PrecompileEnvironment
}
// 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() precompileconfig.Config
Configure(
chainConfig precompileconfig.ChainConfig,
precompileconfig precompileconfig.Config,
state StateDB,
blockContext ConfigurationBlockContext,
) error
}