precompileconfig

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2023 License: GPL-3.0, LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Defines the stateless interface for unmarshalling an arbitrary config of a precompile

TODO: replace with gomock

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewNoopStatefulPrecompileConfig

func NewNoopStatefulPrecompileConfig() *noopStatefulPrecompileConfig

Types

type AcceptContext

type AcceptContext struct {
	SnowCtx      *snow.Context
	SharedMemory SharedMemoryWriter
	Warp         WarpMessageWriter
}

AcceptContext defines the context passed in to a precompileconfig's Accepter

type Accepter

type Accepter interface {
	Accept(acceptCtx *AcceptContext, txHash common.Hash, logIndex int, topics []common.Hash, logData []byte) error
}

Accepter is an optional interface for StatefulPrecompiledContracts to implement. If implemented, Accept will be called for every log with the address of the precompile when the block is accepted. WARNING: If you are implementing a custom precompile, beware that subnet-evm will not maintain backwards compatibility of this interface and your code should not rely on this. Designed for use only by precompiles that ship with subnet-evm.

type Config

type Config interface {
	// Key returns the unique key for the stateful precompile.
	Key() string
	// Timestamp returns the timestamp at which this stateful precompile should be enabled.
	// 1) 0 indicates that the precompile should be enabled from genesis.
	// 2) n indicates that the precompile should be enabled in the first block with timestamp >= [n].
	// 3) nil indicates that the precompile is never enabled.
	Timestamp() *big.Int
	// IsDisabled returns true if this network upgrade should disable the precompile.
	IsDisabled() bool
	// Equal returns true if the provided argument configures the same precompile with the same parameters.
	Equal(Config) bool
	// Verify is called on startup and an error is treated as fatal. Configure can assume the Config has passed verification.
	Verify() error
}

StatefulPrecompileConfig defines the interface for a stateful precompile to be enabled via a network upgrade.

type PrecompilePredicateContext

type PrecompilePredicateContext struct {
	SnowCtx *snow.Context
}

PrecompilePredicateContext is the context passed in to the PrecompilePredicater interface.

type PrecompilePredicater

type PrecompilePredicater interface {
	PredicateGas(storageSlots []byte) (uint64, error)
	VerifyPredicate(predicateContext *PrecompilePredicateContext, storageSlots []byte) error
}

PrecompilePredicater is an optional interface for StatefulPrecompileContracts to implement. If implemented, the predicate will be enforced on every transaction in a block, prior to the block's execution. If VerifyPredicate returns an error, the block will fail verification with no further processing. WARNING: If you are implementing a custom precompile, beware that subnet-evm will not maintain backwards compatibility of this interface and your code should not rely on this. Designed for use only by precompiles that ship with subnet-evm.

type ProposerPredicateContext

type ProposerPredicateContext struct {
	PrecompilePredicateContext
	// ProposerVMBlockCtx defines the ProposerVM context the predicate is verified within
	ProposerVMBlockCtx *block.Context
}

ProposerPredicateContext is the context passed in to the ProposerPredicater interface to verify a precompile predicate within a specific ProposerVM wrapper.

type ProposerPredicater

type ProposerPredicater interface {
	PredicateGas(storageSlots []byte) (uint64, error)
	VerifyPredicate(proposerPredicateContext *ProposerPredicateContext, storageSlots []byte) error
}

ProposerPredicater is an optional interface for StatefulPrecompiledContracts to implement. If implemented, the predicate will be enforced on every transaction in a block, prior to the block's execution. If VerifyPredicate returns an error, the block will fail verification with no further processing. Note: ProposerVMBlockCtx is guaranteed to be non-nil. Precompiles should use ProposerPredicater instead of PrecompilePredicater iff their execution depends on the ProposerVM Block Context. WARNING: If you are implementing a custom precompile, beware that subnet-evm will not maintain backwards compatibility of this interface and your code should not rely on this. Designed for use only by precompiles that ship with subnet-evm.

type SharedMemoryWriter

type SharedMemoryWriter interface {
	AddSharedMemoryRequests(chainID ids.ID, requests *atomic.Requests)
}

SharedMemoryWriter defines an interface to allow a precompile's Accepter to write operations into shared memory to be committed atomically on block accept.

type Upgrade

type Upgrade struct {
	BlockTimestamp *big.Int `json:"blockTimestamp"`
	Disable        bool     `json:"disable,omitempty"`
}

Upgrade contains the timestamp for the upgrade along with a boolean [Disable]. If [Disable] is set, the upgrade deactivates the precompile and clears its storage.

func (*Upgrade) Equal

func (u *Upgrade) Equal(other *Upgrade) bool

Equal returns true iff [other] has the same blockTimestamp and has the same on value for the Disable flag.

func (*Upgrade) IsDisabled

func (u *Upgrade) IsDisabled() bool

IsDisabled returns true if the network upgrade deactivates the precompile.

func (*Upgrade) Timestamp

func (u *Upgrade) Timestamp() *big.Int

Timestamp returns the timestamp this network upgrade goes into effect.

type WarpMessageWriter

type WarpMessageWriter interface {
	AddMessage(unsignedMessage *warp.UnsignedMessage) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL