contract

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: GPL-3.0, LGPL-3.0 Imports: 13 Imported by: 1

Documentation

Overview

Defines the interface for the configuration and execution of a precompile contract

Package contract is a generated GoMock package.

Index

Constants

View Source
const (
	WriteGasCostPerSlot = 20_000
	ReadGasCostPerSlot  = 5_000

	// Per LOG operation.
	LogGas uint64 = 375 // from params/protocol_params.go
	// Gas cost of single topic of the LOG. Should be multiplied by the number of topics.
	LogTopicGas uint64 = 375 // from params/protocol_params.go
	// Per byte cost in a LOG operation's data. Should be multiplied by the byte size of the data.
	LogDataGas uint64 = 8 // from params/protocol_params.go
)

Gas costs for stateful precompiles

View Source
const (
	SelectorLen = 4
)

Variables

This section is empty.

Functions

func CalculateFunctionSelector

func CalculateFunctionSelector(functionSignature string) []byte

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

func DeductGas(suppliedGas uint64, requiredGas uint64) (uint64, error)

DeductGas checks if [suppliedGas] is sufficient against [requiredGas] and deducts [requiredGas] from [suppliedGas].

func IsDurangoActivated added in v0.5.11

func IsDurangoActivated(evm AccessibleState) bool

func PackOrderedHashes

func PackOrderedHashes(dst []byte, hashes []common.Hash) error

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. Kept for testing backwards compatibility.

func PackOrderedHashesWithSelector

func PackOrderedHashesWithSelector(dst []byte, functionSelector []byte, hashes []common.Hash) error

PackOrderedHashesWithSelector packs the function selector and ordered list of hashes into [dst] byte slice. assumes that [dst] has sufficient room for [functionSelector] and [hashes]. Kept for testing backwards compatibility.

func PackedHash

func PackedHash(packed []byte, index int) []byte

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. Kept for testing backwards compatibility.

func ParseABI

func ParseABI(rawABI string) abi.ABI

ParseABI parses the given ABI string and returns the parsed ABI. If the ABI is invalid, it panics.

Types

type AccessibleState

type AccessibleState interface {
	GetStateDB() StateDB
	GetBlockContext() BlockContext
	GetSnowContext() *snow.Context
	GetChainConfig() precompileconfig.ChainConfig
}

AccessibleState defines the interface exposed to stateful precompile contracts

type ActivationFunc added in v0.5.4

type ActivationFunc func(AccessibleState) bool

ActivationFunc defines a function that is used to determine if a function is active The return value is whether or not the function is active

type BlockContext

type BlockContext interface {
	ConfigurationBlockContext
	// GetResults returns an arbitrary byte array result of verifying the predicates
	// of the given transaction, precompile address pair.
	GetPredicateResults(txHash common.Hash, precompileAddress common.Address) []byte
}

type ConfigurationBlockContext added in v0.5.6

type ConfigurationBlockContext interface {
	Number() *big.Int
	Timestamp() uint64
}

ConfigurationBlockContext defines the interface required to configure a precompile.

type Configurator

type Configurator interface {
	MakeConfig() precompileconfig.Config
	Configure(
		chainConfig precompileconfig.ChainConfig,
		precompileconfig precompileconfig.Config,
		state StateDB,
		blockContext ConfigurationBlockContext,
	) error
}

type MockAccessibleState added in v0.5.4

type MockAccessibleState struct {
	// contains filtered or unexported fields
}

MockAccessibleState is a mock of AccessibleState interface.

func NewMockAccessibleState

func NewMockAccessibleState(ctrl *gomock.Controller) *MockAccessibleState

NewMockAccessibleState creates a new mock instance.

func (*MockAccessibleState) EXPECT added in v0.5.4

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockAccessibleState) GetBlockContext added in v0.5.4

func (m *MockAccessibleState) GetBlockContext() BlockContext

GetBlockContext mocks base method.

func (*MockAccessibleState) GetChainConfig added in v0.5.6

func (m *MockAccessibleState) GetChainConfig() precompileconfig.ChainConfig

GetChainConfig mocks base method.

func (*MockAccessibleState) GetSnowContext added in v0.5.4

func (m *MockAccessibleState) GetSnowContext() *snow.Context

GetSnowContext mocks base method.

func (*MockAccessibleState) GetStateDB added in v0.5.4

func (m *MockAccessibleState) GetStateDB() StateDB

GetStateDB mocks base method.

type MockAccessibleStateMockRecorder added in v0.5.4

type MockAccessibleStateMockRecorder struct {
	// contains filtered or unexported fields
}

MockAccessibleStateMockRecorder is the mock recorder for MockAccessibleState.

func (*MockAccessibleStateMockRecorder) GetBlockContext added in v0.5.4

func (mr *MockAccessibleStateMockRecorder) GetBlockContext() *gomock.Call

GetBlockContext indicates an expected call of GetBlockContext.

func (*MockAccessibleStateMockRecorder) GetChainConfig added in v0.5.6

func (mr *MockAccessibleStateMockRecorder) GetChainConfig() *gomock.Call

GetChainConfig indicates an expected call of GetChainConfig.

func (*MockAccessibleStateMockRecorder) GetSnowContext added in v0.5.4

func (mr *MockAccessibleStateMockRecorder) GetSnowContext() *gomock.Call

GetSnowContext indicates an expected call of GetSnowContext.

func (*MockAccessibleStateMockRecorder) GetStateDB added in v0.5.4

func (mr *MockAccessibleStateMockRecorder) GetStateDB() *gomock.Call

GetStateDB indicates an expected call of GetStateDB.

type MockBlockContext added in v0.5.4

type MockBlockContext struct {
	// contains filtered or unexported fields
}

MockBlockContext is a mock of BlockContext interface.

func NewMockBlockContext

func NewMockBlockContext(ctrl *gomock.Controller) *MockBlockContext

NewMockBlockContext creates a new mock instance.

func (*MockBlockContext) EXPECT added in v0.5.4

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBlockContext) GetPredicateResults added in v0.5.4

func (m *MockBlockContext) GetPredicateResults(arg0 common.Hash, arg1 common.Address) []byte

GetPredicateResults mocks base method.

func (*MockBlockContext) Number added in v0.5.4

func (m *MockBlockContext) Number() *big.Int

Number mocks base method.

func (*MockBlockContext) Timestamp added in v0.5.4

func (m *MockBlockContext) Timestamp() uint64

Timestamp mocks base method.

type MockBlockContextMockRecorder added in v0.5.4

type MockBlockContextMockRecorder struct {
	// contains filtered or unexported fields
}

MockBlockContextMockRecorder is the mock recorder for MockBlockContext.

func (*MockBlockContextMockRecorder) GetPredicateResults added in v0.5.4

func (mr *MockBlockContextMockRecorder) GetPredicateResults(arg0, arg1 any) *gomock.Call

GetPredicateResults indicates an expected call of GetPredicateResults.

func (*MockBlockContextMockRecorder) Number added in v0.5.4

Number indicates an expected call of Number.

func (*MockBlockContextMockRecorder) Timestamp added in v0.5.4

func (mr *MockBlockContextMockRecorder) Timestamp() *gomock.Call

Timestamp indicates an expected call of Timestamp.

type MockStateDB added in v0.6.0

type MockStateDB struct {
	// contains filtered or unexported fields
}

MockStateDB is a mock of StateDB interface.

func NewMockStateDB added in v0.6.0

func NewMockStateDB(ctrl *gomock.Controller) *MockStateDB

NewMockStateDB creates a new mock instance.

func (*MockStateDB) AddBalance added in v0.6.0

func (m *MockStateDB) AddBalance(arg0 common.Address, arg1 *uint256.Int)

AddBalance mocks base method.

func (*MockStateDB) AddLog added in v0.6.0

func (m *MockStateDB) AddLog(arg0 common.Address, arg1 []common.Hash, arg2 []byte, arg3 uint64)

AddLog mocks base method.

func (*MockStateDB) CreateAccount added in v0.6.0

func (m *MockStateDB) CreateAccount(arg0 common.Address)

CreateAccount mocks base method.

func (*MockStateDB) EXPECT added in v0.6.0

func (m *MockStateDB) EXPECT() *MockStateDBMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockStateDB) Exist added in v0.6.0

func (m *MockStateDB) Exist(arg0 common.Address) bool

Exist mocks base method.

func (*MockStateDB) GetBalance added in v0.6.0

func (m *MockStateDB) GetBalance(arg0 common.Address) *uint256.Int

GetBalance mocks base method.

func (*MockStateDB) GetLogData added in v0.6.0

func (m *MockStateDB) GetLogData() ([][]common.Hash, [][]byte)

GetLogData mocks base method.

func (*MockStateDB) GetNonce added in v0.6.0

func (m *MockStateDB) GetNonce(arg0 common.Address) uint64

GetNonce mocks base method.

func (*MockStateDB) GetPredicateStorageSlots added in v0.6.0

func (m *MockStateDB) GetPredicateStorageSlots(arg0 common.Address, arg1 int) ([]byte, bool)

GetPredicateStorageSlots mocks base method.

func (*MockStateDB) GetState added in v0.6.0

func (m *MockStateDB) GetState(arg0 common.Address, arg1 common.Hash) common.Hash

GetState mocks base method.

func (*MockStateDB) GetTxHash added in v0.6.0

func (m *MockStateDB) GetTxHash() common.Hash

GetTxHash mocks base method.

func (*MockStateDB) RevertToSnapshot added in v0.6.0

func (m *MockStateDB) RevertToSnapshot(arg0 int)

RevertToSnapshot mocks base method.

func (*MockStateDB) SetNonce added in v0.6.0

func (m *MockStateDB) SetNonce(arg0 common.Address, arg1 uint64)

SetNonce mocks base method.

func (*MockStateDB) SetPredicateStorageSlots added in v0.6.0

func (m *MockStateDB) SetPredicateStorageSlots(arg0 common.Address, arg1 [][]byte)

SetPredicateStorageSlots mocks base method.

func (*MockStateDB) SetState added in v0.6.0

func (m *MockStateDB) SetState(arg0 common.Address, arg1, arg2 common.Hash)

SetState mocks base method.

func (*MockStateDB) Snapshot added in v0.6.0

func (m *MockStateDB) Snapshot() int

Snapshot mocks base method.

type MockStateDBMockRecorder added in v0.6.0

type MockStateDBMockRecorder struct {
	// contains filtered or unexported fields
}

MockStateDBMockRecorder is the mock recorder for MockStateDB.

func (*MockStateDBMockRecorder) AddBalance added in v0.6.0

func (mr *MockStateDBMockRecorder) AddBalance(arg0, arg1 any) *gomock.Call

AddBalance indicates an expected call of AddBalance.

func (*MockStateDBMockRecorder) AddLog added in v0.6.0

func (mr *MockStateDBMockRecorder) AddLog(arg0, arg1, arg2, arg3 any) *gomock.Call

AddLog indicates an expected call of AddLog.

func (*MockStateDBMockRecorder) CreateAccount added in v0.6.0

func (mr *MockStateDBMockRecorder) CreateAccount(arg0 any) *gomock.Call

CreateAccount indicates an expected call of CreateAccount.

func (*MockStateDBMockRecorder) Exist added in v0.6.0

func (mr *MockStateDBMockRecorder) Exist(arg0 any) *gomock.Call

Exist indicates an expected call of Exist.

func (*MockStateDBMockRecorder) GetBalance added in v0.6.0

func (mr *MockStateDBMockRecorder) GetBalance(arg0 any) *gomock.Call

GetBalance indicates an expected call of GetBalance.

func (*MockStateDBMockRecorder) GetLogData added in v0.6.0

func (mr *MockStateDBMockRecorder) GetLogData() *gomock.Call

GetLogData indicates an expected call of GetLogData.

func (*MockStateDBMockRecorder) GetNonce added in v0.6.0

func (mr *MockStateDBMockRecorder) GetNonce(arg0 any) *gomock.Call

GetNonce indicates an expected call of GetNonce.

func (*MockStateDBMockRecorder) GetPredicateStorageSlots added in v0.6.0

func (mr *MockStateDBMockRecorder) GetPredicateStorageSlots(arg0, arg1 any) *gomock.Call

GetPredicateStorageSlots indicates an expected call of GetPredicateStorageSlots.

func (*MockStateDBMockRecorder) GetState added in v0.6.0

func (mr *MockStateDBMockRecorder) GetState(arg0, arg1 any) *gomock.Call

GetState indicates an expected call of GetState.

func (*MockStateDBMockRecorder) GetTxHash added in v0.6.0

func (mr *MockStateDBMockRecorder) GetTxHash() *gomock.Call

GetTxHash indicates an expected call of GetTxHash.

func (*MockStateDBMockRecorder) RevertToSnapshot added in v0.6.0

func (mr *MockStateDBMockRecorder) RevertToSnapshot(arg0 any) *gomock.Call

RevertToSnapshot indicates an expected call of RevertToSnapshot.

func (*MockStateDBMockRecorder) SetNonce added in v0.6.0

func (mr *MockStateDBMockRecorder) SetNonce(arg0, arg1 any) *gomock.Call

SetNonce indicates an expected call of SetNonce.

func (*MockStateDBMockRecorder) SetPredicateStorageSlots added in v0.6.0

func (mr *MockStateDBMockRecorder) SetPredicateStorageSlots(arg0, arg1 any) *gomock.Call

SetPredicateStorageSlots indicates an expected call of SetPredicateStorageSlots.

func (*MockStateDBMockRecorder) SetState added in v0.6.0

func (mr *MockStateDBMockRecorder) SetState(arg0, arg1, arg2 any) *gomock.Call

SetState indicates an expected call of SetState.

func (*MockStateDBMockRecorder) Snapshot added in v0.6.0

func (mr *MockStateDBMockRecorder) Snapshot() *gomock.Call

Snapshot indicates an expected call of Snapshot.

type RunStatefulPrecompileFunc

type RunStatefulPrecompileFunc func(accessibleState AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err 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) *uint256.Int
	AddBalance(common.Address, *uint256.Int)

	CreateAccount(common.Address)
	Exist(common.Address) bool

	AddLog(addr common.Address, topics []common.Hash, data []byte, blockNumber uint64)
	GetLogData() (topics [][]common.Hash, data [][]byte)
	GetPredicateStorageSlots(address common.Address, index int) ([]byte, bool)
	SetPredicateStorageSlots(address common.Address, predicates [][]byte)

	GetTxHash() common.Hash

	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

func NewStatefulPrecompileFunctionWithActivator added in v0.5.4

func NewStatefulPrecompileFunctionWithActivator(selector []byte, execute RunStatefulPrecompileFunc, activation ActivationFunc) *StatefulPrecompileFunction

func (*StatefulPrecompileFunction) IsActivated added in v0.5.4

func (f *StatefulPrecompileFunction) IsActivated(accessibleState AccessibleState) bool

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.

Jump to

Keyboard shortcuts

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