Documentation ¶
Index ¶
- Constants
- Variables
- func AddHostContext(ctx VMHost) int
- func BooleanToInt(b bool) int
- func CustomStorageKey(keyType string, associatedKey []byte) []byte
- func GetCryptoContext(context unsafe.Pointer) vmcommon.CryptoHook
- 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 RemoveAllHostContexts()
- func RemoveHostContext(idx int)
- func TimeTrack(start time.Time, message string)
- func U64MulToBigInt(x, y uint64) *big.Int
- func WithFault(err error, context unsafe.Pointer, failExecution bool) bool
- type AsyncCallExecutionMode
- type AsyncCallInfo
- type AsyncCallInfoHandler
- type AsyncCallStatus
- type AsyncContext
- type AsyncContextInfo
- type AsyncGeneratedCall
- type BigIntContext
- type BlockchainContext
- type BreakpointValue
- type CallArgsParser
- type CodeDeployInput
- type MeteringContext
- type OutputContext
- type RuntimeContext
- type StateStack
- type StorageContext
- type StorageStatus
- type VMHost
- type VMHostParameters
Constants ¶
const AddressLen = 32
const AddressLenEth = 20
const ArgumentLenEth = 32
const AsyncDataPrefix = "asyncCalls"
const BalanceLen = 32
const CallBackFunctionName = "callBack"
const CallbackDefault = "callBack"
const HashLen = 32
const InitFunctionName = "init"
const InitFunctionNameEth = "solidity.ctor"
const TimeLockKeyPrefix = "timelock"
const UpgradeFunctionName = "upgradeContract"
Variables ¶
var ErrAccountNotPayable = errors.New("sending value to non payable contract")
var ErrArgIndexOutOfRange = errors.New("argument index out of range")
var ErrArgOutOfRange = errors.New("argument out of range")
var ErrAsyncCallsDisallowed = errors.New("async calls disallowed")
var ErrAsyncContextDoesNotExist = errors.New("async context does not exist")
var ErrBadBounds = errors.New("bad bounds")
var ErrBadLowerBounds = fmt.Errorf("%w (lower)", ErrBadBounds)
var ErrBadUpperBounds = fmt.Errorf("%w (upper)", ErrBadBounds)
var ErrBitwiseNegative = errors.New("bitwise operations only allowed on positive integers")
var ErrCallBackFuncCalledInRun = fmt.Errorf("%w (calling callBack() directly is forbidden)", ErrInvalidFunction)
var ErrCallBackFuncNotExpected = fmt.Errorf("%w (unexpected callback was received)", ErrInvalidFunction)
var ErrContractInvalid = fmt.Errorf("invalid contract code")
var ErrContractNotFound = fmt.Errorf("%w (not found)", ErrContractInvalid)
var ErrDeploymentOverExistingAccount = errors.New("cannot deploy over existing account")
var ErrDivZero = errors.New("division by 0")
var ErrExecutionFailed = errors.New("execution failed")
var ErrFailedTransfer = errors.New("failed transfer")
var ErrFailedTransferDuringAsyncCall = fmt.Errorf("%w (failed during async call)", ErrFailedTransfer)
var ErrFuncNotFound = fmt.Errorf("%w (not found)", ErrInvalidFunction)
var ErrFunctionNonvoidSignature = fmt.Errorf("%w (nonvoid signature)", ErrInvalidFunction)
var ErrFunctionRunError = errors.New("function run error")
var ErrInitFuncCalledInRun = fmt.Errorf("%w (calling init() directly is forbidden)", ErrInvalidFunction)
var ErrInvalidAPICall = errors.New("invalid API call")
var ErrInvalidAccount = errors.New("account does not exist")
var ErrInvalidCallOnReadOnlyMode = errors.New("operation not permitted in read only mode")
var ErrInvalidFunction = errors.New("invalid function")
var ErrInvalidFunctionName = fmt.Errorf("%w (invalid name)", ErrInvalidFunction)
var ErrInvalidUpgradeArguments = fmt.Errorf("%w (invalid arguments)", ErrUpgradeFailed)
var ErrMaxInstancesReached = fmt.Errorf("%w (max instances reached)", ErrExecutionFailed)
var ErrMemoryDeclarationMissing = fmt.Errorf("%w (missing memory declaration)", ErrContractInvalid)
var ErrNegativeLength = errors.New("negative length")
var ErrNilCallbackVMOutput = errors.New("nil callback VMOutput")
var ErrNotEnoughGas = errors.New("not enough gas")
var ErrReturnCodeNotOk = errors.New("return not is not ok")
var ErrShiftNegative = errors.New("bitwise shift operations only allowed on positive integers and by a positive amount")
var ErrSignalError = errors.New("error signalled by smartcontract")
var ErrStoreElrondReservedKey = errors.New("cannot write to storage under Elrond reserved key")
var ErrTransferInsufficientFunds = fmt.Errorf("%w (insufficient funds)", ErrFailedTransfer)
var ErrTransferNegativeValue = fmt.Errorf("%w (negative value)", ErrFailedTransfer)
var ErrUnhandledRuntimeBreakpoint = errors.New("unhandled runtime breakpoint")
var ErrUpgradeFailed = errors.New("upgrade failed")
var Zero = big.NewInt(0)
Zero is the big integer 0
Functions ¶
func AddHostContext ¶ added in v0.2.5
func BooleanToInt ¶ added in v0.3.21
func CustomStorageKey ¶ added in v0.3.21
func GetCryptoContext ¶ added in v0.2.5
func GetCryptoContext(context unsafe.Pointer) vmcommon.CryptoHook
func GuardedGetBytesSlice ¶ added in v0.3.2
func GuardedMakeByteSlice2D ¶ added in v0.3.2
func IfNil ¶ added in v0.3.21
func IfNil(checker nilInterfaceChecker) bool
IfNil tests if the provided interface pointer or underlying object is nil
func InverseBytes ¶ added in v0.3.2
func PadBytesLeft ¶ added in v0.3.8
func RemoveAllHostContexts ¶ added in v0.3.12
func RemoveAllHostContexts()
func RemoveHostContext ¶ added in v0.2.5
func RemoveHostContext(idx int)
func U64MulToBigInt ¶ added in v0.3.21
Types ¶
type AsyncCallExecutionMode ¶ added in v0.3.25
type AsyncCallExecutionMode uint
const ( SyncCall AsyncCallExecutionMode = iota AsyncBuiltinFunc AsyncUnknown )
type AsyncCallInfo ¶ added in v0.3.5
AsyncCallInfo contains the information required to handle the asynchronous call of another SmartContract
func (*AsyncCallInfo) GetData ¶ added in v0.3.21
func (aci *AsyncCallInfo) GetData() []byte
func (*AsyncCallInfo) GetDestination ¶ added in v0.3.21
func (aci *AsyncCallInfo) GetDestination() []byte
func (*AsyncCallInfo) GetGasLimit ¶ added in v0.3.21
func (aci *AsyncCallInfo) GetGasLimit() uint64
func (*AsyncCallInfo) GetValueBytes ¶ added in v0.3.21
func (aci *AsyncCallInfo) GetValueBytes() []byte
type AsyncCallInfoHandler ¶ added in v0.3.21
type AsyncCallStatus ¶ added in v0.3.21
type AsyncCallStatus uint8
AsyncCallStatus represents the different status an async call can have
const ( AsyncCallPending AsyncCallStatus = iota AsyncCallResolved AsyncCallRejected )
type AsyncContext ¶ added in v0.3.21
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 ¶ added in v0.3.21
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 ¶ added in v0.3.21
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 ¶ added in v0.3.21
func (ac *AsyncGeneratedCall) GetData() []byte
GetData returns the transaction data of the async call
func (*AsyncGeneratedCall) GetDestination ¶ added in v0.3.21
func (ac *AsyncGeneratedCall) GetDestination() []byte
GetDestination returns the destination of an async call
func (*AsyncGeneratedCall) GetGasLimit ¶ added in v0.3.21
func (ac *AsyncGeneratedCall) GetGasLimit() uint64
GetGasLimit returns the gas limit of the current async call
func (*AsyncGeneratedCall) GetValueBytes ¶ added in v0.3.21
func (ac *AsyncGeneratedCall) GetValueBytes() []byte
GetValueBytes returns the byte representation of the value of the async call
func (*AsyncGeneratedCall) IsInterfaceNil ¶ added in v0.3.21
func (ac *AsyncGeneratedCall) IsInterfaceNil() bool
IsInterfaceNil returns true if there is no value under the interface
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 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, error) 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) }
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 BreakpointOutOfGas )
type CallArgsParser ¶ added in v0.3.20
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 ¶ added in v0.3.12
type CodeDeployInput struct { ContractCode []byte ContractCodeMetadata []byte ContractAddress []byte }
CodeDeployInput contains code deploy state, whether it comes from a ContractCreateInput or a ContractCallInput
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 CodeDeployInput) error DeductInitialGasForIndirectDeployment(input CodeDeployInput) error DeductAndLockGasIfAsyncStep() error UnlockGasIfAsyncStep() GetGasLockedForAsyncStep() uint64 }
func GetMeteringContext ¶ added in v0.3.3
func GetMeteringContext(context unsafe.Pointer) MeteringContext
type OutputContext ¶ added in v0.3.3
type OutputContext interface { StateStack PopMergeActiveState() CensorVMOutput() AddToActiveState(rightOutput *vmcommon.VMOutput) GetOutputAccount(address []byte) (*vmcommon.OutputAccount, bool) DeleteOutputAccount(address []byte) WriteLog(address []byte, topics [][]byte, data []byte) Transfer(destination []byte, sender []byte, gasLimit uint64, value *big.Int, input []byte) 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) GetVMOutput() *vmcommon.VMOutput AddTxValueToAccount(address []byte, value *big.Int) DeployCode(input CodeDeployInput) CreateVMOutputInCaseOfError(err error) *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) SetCustomCallFunction(callFunction string) GetVMInput() *vmcommon.VMInput SetVMInput(vmInput *vmcommon.VMInput) GetSCAddress() []byte SetSCAddress(scAddress []byte) 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 GetAsyncCallInfo() *AsyncCallInfo SetAsyncCallInfo(asyncCallInfo *AsyncCallInfo) AddAsyncContextCall(contextIdentifier []byte, asyncCall *AsyncGeneratedCall) error GetAsyncContextInfo() *AsyncContextInfo GetAsyncContext(contextIdentifier []byte) (*AsyncContext, error) PushInstance() PopInstance() RunningInstancesCount() uint64 ClearInstanceStack() ReadOnly() bool SetReadOnly(readOnly bool) StartWasmerInstance(contract []byte, gasLimit uint64) 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) 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() PopSetActiveState() PopDiscard() ClearStateStack() }
type StorageContext ¶ added in v0.3.3
type StorageContext interface { StateStack SetAddress(address []byte) GetStorageUpdates(address []byte) map[string]*vmcommon.StorageUpdate GetStorage(key []byte) []byte GetStorageUnmetered(key []byte) []byte SetStorage(key []byte, value []byte) (StorageStatus, error) }
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 { 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) (*AsyncContextInfo, error) ExecuteOnDestContext(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, *AsyncContextInfo, error) EthereumCallData() []byte GetAPIMethods() *wasmer.Imports GetProtocolBuiltinFunctions() vmcommon.FunctionNames IsBuiltinFunctionName(functionName string) bool }
func GetVmContext ¶ added in v0.3.3
type VMHostParameters ¶ added in v0.3.14
type VMHostParameters struct { VMType []byte BlockGasLimit uint64 GasSchedule config.GasScheduleMap ProtocolBuiltinFunctions vmcommon.FunctionNames ElrondProtectedKeyPrefix []byte }
VMHostParameters represents the parameters to be passed to VMHost