Documentation ¶
Index ¶
- Constants
- Variables
- func BooleanToInt(b bool) int
- func CustomStorageKey(keyType string, associatedKey []byte) []byte
- func GetCryptoContext(vmHostPtr unsafe.Pointer) crypto.VMCrypto
- func GetSCCode(fileName string) []byte
- func GuardedGetBytesSlice(data []byte, offset int32, length int32) ([]byte, error)
- func GuardedMakeByteSlice2D(length int32) ([][]byte, error)
- func IfNil(checker nilInterfaceChecker) bool
- func InverseBytes(data []byte) []byte
- func PadBytesLeft(data []byte, size int) []byte
- func U64ToLEB128(n uint64) (out []byte)
- func WithFault(err error, vmHostPtr unsafe.Pointer, failExecution bool) bool
- type AsyncCallExecutionMode
- type AsyncCallInfo
- type AsyncCallInfoHandler
- type AsyncCallStatus
- type AsyncContext
- type AsyncContextInfo
- type AsyncGeneratedCall
- func (ac *AsyncGeneratedCall) GetData() []byte
- func (ac *AsyncGeneratedCall) GetDestination() []byte
- func (ac *AsyncGeneratedCall) GetGasLimit() uint64
- func (ac *AsyncGeneratedCall) GetGasLocked() uint64
- func (ac *AsyncGeneratedCall) GetValueBytes() []byte
- func (ac *AsyncGeneratedCall) IsInterfaceNil() bool
- type BigIntContext
- type BlockchainContext
- type BreakpointValue
- type CallArgsParser
- type CodeDeployInput
- type InstanceBuilder
- type MeteringContext
- type OutputContext
- type RuntimeContext
- type StateStack
- type StorageContext
- type StorageStatus
- type VMHost
- type VMHostParameters
Constants ¶
const ( // AsyncCallPending is the status of an async call that awaits complete execution AsyncCallPending AsyncCallStatus = iota // AsyncCallResolved is the status of an async call that was executed completely and successfully AsyncCallResolved // AsyncCallRejected is the status of an async call that was executed completely but unsuccessfully AsyncCallRejected // AddressLen specifies the length of the address AddressLen = 32 // HashLen specifies the lenghth of a hash HashLen = 32 // BalanceLen specifies the number of bytes on which the balance is stored BalanceLen = 32 // CodeMetadataLen specifies the length of the code metadata CodeMetadataLen = 2 // InitFunctionName specifies the name for the init function InitFunctionName = "init" // InitFunctionNameEth specifies the name for the init function on Ethereum InitFunctionNameEth = "solidity.ctor" // UpgradeFunctionName specifies if the call is an upgradeContract call UpgradeFunctionName = "upgradeContract" )
const AsyncDataPrefix = ProtectedStoragePrefix + "ASYNC"
AsyncDataPrefix is the storage key prefix used for AsyncContext-related storage.
const CallbackFunctionName = "callBack"
CallbackFunctionName is the name of the default asynchronous callback function of a smart contract
const ProtectedStoragePrefix = "A" + "R" + "W" + "E" + "N@"
ProtectedStoragePrefix is the storage key prefix that will be protected by VM explicitly, and implicitly by the node due to '@'; the protection can be disabled temporarily by the StorageContext
const TimeLockKeyPrefix = ProtectedStoragePrefix + "TIMELOCK"
TimeLockKeyPrefix is the storage key prefix used for timelock-related storage.
const VMVersion = "v1.2"
Variables ¶
var ErrAccountNotPayable = errors.New("sending value to non payable contract")
ErrAccountNotPayable signals that the value transfer to a non payable contract is not possible
var ErrArgIndexOutOfRange = errors.New("argument index out of range")
ErrArgIndexOutOfRange signals that the argument index is out of range
var ErrArgOutOfRange = errors.New("argument out of range")
ErrArgOutOfRange signals that the argument is out of range
var ErrAsyncContextDoesNotExist = errors.New("async context does not exist")
ErrAsyncContextDoesNotExist signals that the async context does not exist
var ErrBadBounds = errors.New("bad bounds")
ErrBadBounds signals that a certain variable is out of bounds
var ErrBadLowerBounds = fmt.Errorf("%w (lower)", ErrBadBounds)
ErrBadLowerBounds signals that a certain variable is lower than allowed
var ErrBadUpperBounds = fmt.Errorf("%w (upper)", ErrBadBounds)
ErrBadUpperBounds signals that a certain variable is higher than allowed
var ErrBitwiseNegative = errors.New("bitwise operations only allowed on positive integers")
ErrBitwiseNegative signals that an attempt to apply a bitwise operation on negative numbers has been made
var ErrBuiltinCallOnSameContextDisallowed = errors.New("calling built-in function on the same context is disallowed")
ErrBuiltinCallOnSameContextDisallowed signals that calling a built-in function on the same context is not allowed
var ErrCallBackFuncCalledInRun = fmt.Errorf("%w (calling callBack() directly is forbidden)", ErrInvalidFunction)
ErrCallBackFuncCalledInRun signals that a callback func was called directly, which is forbidden
var ErrCallBackFuncNotExpected = fmt.Errorf("%w (unexpected callback was received)", ErrInvalidFunction)
ErrCallBackFuncNotExpected signals that an unexpected callback was received
var ErrCannotWriteProtectedKey = errors.New("cannot write to protected key")
ErrCannotWriteProtectedKey signals an attempt to write to a protected key, while storage protection is enforced
var ErrContractInvalid = fmt.Errorf("invalid contract code")
ErrContractInvalid signals that the contract code is invalid
var ErrContractNotFound = fmt.Errorf("%w (not found)", ErrContractInvalid)
ErrContractNotFound signals that the contract was not found
var ErrDeploymentOverExistingAccount = errors.New("cannot deploy over existing account")
ErrDeploymentOverExistingAccount signals that an attempt to deploy a new SC over an already existing account has been made
var ErrDivZero = errors.New("division by 0")
ErrDivZero signals that an attempt to divide by 0 has been made
var ErrExecutionFailed = errors.New("execution failed")
ErrExecutionFailed signals that the execution failed
var ErrFailedTransfer = errors.New("failed transfer")
ErrFailedTransfer signals that the transfer operation has failed
var ErrFuncNotFound = fmt.Errorf("%w (not found)", ErrInvalidFunction)
ErrFuncNotFound signals that the the function does not exist
var ErrFunctionNonvoidSignature = fmt.Errorf("%w (nonvoid signature)", ErrInvalidFunction)
ErrFunctionNonvoidSignature signals that the signature for the function is invalid
var ErrInitFuncCalledInRun = fmt.Errorf("%w (calling init() directly is forbidden)", ErrInvalidFunction)
ErrInitFuncCalledInRun signals that the init func was called directly, which is forbidden
var ErrInputAndOutputGasDoesNotMatch = errors.New("input and output gas does not match")
ErrInputAndOutputGasDoesNotMatch is raised when the output gas (gas used + gas locked + gas remaining) is not equal to the input gas
var ErrInvalidAccount = errors.New("account does not exist")
ErrInvalidAccount signals that a certain account does not exist
var ErrInvalidCallOnReadOnlyMode = errors.New("operation not permitted in read only mode")
ErrInvalidCallOnReadOnlyMode signals that an operation is not permitted due to read only mode
var ErrInvalidFunction = errors.New("invalid function")
ErrInvalidFunction signals that the function is invalid
var ErrInvalidFunctionName = fmt.Errorf("%w (invalid name)", ErrInvalidFunction)
ErrInvalidFunctionName signals that the function name is invalid
var ErrInvalidPublicKeySize = errors.New("invalid public key size")
ErrInvalidPublicKeySize signals that the public key size is invalid
var ErrInvalidUpgradeArguments = fmt.Errorf("%w (invalid arguments)", ErrUpgradeFailed)
ErrInvalidUpgradeArguments signals that the upgrade process failed due to invalid arguments
var ErrMaxInstancesReached = fmt.Errorf("%w (max instances reached)", ErrExecutionFailed)
ErrMaxInstancesReached signals that the max number of Wasmer instances has been reached.
var ErrMemoryDeclarationMissing = fmt.Errorf("%w (missing memory declaration)", ErrContractInvalid)
ErrMemoryDeclarationMissing signals that a memory declaration is missing
var ErrNegativeLength = errors.New("negative length")
ErrNegativeLength signals that the given length is less than 0
var ErrNilCallbackFunction = errors.New("nil callback function")
ErrNilCallbackFunction signals that a nil callback function has been provided
var ErrNilContract = errors.New("nil contract")
ErrNilContract signals that the contract is nil
var ErrNilEnableEpochsHandler = errors.New("nil enable epochs handler")
ErrNilEnableEpochsHandler signals that enable epochs handler is nil
var ErrNonPayableFunctionEgld = errors.New("function does not accept EGLD payment")
ErrNonPayableFunctionEgld signals that a non-payable function received non-zero call value
var ErrNonPayableFunctionEsdt = errors.New("function does not accept ESDT payment")
ErrNonPayableFunctionEsdt signals that a non-payable function received non-zero ESDT call value
var ErrNotEnoughGas = errors.New("not enough gas")
ErrNotEnoughGas signals that there is not enough gas for the operation
var ErrReturnCodeNotOk = errors.New("return code is not ok")
ErrReturnCodeNotOk signals that the returned code is different than vmcommon.Ok
var ErrShiftNegative = errors.New("bitwise shift operations only allowed on positive integers and by a positive amount")
ErrShiftNegative signals that an attempt to apply a bitwise shift operation on negative numbers has been made
var ErrSignalError = errors.New("error signalled by smartcontract")
ErrSignalError is given when the smart contract signals an error
var ErrStorageValueOutOfRange = errors.New("storage value out of range")
ErrStorageValueOutOfRange signals that the storage value is out of range
var ErrStoreReservedKey = errors.New("cannot write to storage under reserved key")
ErrStoreReservedKey signals that an attempt to write under an reserved key has been made
var ErrSyncExecutionNotInSameShard = errors.New("sync execution request is not in the same shard")
ErrSyncExecutionNotInSameShard signals that the sync execution request is not in the same shard
var ErrTransferInsufficientFunds = fmt.Errorf("%w (insufficient funds)", ErrFailedTransfer)
ErrTransferInsufficientFunds signals that the transfer has failed due to insufficient funds
var ErrTransferNegativeValue = fmt.Errorf("%w (negative value)", ErrFailedTransfer)
ErrTransferNegativeValue signals that the transfer has failed due to the fact that the value is less than 0
var ErrTransferValueOnESDTCall = errors.New("transfer value on esdt call")
ErrTransferValueOnESDTCall signals that balance transfer was given in esdt call
var ErrUnhandledRuntimeBreakpoint = errors.New("unhandled runtime breakpoint")
ErrUnhandledRuntimeBreakpoint signals that the runtime breakpoint is unhandled
var ErrUpgradeFailed = errors.New("upgrade failed")
ErrUpgradeFailed signals that the upgrade encountered an error
var ErrUpgradeNotAllowed = errors.New("upgrade not allowed")
ErrUpgradeNotAllowed signals that an upgrade is not allowed
var Zero = big.NewInt(0)
Zero is the big integer 0
Functions ¶
func BooleanToInt ¶
BooleanToInt returns 1 if the given bool is true, 0 otherwise
func CustomStorageKey ¶
CustomStorageKey appends the given key type to the given associated key
func GetCryptoContext ¶
GetCryptoContext returns the crypto context
func GuardedGetBytesSlice ¶
GuardedGetBytesSlice returns a chunk from the given data
func GuardedMakeByteSlice2D ¶
GuardedMakeByteSlice2D creates a new two-dimensional byte slice of the given dimension.
func IfNil ¶
func IfNil(checker nilInterfaceChecker) bool
IfNil tests if the provided interface pointer or underlying object is nil
func InverseBytes ¶
InverseBytes reverses the bytes of the given byte slice
func PadBytesLeft ¶
PadBytesLeft adds a padding of the given size to the left the byte slice
func U64ToLEB128 ¶
U64ToLEB128 encodes an uint64 using LEB128 (Little Endian Base 128), used in WASM bytecode See https://en.wikipedia.org/wiki/LEB128 Copied from https://github.com/filecoin-project/go-leb128/blob/master/leb128.go
Types ¶
type AsyncCallExecutionMode ¶
type AsyncCallExecutionMode uint
AsyncCallExecutionMode encodes the execution modes of an AsyncCall
const ( // SyncCall indicates that the async call can be executed synchronously, // with its corresponding callback SyncCall AsyncCallExecutionMode = iota // AsyncBuiltinFuncIntraShard indicates that the async call is an intra-shard built in function call AsyncBuiltinFuncIntraShard // AsyncBuiltinFuncCrossShard indicates that the async call is a cross-shard call to a // built-in function, which is executed half in-shard, half cross-shard AsyncBuiltinFuncCrossShard // ESDTTransferOnCallBack indicated that the async call is actually a callback with ESDT transfer ESDTTransferOnCallBack // AsyncUnknown indicates that the async call cannot be executed locally, and // must be forwarded to the destination account AsyncUnknown )
type AsyncCallInfo ¶
type AsyncCallInfo struct { Destination []byte Data []byte GasLimit uint64 GasLocked uint64 ValueBytes []byte }
AsyncCallInfo contains the information required to handle the asynchronous call of another SmartContract
func (*AsyncCallInfo) GetData ¶
func (aci *AsyncCallInfo) GetData() []byte
GetData returns the transaction data of the async call
func (*AsyncCallInfo) GetDestination ¶
func (aci *AsyncCallInfo) GetDestination() []byte
GetDestination returns the destination of an async call
func (*AsyncCallInfo) GetGasLimit ¶
func (aci *AsyncCallInfo) GetGasLimit() uint64
GetGasLimit returns the gas limit of the current async call
func (*AsyncCallInfo) GetGasLocked ¶
func (aci *AsyncCallInfo) GetGasLocked() uint64
GetGasLocked returns the gas locked for the async callback
func (*AsyncCallInfo) GetValueBytes ¶
func (aci *AsyncCallInfo) GetValueBytes() []byte
GetValueBytes returns the byte representation of the value of the async call
type AsyncCallInfoHandler ¶
type AsyncCallInfoHandler interface { GetDestination() []byte GetData() []byte GetGasLimit() uint64 GetGasLocked() uint64 GetValueBytes() []byte }
AsyncCallInfoHandler defines the functionality for working with AsyncCallInfo
type AsyncCallStatus ¶
type AsyncCallStatus uint8
AsyncCallStatus represents the different status an async call can have
type AsyncContext ¶
type AsyncContext struct { Callback string AsyncCalls []*AsyncGeneratedCall }
AsyncContext is a structure containing a group of async calls and a callback
that should be called when all these async calls are resolved
type AsyncContextInfo ¶
type AsyncContextInfo struct { CallerAddr []byte ReturnData []byte AsyncContextMap map[string]*AsyncContext }
AsyncContextInfo is the structure resulting after a smart contract call that has initiated one or more async calls. It will
type AsyncGeneratedCall ¶
type AsyncGeneratedCall struct { Status AsyncCallStatus Destination []byte Data []byte GasLimit uint64 ValueBytes []byte SuccessCallback string ErrorCallback string ProvidedGas uint64 }
AsyncGeneratedCall holds the information abount an async call
func (*AsyncGeneratedCall) GetData ¶
func (ac *AsyncGeneratedCall) GetData() []byte
GetData returns the transaction data of the async call
func (*AsyncGeneratedCall) GetDestination ¶
func (ac *AsyncGeneratedCall) GetDestination() []byte
GetDestination returns the destination of an async call
func (*AsyncGeneratedCall) GetGasLimit ¶
func (ac *AsyncGeneratedCall) GetGasLimit() uint64
GetGasLimit returns the gas limit of the current async call
func (*AsyncGeneratedCall) GetGasLocked ¶
func (ac *AsyncGeneratedCall) GetGasLocked() uint64
GetGasLocked returns the gas locked for the async callback
func (*AsyncGeneratedCall) GetValueBytes ¶
func (ac *AsyncGeneratedCall) GetValueBytes() []byte
GetValueBytes returns the byte representation of the value of the async call
func (*AsyncGeneratedCall) IsInterfaceNil ¶
func (ac *AsyncGeneratedCall) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
type BigIntContext ¶
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) }
BigIntContext defines the functionality needed for interacting with the big int context
func GetBigIntContext ¶
func GetBigIntContext(vmHostPtr unsafe.Pointer) BigIntContext
GetBigIntContext returns the big int context
type BlockchainContext ¶
type BlockchainContext interface { NewAddress(creatorAddress []byte) ([]byte, error) AccountExists(addr []byte) bool GetBalance(addr []byte) []byte GetBalanceBigInt(addr []byte) *big.Int 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 GetCode(addr []byte) ([]byte, error) GetCodeSize(addr []byte) (int32, error) BlockHash(number int64) []byte GetOwnerAddress() ([]byte, error) GetShardOfAddress(addr []byte) uint32 IsSmartContract(addr []byte) bool IsPayable(address []byte) (bool, error) SaveCompiledCode(codeHash []byte, code []byte) GetCompiledCode(codeHash []byte) (bool, []byte) GetESDTToken(address []byte, tokenID []byte, nonce uint64) (*esdt.ESDigitalToken, error) }
BlockchainContext defines the functionality needed for interacting with the blockchain context
func GetBlockchainContext ¶
func GetBlockchainContext(vmHostPtr unsafe.Pointer) BlockchainContext
GetBlockchainContext returns the blockchain context
type BreakpointValue ¶
type BreakpointValue uint64
BreakpointValue encodes Wasmer runtime breakpoint types
const ( // BreakpointNone signifies the lack of a breakpoint BreakpointNone BreakpointValue = iota // BreakpointExecutionFailed means that Wasmer must stop immediately due to failure indicated by VM BreakpointExecutionFailed // BreakpointAsyncCall means that Wasmer must stop immediately so VM can execute an AsyncCall BreakpointAsyncCall // BreakpointSignalError means that Wasmer must stop immediately due to a contract-signalled error BreakpointSignalError // BreakpointOutOfGas means that Wasmer must stop immediately due to gas being exhausted BreakpointOutOfGas )
type CallArgsParser ¶
type CallArgsParser interface { ParseData(data string) (string, [][]byte, error) IsInterfaceNil() bool }
CallArgsParser defines the functionality to parse transaction data for a smart contract call
type CodeDeployInput ¶
type CodeDeployInput struct { ContractCode []byte ContractCodeMetadata []byte ContractAddress []byte CodeDeployerAddress []byte }
CodeDeployInput contains code deploy state, whether it comes from a ContractCreateInput or a ContractCallInput
type InstanceBuilder ¶
type InstanceBuilder interface { NewInstanceWithOptions(contractCode []byte, options wasmer.CompilationOptions) (wasmer.InstanceHandler, error) NewInstanceFromCompiledCodeWithOptions(compiledCode []byte, options wasmer.CompilationOptions) (wasmer.InstanceHandler, error) }
InstanceBuilder defines the functionality needed to create Wasmer instances
type MeteringContext ¶
type MeteringContext interface { StateStack InitStateFromContractCallInput(input *vmcommon.VMInput) SetGasSchedule(gasMap config.GasScheduleMap) GasSchedule() *config.GasCost UseGas(gas uint64) FreeGas(gas uint64) RestoreGas(gas uint64) GasLeft() uint64 ForwardGas(sourceAddress []byte, destAddress []byte, gas uint64) GasUsedByContract() (uint64, uint64) GasUsedForExecution() uint64 GasSpentByContract() uint64 GetGasForExecution() uint64 GetGasProvided() uint64 GetSCPrepareInitialCost() uint64 BoundGasLimit(value int64) uint64 BlockGasLimit() uint64 DeductInitialGasForExecution(contract []byte) error DeductInitialGasForDirectDeployment(input CodeDeployInput) error DeductInitialGasForIndirectDeployment(input CodeDeployInput) error ComputeGasLockedForAsync() uint64 UseGasForAsyncStep() error UseGasBounded(gasToUse uint64) error GetGasLocked() uint64 SetTotalUsedGas(total uint64) GetPreviousTotalUsedGas() uint64 }
MeteringContext defines the functionality needed for interacting with the metering context
func GetMeteringContext ¶
func GetMeteringContext(vmHostPtr unsafe.Pointer) MeteringContext
GetMeteringContext returns the metering context
type OutputContext ¶
type OutputContext interface { StateStack PopMergeActiveState() CensorVMOutput() ResetGas() AddToActiveState(rightOutput *vmcommon.VMOutput) GetOutputAccount(address []byte) (*vmcommon.OutputAccount, bool) DeleteOutputAccount(address []byte) WriteLog(address []byte, topics [][]byte, data []byte) TransferValueOnly(destination []byte, sender []byte, value *big.Int, checkPayable bool) error Transfer(destination []byte, sender []byte, gasLimit uint64, gasLocked uint64, value *big.Int, input []byte, callType vm.CallType) error TransferESDT(destination []byte, sender []byte, tokenIdentifier []byte, nonce uint64, value *big.Int, callInput *vmcommon.ContractCallInput) (uint64, error) 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) PrependFinish(data []byte) GetVMOutput() *vmcommon.VMOutput AddTxValueToAccount(address []byte, value *big.Int) DeployCode(input CodeDeployInput) CreateVMOutputInCaseOfError(err error) *vmcommon.VMOutput GetCurrentTotalUsedGas() (uint64, bool) }
OutputContext defines the functionality needed for interacting with the output context
func GetOutputContext ¶
func GetOutputContext(vmHostPtr unsafe.Pointer) OutputContext
GetOutputContext returns the output context
type RuntimeContext ¶
type RuntimeContext interface { StateStack InitStateFromContractCallInput(input *vmcommon.ContractCallInput) SetCustomCallFunction(callFunction string) GetVMInput() *vmcommon.VMInput SetVMInput(vmInput *vmcommon.VMInput) GetSCAddress() []byte SetSCAddress(scAddress []byte) GetSCCode() ([]byte, error) GetSCCodeSize() uint64 GetVMType() []byte Function() string Arguments() [][]byte GetCurrentTxHash() []byte GetOriginalTxHash() []byte ExtractCodeUpgradeFromArgs() ([]byte, []byte, error) SignalUserError(message string) FailExecution(err error) MustVerifyNextContractCode() SetRuntimeBreakpointValue(value BreakpointValue) GetRuntimeBreakpointValue() BreakpointValue IsContractOnTheStack(address []byte) bool GetAsyncCallInfo() *AsyncCallInfo SetAsyncCallInfo(asyncCallInfo *AsyncCallInfo) AddAsyncContextCall(contextIdentifier []byte, asyncCall *AsyncGeneratedCall) error GetAsyncContextInfo() *AsyncContextInfo GetAsyncContext(contextIdentifier []byte) (*AsyncContext, error) RunningInstancesCount() uint64 IsFunctionImported(name string) bool IsWarmInstance() bool ResetWarmInstance() ReadOnly() bool SetReadOnly(readOnly bool) StartWasmerInstance(contract []byte, gasLimit uint64, newCode bool) error CleanWasmerInstance() SetMaxInstanceCount(uint64) VerifyContractCode() error 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) MemLoadMultiple(offset int32, lengths []int32) ([][]byte, error) BaseOpsErrorShouldFailExecution() bool SyncExecAPIErrorShouldFailExecution() bool CryptoAPIErrorShouldFailExecution() bool BigIntAPIErrorShouldFailExecution() bool ExecuteAsyncCall(address []byte, data []byte, value []byte) error // TODO remove after implementing proper mocking of Wasmer instances; this is // used for tests only ReplaceInstanceBuilder(builder InstanceBuilder) }
RuntimeContext defines the functionality needed for interacting with the runtime context
func GetRuntimeContext ¶
func GetRuntimeContext(vmHostPtr unsafe.Pointer) RuntimeContext
GetRuntimeContext returns the runtime context
type StateStack ¶
type StateStack interface { InitState() PushState() PopSetActiveState() PopDiscard() ClearStateStack() }
StateStack defines the functionality for working with a state stack
type StorageContext ¶
type StorageContext interface { StateStack SetAddress(address []byte) GetStorageUpdates(address []byte) map[string]*vmcommon.StorageUpdate GetStorageFromAddress(address []byte, key []byte) []byte GetStorage(key []byte) []byte GetStorageUnmetered(key []byte) []byte SetStorage(key []byte, value []byte) (StorageStatus, error) SetProtectedStorage(key []byte, value []byte) (StorageStatus, error) }
StorageContext defines the functionality needed for interacting with the storage context
func GetStorageContext ¶
func GetStorageContext(vmHostPtr unsafe.Pointer) StorageContext
GetStorageContext returns the storage context
type StorageStatus ¶
type StorageStatus int
StorageStatus defines the states the storage can be in
const ( // StorageUnchanged signals that the storage was not changed StorageUnchanged StorageStatus = iota // StorageModified signals that the storage has been modified StorageModified // StorageAdded signals that something was added to storage StorageAdded // StorageDeleted signals that something was removed from storage StorageDeleted )
type VMHost ¶
type VMHost interface { Crypto() crypto.VMCrypto Blockchain() BlockchainContext Runtime() RuntimeContext BigInt() BigIntContext Output() OutputContext Metering() MeteringContext Storage() StorageContext IsVMV2Enabled() bool IsAheadOfTimeCompileEnabled() bool IsDynamicGasLockingEnabled() bool IsVMV3Enabled() bool IsESDTFunctionsEnabled() bool ExecuteESDTTransfer(destination []byte, sender []byte, tokenIdentifier []byte, nonce uint64, value *big.Int, callType vm.CallType, isRevert bool) (*vmcommon.VMOutput, uint64, error) RevertESDTTransfer(input *vmcommon.ContractCallInput) CreateNewContract(input *vmcommon.ContractCreateInput) ([]byte, error) ExecuteOnSameContext(input *vmcommon.ContractCallInput) (*AsyncContextInfo, error) ExecuteOnDestContext(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, *AsyncContextInfo, uint64, error) GetAPIMethods() *wasmer.Imports GetProtocolBuiltinFunctions() vmcommon.FunctionNames IsBuiltinFunctionName(functionName string) bool AreInSameShard(leftAddress []byte, rightAddress []byte) bool }
VMHost defines the functionality for working with the VM
type VMHostParameters ¶
type VMHostParameters struct { VMType []byte BlockGasLimit uint64 GasSchedule config.GasScheduleMap ProtocolBuiltinFunctions vmcommon.FunctionNames ProtectedKeyPrefix []byte WasmerSIGSEGVPassthrough bool UseWarmInstance bool EnableEpochsHandler vmcommon.EnableEpochsHandler }
VMHostParameters represents the parameters to be passed to VMHost