bvm

package
v0.0.0-...-24d451d Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GasSha3          uint64 = 10
	GasGetAccount    uint64 = 10
	GasStorageUpdate uint64 = 10
	GasCreateAccount uint64 = 10

	GasBaseOp  uint64 = 1
	GasStackOp uint64 = 1

	GasEcRecover     uint64 = 10
	GasSha256Word    uint64 = 10
	GasSha256Base    uint64 = 10
	GasRipemd160Word uint64 = 1
	GasRipemd160Base uint64 = 1
	GasIdentityWord  uint64 = 1
	GasIdentityBase  uint64 = 1

	GasBlockHash uint64 = 100 // 太昂贵的操作了
)
View Source
const (
	DataStackInitialCapacity    = 1024
	MaximumAllowedBlockLookBack = 256
)
View Source
const SignatureLength = 65

Variables

This section is empty.

Functions

func CalcContractAddr

func CalcContractAddr(senderAddr gocrypto.Address, nonce []byte, chainID string) gocrypto.Address

func DebugOpcodes

func DebugOpcodes(vm *VM)

func DumpTokens

func DumpTokens(vm *VM)

func ExecuteNativeContract

func ExecuteNativeContract(address crypto.BVMAddress, st Interface, caller crypto.BVMAddress, input []byte, gas *uint64,
	logger log.Logger) ([]byte, errors.CodedError)

func Is64BitOverflow

func Is64BitOverflow(word Word256) bool

func IsRegisteredNativeContract

func IsRegisteredNativeContract(address crypto.BVMAddress) bool

func MemoryProvider

func MemoryProvider(memoryProvider func(errors.Sink) Memory) func(*VM)

func NewLogFreeEventSink

func NewLogFreeEventSink(eventSink EventSink) *logFreeEventSink

func StackOptions

func StackOptions(callStackMaxDepth uint64, dataStackInitialCapacity uint64, dataStackMaxDepth uint64) func(*VM)

Types

type BcEventSink

type BcEventSink struct {
	Logger log.Logger
	Tags   *[]interface{}
}

func NewBcEventSink

func NewBcEventSink(Logger log.Logger, tags *[]interface{}) *BcEventSink

func (*BcEventSink) Call

func (es *BcEventSink) Call(call *exec.CallEvent, exception *errors.Exception) error

func (*BcEventSink) CallTransfer

func (es *BcEventSink) CallTransfer(transfer *exec.TransferData, exception *errors.Exception) error

func (*BcEventSink) Log

func (es *BcEventSink) Log(log *exec.LogEvent) error

type EventSink

type EventSink interface {
	Call(call *exec.CallEvent, exception *errors.Exception) error
	CallTransfer(call *exec.TransferData, exception *errors.Exception) error
	Log(log *exec.LogEvent) error
}

type FakeAppState

type FakeAppState struct {
	Accounts map[crypto.BVMAddress]*acm.Account
	Storage  map[string][]byte
	// contains filtered or unexported fields
}

func (*FakeAppState) GetAccount

func (fas *FakeAppState) GetAccount(addr crypto.BVMAddress) (*acm.Account, error)

func (*FakeAppState) GetStorage

func (fas *FakeAppState) GetStorage(addr crypto.BVMAddress, key Word256) ([]byte, error)

func (*FakeAppState) GetToken

func (fas *FakeAppState) GetToken() goCrypto.Address

func (*FakeAppState) RemoveAccount

func (fas *FakeAppState) RemoveAccount(address crypto.BVMAddress) error

func (*FakeAppState) SetStorage

func (fas *FakeAppState) SetStorage(addr crypto.BVMAddress, key Word256, value []byte) error

func (*FakeAppState) SetToken

func (fas *FakeAppState) SetToken(token goCrypto.Address)

func (*FakeAppState) UpdateAccount

func (fas *FakeAppState) UpdateAccount(account *acm.Account) error

type Interface

type Interface interface {
	Reader
	Writer
	// Capture any errors when accessing or writing state - will return nil if no errors have occurred so far
	errors.Provider
	errors.Sink
	// Create a new cached state over this one inheriting any cache options
	NewCache(cacheOptions ...acmstate.CacheOption) Interface
	// Sync this state cache to into its originator
	Sync() errors.CodedError
}

type Memory

type Memory interface {
	// Read a value from the memory store starting at offset
	// (index of first byte will equal offset). The value will be returned as a
	// length-bytes byte slice. Returns an error if the memory cannot be read or
	// is not allocated.
	//
	// The value returned should be copy of any underlying memory, not a reference
	// to the underlying store.
	Read(offset, length *big.Int) []byte
	// Write a value to the memory starting at offset (the index of the first byte
	// written will equal offset). The value is provided as bytes to be written
	// consecutively to the memory store. Return an error if the memory cannot be
	// written or allocated.
	Write(offset *big.Int, value []byte)
	// Returns the current capacity of the memory. For dynamically allocating
	// memory this capacity can be used as a write offset that is guaranteed to be
	// unused. Solidity in particular makes this assumption when using MSIZE to
	// get the current allocated memory.
	Capacity() *big.Int
}

Interface for a bounded linear memory indexed by a single *big.Int parameter for each byte in the memory.

func DefaultDynamicMemoryProvider

func DefaultDynamicMemoryProvider(errSink errors.Sink) Memory

func NewDynamicMemory

func NewDynamicMemory(initialCapacity, maximumCapacity uint64, errSink errors.Sink) Memory

Get a new DynamicMemory (note that although we take a maximumCapacity of uint64 we currently limit the maximum to int32 at runtime because we are using a single slice which we cannot guarantee to be indexable above int32 or all validators

type NativeContract

type NativeContract func(state Interface, caller crypto.BVMAddress, input []byte, gas *uint64,
	logger log.Logger) (output []byte, err error)

type Params

type Params struct {
	BlockHeader              types2.Header
	GasLimit                 uint64
	BlockHash                []byte
	GasPrice                 int64
	CallStackMaxDepth        uint64
	DataStackInitialCapacity uint64
	DataStackMaxDepth        uint64
}

type Reader

type Reader interface {
	GetStorage(address crypto.BVMAddress, key binary.Word256) []byte
	GetBalance(address crypto.BVMAddress) bn.Number
	GetToken() crypto2.Address
	GetBVMCode(address crypto.BVMAddress) acm.ByteCode
	GetWASMCode(address crypto.BVMAddress) acm.ByteCode
	Exists(address crypto.BVMAddress) bool
	GetBlockHash(blockNumber uint64) (binary.Word256, error)
}

type Stack

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

Not goroutine safe

func NewStack

func NewStack(initialCapacity uint64, maxCapacity uint64, gas *uint64, errSink errors.Sink) *Stack

func (*Stack) Dup

func (st *Stack) Dup(n int)

func (*Stack) Len

func (st *Stack) Len() int

func (*Stack) Peek

func (st *Stack) Peek() Word256

Not an opCode, costs no gas.

func (*Stack) Pop

func (st *Stack) Pop() Word256

func (*Stack) Pop64

func (st *Stack) Pop64() int64

func (*Stack) PopAddress

func (st *Stack) PopAddress() crypto.BVMAddress

func (*Stack) PopBigInt

func (st *Stack) PopBigInt() *big.Int

func (*Stack) PopBigIntSigned

func (st *Stack) PopBigIntSigned() *big.Int

func (*Stack) PopBytes

func (st *Stack) PopBytes() []byte

func (*Stack) PopU64

func (st *Stack) PopU64() uint64

func (*Stack) Print

func (st *Stack) Print(n int)

func (*Stack) Push

func (st *Stack) Push(d Word256)

func (*Stack) Push64

func (st *Stack) Push64(i int64)

func (*Stack) PushAddress

func (st *Stack) PushAddress(address crypto.BVMAddress)

func (*Stack) PushBigInt

func (st *Stack) PushBigInt(bigInt *big.Int) Word256

Pushes the bigInt as a Word256 encoding negative values in 32-byte twos complement and returns the encoded result

func (*Stack) PushBytes

func (st *Stack) PushBytes(bz []byte)

currently only called after sha3.Sha3

func (*Stack) PushU64

func (st *Stack) PushU64(i uint64)

func (*Stack) Swap

func (st *Stack) Swap(n int)

type State

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

func NewState

func NewState(st acmstate.ReaderWriter, blockHashGetter func(height uint64) []byte, cacheOptions ...acmstate.CacheOption) *State

func (*State) AddToBalance

func (st *State) AddToBalance(address crypto.BVMAddress, amount bn.Number)

func (*State) CreateAccount

func (st *State) CreateAccount(address crypto.BVMAddress)

func (*State) Error

func (st *State) Error() errors.CodedError

func (*State) Exists

func (st *State) Exists(address crypto.BVMAddress) bool

func (*State) GetBVMCode

func (st *State) GetBVMCode(address crypto.BVMAddress) acm.ByteCode

func (*State) GetBalance

func (st *State) GetBalance(address crypto.BVMAddress) bn.Number

func (*State) GetBlockHash

func (st *State) GetBlockHash(height uint64) (binary.Word256, error)

func (*State) GetStorage

func (st *State) GetStorage(address crypto.BVMAddress, key binary.Word256) []byte

func (*State) GetToken

func (st *State) GetToken() crypto2.Address

func (*State) GetWASMCode

func (st *State) GetWASMCode(address crypto.BVMAddress) acm.ByteCode

func (*State) InitCode

func (st *State) InitCode(address crypto.BVMAddress, code []byte)

func (*State) InitWASMCode

func (st *State) InitWASMCode(address crypto.BVMAddress, code []byte)

func (*State) NewCache

func (st *State) NewCache(cacheOptions ...acmstate.CacheOption) Interface

func (*State) PushError

func (st *State) PushError(err error)

Errors pushed to state may end up in TxExecutions and therefore the merkle state so it is essential that errors are deterministic and independent of the code path taken to execution (e.g. replay takes a different path to that of normal consensus reactor so stack traces may differ - as they may across architectures)

func (*State) RemoveAccount

func (st *State) RemoveAccount(address crypto.BVMAddress)

func (*State) SetStorage

func (st *State) SetStorage(address crypto.BVMAddress, key binary.Word256, value []byte)

func (*State) SubtractFromBalance

func (st *State) SubtractFromBalance(address crypto.BVMAddress, amount bn.Number)

func (*State) Sync

func (st *State) Sync() errors.CodedError

type VM

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

func NewVM

func NewVM(params Params, origin crypto.BVMAddress, nonce []byte, logger log.Logger, options ...func(*VM)) *VM

Create a new BVM instance. Nonce is required to be globally unique (nearly almost surely) to avoid duplicate addresses for BVM created Accounts. In Burrow we use TxHash for this but a random nonce or sequence number could be used.

func (*VM) Call

func (vm *VM) Call(callState Interface, eventSink EventSink, caller, callee crypto.BVMAddress, code,
	input []byte, value bn.Number, gas *uint64) (output []byte, err errors.CodedError)

Initiate an BVM call against the provided state pushing events to eventSink. code should contain the BVM bytecode, input the CallData (readable by CALLDATALOAD), value the amount of native token to transfer with the call an quantity metering the number of computational steps available to the execution according to the gas schedule.

func (*VM) Debugf

func (vm *VM) Debugf(format string, a ...interface{})

type Writer

type Writer interface {
	CreateAccount(address crypto.BVMAddress)
	InitCode(address crypto.BVMAddress, code []byte)
	InitWASMCode(address crypto.BVMAddress, code []byte)
	RemoveAccount(address crypto.BVMAddress)
	SetStorage(address crypto.BVMAddress, key binary.Word256, value []byte)
	AddToBalance(address crypto.BVMAddress, amount bn.Number)
	SubtractFromBalance(address crypto.BVMAddress, amount bn.Number)
}

Directories

Path Synopsis
asm
bc

Jump to

Keyboard shortcuts

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