arwen

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const AddressLen = 32
View Source
const AddressLenEth = 20
View Source
const ArgumentLenEth = 32
View Source
const BalanceLen = 32
View Source
const HashLen = 32
View Source
const InitFunctionName = "init"
View Source
const InitFunctionNameEth = "solidity.ctor"

Variables

View Source
var ErrBadBounds = errors.New("bad bounds")
View Source
var ErrBadLowerBounds = fmt.Errorf("%w (lower)", ErrBadBounds)
View Source
var ErrBadUpperBounds = fmt.Errorf("%w (upper)", ErrBadBounds)
View Source
var ErrExecutionFailed = errors.New("execution failed")
View Source
var ErrFuncNotFound = errors.New("function not found")
View Source
var ErrFunctionReturnNotVoidError = errors.New("function return value other than void not allowed")

TODO: replace with wrong signature error/return code

View Source
var ErrFunctionRunError = errors.New("function run error")
View Source
var ErrInitFuncCalledInRun = errors.New("it is not allowed to call init in run")
View Source
var ErrInvalidAPICall = errors.New("invalid API call")
View Source
var ErrInvalidCallOnReadOnlyMode = errors.New("operation not permitted in read only mode")
View Source
var ErrInvalidFunctionName = errors.New("invalid function name")
View Source
var ErrMemoryDeclarationMissing = errors.New("wasm memory declaration missing")
View Source
var ErrNegativeLength = errors.New("negative length")
View Source
var ErrNotEnoughGas = errors.New("not enough gas")
View Source
var ErrReturnCodeNotOk = errors.New("return not is not ok")
View Source
var ErrSignalError = errors.New("error signalled by smartcontract")
View Source
var ErrUnhandledRuntimeBreakpoint = errors.New("unhandled runtime breakpoint")
View Source
var InstanceStackUnderflow = errors.New("instance stack underflow")
View Source
var StateStackUnderflow = errors.New("state stack underflow")

Functions

func AddHostContext added in v0.2.5

func AddHostContext(ctx VMHost) int

func GetCryptoContext added in v0.2.5

func GetCryptoContext(context unsafe.Pointer) vmcommon.CryptoHook

func GuardedGetBytesSlice added in v0.3.2

func GuardedGetBytesSlice(data []byte, offset int32, length int32) ([]byte, error)

func GuardedMakeByteSlice2D added in v0.3.2

func GuardedMakeByteSlice2D(length int32) ([][]byte, error)

func InverseBytes added in v0.3.2

func InverseBytes(data []byte) []byte

func PadBytesLeft added in v0.3.8

func PadBytesLeft(data []byte, size int) []byte

func RemoveHostContext added in v0.2.5

func RemoveHostContext(idx int)

func WithFault added in v0.3.5

func WithFault(err error, context unsafe.Pointer, failExecution bool) bool

Types

type ArgumentsParser added in v0.3.5

type ArgumentsParser interface {
	GetArguments() ([][]byte, error)
	GetCode() ([]byte, error)
	GetFunction() (string, error)
	ParseData(data string) error

	CreateDataFromStorageUpdate(storageUpdates []*vmcommon.StorageUpdate) string
	GetStorageUpdates(data string) ([]*vmcommon.StorageUpdate, error)
	IsInterfaceNil() bool
}

ArgumentsParser defines the functionality to parse transaction data into arguments and code for smart contracts

type AsyncCallInfo added in v0.3.5

type AsyncCallInfo struct {
	Destination []byte
	Data        []byte
	GasLimit    uint64
	ValueBytes  []byte
}

AsyncCallInfo contains the information required to handle the asynchronous call of another SmartContract

type BigIntContext added in v0.2.5

type BigIntContext interface {
	StateStack

	Put(value int64) int32
	GetOne(id int32) *big.Int
	GetTwo(id1, id2 int32) (*big.Int, *big.Int)
	GetThree(id1, id2, id3 int32) (*big.Int, *big.Int, *big.Int)
}

func GetBigIntContext added in v0.2.5

func GetBigIntContext(context unsafe.Pointer) BigIntContext

type BlockchainContext added in v0.3.3

type BlockchainContext interface {
	NewAddress(creatorAddress []byte) ([]byte, error)
	AccountExists(addr []byte) bool
	GetBalance(addr []byte) []byte
	GetNonce(addr []byte) (uint64, error)
	CurrentEpoch() uint32
	GetStateRootHash() []byte
	LastTimeStamp() uint64
	LastNonce() uint64
	LastRound() uint64
	LastEpoch() uint32
	CurrentRound() uint64
	CurrentNonce() uint64
	CurrentTimeStamp() uint64
	CurrentRandomSeed() []byte
	LastRandomSeed() []byte
	IncreaseNonce(addr []byte)
	GetCodeHash(addr []byte) ([]byte, error)
	GetCode(addr []byte) ([]byte, error)
	GetCodeSize(addr []byte) (int32, error)
	BlockHash(number int64) []byte
}

func GetBlockchainContext added in v0.3.3

func GetBlockchainContext(context unsafe.Pointer) BlockchainContext

type BreakpointValue added in v0.3.3

type BreakpointValue uint64
const (
	BreakpointNone BreakpointValue = iota
	BreakpointExecutionFailed
	BreakpointAsyncCall
	BreakpointSignalError
	BreakpointSignalExit
	BreakpointOutOfGas
)

type MeteringContext added in v0.3.3

type MeteringContext interface {
	GasSchedule() *config.GasCost
	UseGas(gas uint64)
	FreeGas(gas uint64)
	RestoreGas(gas uint64)
	GasLeft() uint64
	BoundGasLimit(value int64) uint64
	BlockGasLimit() uint64
	DeductInitialGasForExecution(contract []byte) error
	DeductInitialGasForDirectDeployment(input *vmcommon.ContractCreateInput) error
	DeductInitialGasForIndirectDeployment(input *vmcommon.ContractCreateInput) error
	UnlockGasIfAsyncStep()
}

func GetMeteringContext added in v0.3.3

func GetMeteringContext(context unsafe.Pointer) MeteringContext

type OutputContext added in v0.3.3

type OutputContext interface {
	StateStack

	GetOutputAccount(address []byte) (*vmcommon.OutputAccount, bool)
	WriteLog(address []byte, topics [][]byte, data []byte)
	Transfer(destination []byte, sender []byte, gasLimit uint64, value *big.Int, input []byte)
	SelfDestruct(address []byte, beneficiary []byte)
	GetRefund() uint64
	SetRefund(refund uint64)
	ReturnCode() vmcommon.ReturnCode
	SetReturnCode(returnCode vmcommon.ReturnCode)
	ReturnMessage() string
	SetReturnMessage(message string)
	ReturnData() [][]byte
	ClearReturnData()
	Finish(data []byte)
	GetVMOutput() *vmcommon.VMOutput
	AddTxValueToAccount(address []byte, value *big.Int)
	DeployCode(address []byte, code []byte)
	CreateVMOutputInCaseOfError(errCode vmcommon.ReturnCode, message string) *vmcommon.VMOutput
}

func GetOutputContext added in v0.3.3

func GetOutputContext(context unsafe.Pointer) OutputContext

type RuntimeContext added in v0.3.3

type RuntimeContext interface {
	StateStack

	InitStateFromContractCallInput(input *vmcommon.ContractCallInput)
	ArgParser() ArgumentsParser
	GetVMInput() *vmcommon.VMInput
	SetVMInput(vmInput *vmcommon.VMInput)
	GetSCAddress() []byte
	SetSCAddress(scAddress []byte)
	GetVMType() []byte
	Function() string
	Arguments() [][]byte
	SignalUserError(message string)
	FailExecution(err error)
	SetRuntimeBreakpointValue(value BreakpointValue)
	GetRuntimeBreakpointValue() BreakpointValue
	GetAsyncCallInfo() *AsyncCallInfo
	SetAsyncCallInfo(asyncCallInfo *AsyncCallInfo)
	PushInstance()
	PopInstance()
	ClearInstanceStack()
	ReadOnly() bool
	SetReadOnly(readOnly bool)
	CreateWasmerInstance(contract []byte, gasLimit uint64) error
	VerifyContractCode() error
	SetInstanceContext(instCtx *wasmer.InstanceContext)
	GetInstanceContext() *wasmer.InstanceContext
	GetInstanceExports() wasmer.ExportsMap
	GetInitFunction() wasmer.ExportedFunctionCallback
	GetFunctionToCall() (wasmer.ExportedFunctionCallback, error)
	GetPointsUsed() uint64
	SetPointsUsed(gasPoints uint64)
	MemStore(offset int32, data []byte) error
	MemLoad(offset int32, length int32) ([]byte, error)
	CleanInstance()
	SetInstanceContextId(id int)
	ElrondAPIErrorShouldFailExecution() bool
	CryptoAPIErrorShouldFailExecution() bool
	BigIntAPIErrorShouldFailExecution() bool
}

func GetRuntimeContext added in v0.3.3

func GetRuntimeContext(context unsafe.Pointer) RuntimeContext

type StateStack added in v0.3.3

type StateStack interface {
	InitState()
	PushState()
	PopState()
	ClearStateStack()
}

type StorageContext added in v0.3.3

type StorageContext interface {
	GetStorageUpdates(address []byte) map[string]*vmcommon.StorageUpdate
	GetStorage(address []byte, key []byte) []byte
	SetStorage(address []byte, key []byte, value []byte) int32
}

func GetStorageContext added in v0.3.3

func GetStorageContext(context unsafe.Pointer) StorageContext

type StorageStatus

type StorageStatus int
const (
	StorageUnchanged StorageStatus = iota
	StorageModified
	StorageAdded
	StorageDeleted
)

type VMHost added in v0.3.3

type VMHost interface {
	StateStack

	Crypto() vmcommon.CryptoHook
	Blockchain() BlockchainContext
	Runtime() RuntimeContext
	BigInt() BigIntContext
	Output() OutputContext
	Metering() MeteringContext
	Storage() StorageContext

	CreateNewContract(input *vmcommon.ContractCreateInput) ([]byte, error)
	ExecuteOnSameContext(input *vmcommon.ContractCallInput) error
	ExecuteOnDestContext(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
	EthereumCallData() []byte
}

func GetVmContext added in v0.3.3

func GetVmContext(context unsafe.Pointer) VMHost

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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