Documentation
¶
Overview ¶
Defines the interface for the configuration and execution of a precompile contract
Index ¶
- Constants
- func CalculateFunctionSelector(functionSignature string) []byte
- func DeductGas(suppliedGas uint64, requiredGas uint64) (uint64, error)
- func NewMockAccessibleState(state StateDB, blockContext *mockBlockContext, snowContext *snow.Context) *mockAccessibleState
- func NewMockBlockContext(blockNumber *big.Int, timestamp uint64) *mockBlockContext
- func NewMockChainState(feeConfig commontype.FeeConfig, allowedFeeRecipients bool) *mockChainState
- func PackOrderedHashes(dst []byte, hashes []common.Hash) error
- func PackOrderedHashesWithSelector(dst []byte, functionSelector []byte, hashes []common.Hash) error
- func PackedHash(packed []byte, index int) []byte
- func ParseABI(rawABI string) abi.ABI
- type AccessibleState
- type BlockContext
- type ChainConfig
- type Configurator
- type RunStatefulPrecompileFunc
- type StateDB
- type StatefulPrecompileFunction
- type StatefulPrecompiledContract
Constants ¶
const ( WriteGasCostPerSlot = 20_000 ReadGasCostPerSlot = 5_000 )
Gas costs for stateful precompiles
const (
SelectorLen = 4
)
Variables ¶
This section is empty.
Functions ¶
func CalculateFunctionSelector ¶
CalculateFunctionSelector returns the 4 byte function selector that results from [functionSignature] Ex. the function setBalance(addr address, balance uint256) should be passed in as the string: "setBalance(address,uint256)" TODO: remove this after moving to ABI based function selectors.
func DeductGas ¶
DeductGas checks if [suppliedGas] is sufficient against [requiredGas] and deducts [requiredGas] from [suppliedGas].
func NewMockAccessibleState ¶
func NewMockBlockContext ¶
func NewMockChainState ¶
func NewMockChainState(feeConfig commontype.FeeConfig, allowedFeeRecipients bool) *mockChainState
func PackOrderedHashes ¶
PackOrderedHashes packs the ordered list of [hashes] into the [dst] byte buffer. assumes that [dst] has sufficient space to pack [hashes] or else this function will panic.
func PackOrderedHashesWithSelector ¶
PackOrderedHashesWithSelector packs the function selector and ordered list of hashes into [dst] byte slice. assumes that [dst] has sufficient room for [functionSelector] and [hashes].
func PackedHash ¶
PackedHash returns packed the byte slice with common.HashLength from [packed] at the given [index]. Assumes that [packed] is composed entirely of packed 32 byte segments.
Types ¶
type AccessibleState ¶
type AccessibleState interface {
GetStateDB() StateDB
GetBlockContext() BlockContext
GetSnowContext() *snow.Context
CallFromPrecompile(caller common.Address, addr common.Address, input []byte, gas uint64, value *big.Int) (ret []byte, leftOverGas uint64, err error)
}
AccessibleState defines the interface exposed to stateful precompile contracts
type BlockContext ¶
BlockContext defines an interface that provides information to a stateful precompile about the block that activates the upgrade. The precompile can access this information to initialize its state.
type ChainConfig ¶
type ChainConfig interface {
// GetFeeConfig returns the original FeeConfig that was set in the genesis.
GetFeeConfig() commontype.FeeConfig
// AllowedFeeRecipients returns true if fee recipients are allowed in the genesis.
AllowedFeeRecipients() bool
}
ChainContext defines an interface that provides information to a stateful precompile about the chain configuration. The precompile can access this information to initialize its state.
type Configurator ¶
type Configurator interface {
MakeConfig() precompileconfig.Config
Configure(
chainConfig ChainConfig,
precompileconfig precompileconfig.Config,
state StateDB,
blockContext BlockContext,
) error
}
type StateDB ¶
type StateDB interface {
GetState(common.Address, common.Hash) common.Hash
SetState(common.Address, common.Hash, common.Hash)
SetNonce(common.Address, uint64)
GetNonce(common.Address) uint64
GetBalance(common.Address) *big.Int
AddBalance(common.Address, *big.Int)
CreateAccount(common.Address)
Exist(common.Address) bool
AddLog(addr common.Address, topics []common.Hash, data []byte, blockNumber uint64)
GetPredicateStorageSlots(address common.Address) ([]byte, bool)
Suicide(common.Address) bool
Finalise(deleteEmptyObjects bool)
Snapshot() int
RevertToSnapshot(int)
}
StateDB is the interface for accessing EVM state
type StatefulPrecompileFunction ¶
type StatefulPrecompileFunction struct {
// contains filtered or unexported fields
}
StatefulPrecompileFunction defines a function implemented by a stateful precompile
func NewStatefulPrecompileFunction ¶
func NewStatefulPrecompileFunction(selector []byte, execute RunStatefulPrecompileFunc) *StatefulPrecompileFunction
NewStatefulPrecompileFunction creates a stateful precompile function with the given arguments
type StatefulPrecompiledContract ¶
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)
}
StatefulPrecompiledContract is the interface for executing a precompiled contract
func NewStatefulPrecompileContract ¶
func NewStatefulPrecompileContract(fallback RunStatefulPrecompileFunc, functions []*StatefulPrecompileFunction) (StatefulPrecompiledContract, error)
NewStatefulPrecompileContract generates new StatefulPrecompile using [functions] as the available functions and [fallback] as an optional fallback if there is no input data. Note: the selector of [fallback] will be ignored, so it is required to be left empty.