wasmvm

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: LGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

SPDX-License-Identifier: LGPL-3.0-or-later Copyright 2019 DNA Dev team

  • Copyright (C) 2018 The ontology Authors
  • This file is part of The ontology library. *
  • The ontology is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The ontology is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The ontology. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

This section is empty.

Variables

View Source
var (
	TIMESTAMP_GAS        uint64 = 1
	BLOCK_HEGHT_GAS      uint64 = 1
	SELF_ADDRESS_GAS     uint64 = 1
	CALLER_ADDRESS_GAS   uint64 = 1
	ENTRY_ADDRESS_GAS    uint64 = 1
	CHECKWITNESS_GAS     uint64 = 200
	CALL_CONTRACT_GAS    uint64 = 10
	CONTRACT_CREATE_GAS  uint64 = 20000000
	CONTRACT_MIGRATE_GAS uint64 = 20000000
	NATIVE_INVOKE_GAS    uint64 = 1000

	CURRENT_BLOCK_HASH_GAS uint64 = 100
	CURRENT_TX_HASH_GAS    uint64 = 100

	STORAGE_GET_GAS          uint64 = 200
	STORAGE_PUT_GAS          uint64 = 4000
	STORAGE_DELETE_GAS       uint64 = 100
	UINT_DEPLOY_CODE_LEN_GAS uint64 = 200000
	PER_UNIT_CODE_LEN        uint64 = 1024

	SHA256_GAS uint64 = 10
)
View Source
var (
	ERR_CHECK_STACK_SIZE  = errors.NewErr("[WasmVmService] vm over max stack size!")
	ERR_EXECUTE_CODE      = errors.NewErr("[WasmVmService] vm execute code invalid!")
	ERR_GAS_INSUFFICIENT  = errors.NewErr("[WasmVmService] gas insufficient")
	VM_EXEC_STEP_EXCEED   = errors.NewErr("[WasmVmService] vm execute step exceed!")
	CONTRACT_NOT_EXIST    = errors.NewErr("[WasmVmService] Get contract code from db fail")
	DEPLOYCODE_TYPE_ERROR = errors.NewErr("[WasmVmService] DeployCode type error!")
	VM_EXEC_FAULT         = errors.NewErr("[WasmVmService] vm execute state fault!")
	VM_INIT_FAULT         = errors.NewErr("[WasmVmService] vm init state fault!")

	CODE_CACHE_SIZE      = 100
	CONTRACT_METHOD_NAME = "invoke"

	//max memory size of wasm vm
	WASM_MEM_LIMITATION  uint64 = 10 * 1024 * 1024
	VM_STEP_LIMIT               = 40000000
	WASM_CALLSTACK_LIMIT        = 1024

	CodeCache *lru.ARCCache
)

Functions

func BlockHeight

func BlockHeight(proc *exec.Process) uint32

func CallContract

func CallContract(proc *exec.Process, contractAddr uint32, inputPtr uint32, inputLen uint32) uint32

func CallOutputLength

func CallOutputLength(proc *exec.Process) uint32

func CallerAddress

func CallerAddress(proc *exec.Process, dst uint32)

func Checkwitness

func Checkwitness(proc *exec.Process, dst uint32) uint32

func ContractCreate

func ContractCreate(proc *exec.Process,
	codePtr uint32,
	codeLen uint32,
	vmType uint32,
	namePtr uint32,
	nameLen uint32,
	verPtr uint32,
	verLen uint32,
	authorPtr uint32,
	authorLen uint32,
	emailPtr uint32,
	emailLen uint32,
	descPtr uint32,
	descLen uint32,
	newAddressPtr uint32) uint32

func ContractDestroy

func ContractDestroy(proc *exec.Process)

func ContractMigrate

func ContractMigrate(proc *exec.Process,
	codePtr uint32,
	codeLen uint32,
	vmType uint32,
	namePtr uint32,
	nameLen uint32,
	verPtr uint32,
	verLen uint32,
	authorPtr uint32,
	authorLen uint32,
	emailPtr uint32,
	emailLen uint32,
	descPtr uint32,
	descLen uint32,
	newAddressPtr uint32) uint32

func Debug

func Debug(proc *exec.Process, ptr uint32, len uint32)

func EntryAddress

func EntryAddress(proc *exec.Process, dst uint32)

func GetCallOut

func GetCallOut(proc *exec.Process, dst uint32)

func GetCurrentBlockHash

func GetCurrentBlockHash(proc *exec.Process, ptr uint32) uint32

func GetCurrentTxHash

func GetCurrentTxHash(proc *exec.Process, ptr uint32) uint32

func GetInput

func GetInput(proc *exec.Process, dst uint32)

func InputLength

func InputLength(proc *exec.Process) uint32

func NewHostModule

func NewHostModule() *wasm.Module

func Notify

func Notify(proc *exec.Process, ptr uint32, l uint32)

func RaiseException

func RaiseException(proc *exec.Process, ptr uint32, len uint32)

func ReadWasmMemory

func ReadWasmMemory(proc *exec.Process, ptr uint32, len uint32) ([]byte, error)

func ReadWasmModule

func ReadWasmModule(Code []byte, verify bool) (*exec.CompiledModule, error)

func Ret

func Ret(proc *exec.Process, ptr uint32, len uint32)

func SelfAddress

func SelfAddress(proc *exec.Process, dst uint32)

func Sha256

func Sha256(proc *exec.Process, src uint32, slen uint32, dst uint32)

func StorageDelete

func StorageDelete(proc *exec.Process, keyPtr uint32, keyLen uint32)

func StorageRead

func StorageRead(proc *exec.Process, keyPtr uint32, klen uint32, val uint32, vlen uint32, offset uint32) uint32

func StorageWrite

func StorageWrite(proc *exec.Process, keyPtr uint32, keyLen uint32, valPtr uint32, valLen uint32)

func Timestamp

func Timestamp(proc *exec.Process) uint64

Types

type ContractType

type ContractType byte
const (
	NATIVE_CONTRACT ContractType = iota
	NEOVM_CONTRACT
	WASMVM_CONTRACT
	UNKOWN_CONTRACT
)

type Runtime

type Runtime struct {
	Service    *WasmVmService
	Input      []byte
	Output     []byte
	CallOutPut []byte
}

type WasmVmService

type WasmVmService struct {
	Store         store.LedgerStore
	CacheDB       *storage.CacheDB
	ContextRef    context.ContextRef
	Notifications []*event.NotifyEventInfo
	Code          []byte
	Tx            *types.Transaction
	Time          uint32
	Height        uint32
	BlockHash     common.Uint256
	PreExec       bool
	GasPrice      uint64
	GasLimit      *uint64
	ExecStep      *uint64
	GasFactor     uint64
	IsTerminate   bool
	// contains filtered or unexported fields
}

func (*WasmVmService) Invoke

func (this *WasmVmService) Invoke() (interface{}, error)

Jump to

Keyboard shortcuts

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