Documentation ¶
Index ¶
- Constants
- func CalcContractAddr(senderAddr gocrypto.Address, nonce []byte, chainID string) gocrypto.Address
- func DebugOpcodes(vm *VM)
- func DumpTokens(vm *VM)
- func ExecuteNativeContract(address crypto.BVMAddress, st Interface, caller crypto.BVMAddress, ...) ([]byte, errors.CodedError)
- func Is64BitOverflow(word Word256) bool
- func IsRegisteredNativeContract(address crypto.BVMAddress) bool
- func MemoryProvider(memoryProvider func(errors.Sink) Memory) func(*VM)
- func NewLogFreeEventSink(eventSink EventSink) *logFreeEventSink
- func StackOptions(callStackMaxDepth uint64, dataStackInitialCapacity uint64, ...) func(*VM)
- type BcEventSink
- type EventSink
- type FakeAppState
- func (fas *FakeAppState) GetAccount(addr crypto.BVMAddress) (*acm.Account, error)
- func (fas *FakeAppState) GetStorage(addr crypto.BVMAddress, key Word256) ([]byte, error)
- func (fas *FakeAppState) GetToken() goCrypto.Address
- func (fas *FakeAppState) RemoveAccount(address crypto.BVMAddress) error
- func (fas *FakeAppState) SetStorage(addr crypto.BVMAddress, key Word256, value []byte) error
- func (fas *FakeAppState) SetToken(token goCrypto.Address)
- func (fas *FakeAppState) UpdateAccount(account *acm.Account) error
- type Interface
- type Memory
- type NativeContract
- type Params
- type Reader
- type Stack
- func (st *Stack) Dup(n int)
- func (st *Stack) Len() int
- func (st *Stack) Peek() Word256
- func (st *Stack) Pop() Word256
- func (st *Stack) Pop64() int64
- func (st *Stack) PopAddress() crypto.BVMAddress
- func (st *Stack) PopBigInt() *big.Int
- func (st *Stack) PopBigIntSigned() *big.Int
- func (st *Stack) PopBytes() []byte
- func (st *Stack) PopU64() uint64
- func (st *Stack) Print(n int)
- func (st *Stack) Push(d Word256)
- func (st *Stack) Push64(i int64)
- func (st *Stack) PushAddress(address crypto.BVMAddress)
- func (st *Stack) PushBigInt(bigInt *big.Int) Word256
- func (st *Stack) PushBytes(bz []byte)
- func (st *Stack) PushU64(i uint64)
- func (st *Stack) Swap(n int)
- type State
- func (st *State) AddToBalance(address crypto.BVMAddress, amount bn.Number)
- func (st *State) CreateAccount(address crypto.BVMAddress)
- func (st *State) Error() errors.CodedError
- func (st *State) Exists(address crypto.BVMAddress) bool
- func (st *State) GetBVMCode(address crypto.BVMAddress) acm.ByteCode
- func (st *State) GetBalance(address crypto.BVMAddress) bn.Number
- func (st *State) GetBlockHash(height uint64) (binary.Word256, error)
- func (st *State) GetStorage(address crypto.BVMAddress, key binary.Word256) []byte
- func (st *State) GetToken() crypto2.Address
- func (st *State) GetWASMCode(address crypto.BVMAddress) acm.ByteCode
- func (st *State) InitCode(address crypto.BVMAddress, code []byte)
- func (st *State) InitWASMCode(address crypto.BVMAddress, code []byte)
- func (st *State) NewCache(cacheOptions ...acmstate.CacheOption) Interface
- func (st *State) PushError(err error)
- func (st *State) RemoveAccount(address crypto.BVMAddress)
- func (st *State) SetStorage(address crypto.BVMAddress, key binary.Word256, value []byte)
- func (st *State) SubtractFromBalance(address crypto.BVMAddress, amount bn.Number)
- func (st *State) Sync() errors.CodedError
- type VM
- type Writer
Constants ¶
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 // 太昂贵的操作了 )
const ( DataStackInitialCapacity = 1024 MaximumAllowedBlockLookBack = 256 )
const SignatureLength = 65
Variables ¶
This section is empty.
Functions ¶
func CalcContractAddr ¶
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 NewLogFreeEventSink ¶
func NewLogFreeEventSink(eventSink EventSink) *logFreeEventSink
Types ¶
type BcEventSink ¶
func NewBcEventSink ¶
func NewBcEventSink(Logger log.Logger, tags *[]interface{}) *BcEventSink
func (*BcEventSink) CallTransfer ¶
func (es *BcEventSink) CallTransfer(transfer *exec.TransferData, exception *errors.Exception) 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 NewDynamicMemory ¶
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 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 (*Stack) PopAddress ¶
func (st *Stack) PopAddress() crypto.BVMAddress
func (*Stack) PopBigIntSigned ¶
func (*Stack) PushAddress ¶
func (st *Stack) PushAddress(address crypto.BVMAddress)
func (*Stack) PushBigInt ¶
Pushes the bigInt as a Word256 encoding negative values in 32-byte twos complement and returns the encoded result
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) GetBVMCode ¶
func (st *State) GetBVMCode(address crypto.BVMAddress) acm.ByteCode
func (*State) GetBalance ¶
func (st *State) GetBalance(address crypto.BVMAddress) bn.Number
func (*State) GetStorage ¶
func (*State) GetWASMCode ¶
func (st *State) GetWASMCode(address crypto.BVMAddress) acm.ByteCode
func (*State) InitWASMCode ¶
func (st *State) InitWASMCode(address crypto.BVMAddress, code []byte)
func (*State) PushError ¶
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 (*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.
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) }