Documentation ¶
Index ¶
- Constants
- func DebugOpcodes(vm *VM)
- func DumpTokens(vm *VM)
- func EnsurePermission(st Interface, address crypto.Address, perm permission.PermFlag)
- func ExecuteNativeContract(address crypto.Address, st Interface, caller crypto.Address, input []byte, ...) ([]byte, errors.CodedError)
- func HasPermission(st Interface, address crypto.Address, perm permission.PermFlag) bool
- func Is64BitOverflow(word Word256) bool
- func IsRegisteredNativeContract(address crypto.Address) bool
- func MemoryProvider(memoryProvider func(errors.Sink) Memory) func(*VM)
- func NewLogFreeEventSink(eventSink EventSink) *logFreeEventSink
- func NewNoopEventSink() *noopEventSink
- func RegisterNativeContract(address crypto.Address, fn NativeContract) bool
- func SNativeContracts() map[string]*SNativeContractDescription
- func StackOptions(callStackMaxDepth uint64, dataStackInitialCapacity uint64, ...) func(*VM)
- type EventSink
- type FakeAppState
- func (fas *FakeAppState) GetAccount(addr crypto.Address) (*acm.Account, error)
- func (fas *FakeAppState) GetStorage(addr crypto.Address, key Word256) (Word256, error)
- func (fas *FakeAppState) RemoveAccount(address crypto.Address) error
- func (fas *FakeAppState) SetStorage(addr crypto.Address, key Word256, value Word256) error
- func (fas *FakeAppState) UpdateAccount(account *acm.Account) error
- type Interface
- type Memory
- type NativeContract
- type Params
- type Reader
- type SNativeContractDescription
- func (contract *SNativeContractDescription) Address() (address crypto.Address)
- func (contract *SNativeContractDescription) Dispatch(st Interface, caller crypto.Address, args []byte, gas *uint64, ...) (output []byte, err error)
- func (contract *SNativeContractDescription) FunctionByID(id abi.FunctionID) (*SNativeFunctionDescription, errors.CodedError)
- func (contract *SNativeContractDescription) FunctionByName(name string) (*SNativeFunctionDescription, error)
- func (contract *SNativeContractDescription) Functions() []*SNativeFunctionDescription
- type SNativeFunctionDescription
- 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.Address
- 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.Address)
- 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) AddRole(address crypto.Address, role string) bool
- func (st *State) AddToBalance(address crypto.Address, amount uint64)
- func (st *State) CreateAccount(address crypto.Address)
- func (st *State) Error() errors.CodedError
- func (st *State) Exists(address crypto.Address) bool
- func (st *State) GetBalance(address crypto.Address) uint64
- func (st *State) GetBlockHash(height uint64) (binary.Word256, error)
- func (st *State) GetCode(address crypto.Address) acm.Bytecode
- func (st *State) GetPermissions(address crypto.Address) permission.AccountPermissions
- func (st *State) GetSequence(address crypto.Address) uint64
- func (st *State) GetStorage(address crypto.Address, key binary.Word256) binary.Word256
- func (st *State) InitCode(address crypto.Address, code []byte)
- func (st *State) NewCache(cacheOptions ...acmstate.CacheOption) Interface
- func (st *State) PushError(err error)
- func (st *State) RemoveAccount(address crypto.Address)
- func (st *State) RemoveRole(address crypto.Address, role string) bool
- func (st *State) SetPermission(address crypto.Address, permFlag permission.PermFlag, value bool)
- func (st *State) SetStorage(address crypto.Address, key, value binary.Word256)
- func (st *State) SubtractFromBalance(address crypto.Address, amount uint64)
- func (st *State) Sync() errors.CodedError
- func (st *State) UnsetPermission(address crypto.Address, permFlag permission.PermFlag)
- type VM
- type Writer
Constants ¶
const ( GasSha3 uint64 = 1 GasGetAccount uint64 = 1 GasStorageUpdate uint64 = 1 GasCreateAccount uint64 = 1 GasBaseOp uint64 = 0 // TODO: make this 1 GasStackOp uint64 = 1 GasEcRecover uint64 = 1 GasSha256Word uint64 = 1 GasSha256Base uint64 = 1 GasRipemd160Word uint64 = 1 GasRipemd160Base uint64 = 1 GasIdentityWord uint64 = 1 GasIdentityBase uint64 = 1 )
const ( DataStackInitialCapacity = 1024 MaximumAllowedBlockLookBack = 256 )
Variables ¶
This section is empty.
Functions ¶
func DebugOpcodes ¶
func DebugOpcodes(vm *VM)
func DumpTokens ¶
func DumpTokens(vm *VM)
func EnsurePermission ¶ added in v0.23.0
func EnsurePermission(st Interface, address crypto.Address, perm permission.PermFlag)
func ExecuteNativeContract ¶ added in v0.19.0
func HasPermission ¶
CONTRACT: it is the duty of the contract writer to call known permissions we do not convey if a permission is not set (unlike in state/execution, where we guarantee HasPermission is called on known permissions and panics else) If the perm is not defined in the acc nor set by default in GlobalPermissions, this function returns false.
func Is64BitOverflow ¶
func Is64BitOverflow(word Word256) bool
func IsRegisteredNativeContract ¶ added in v0.19.0
func NewLogFreeEventSink ¶ added in v0.23.0
func NewLogFreeEventSink(eventSink EventSink) *logFreeEventSink
func NewNoopEventSink ¶ added in v0.23.0
func NewNoopEventSink() *noopEventSink
func RegisterNativeContract ¶
func RegisterNativeContract(address crypto.Address, fn NativeContract) bool
func SNativeContracts ¶
func SNativeContracts() map[string]*SNativeContractDescription
Returns a map of all SNative contracts defined indexed by name
Types ¶
type FakeAppState ¶
type FakeAppState struct {
// contains filtered or unexported fields
}
func (*FakeAppState) GetAccount ¶
func (*FakeAppState) GetStorage ¶
func (fas *FakeAppState) GetStorage(addr crypto.Address, key Word256) (Word256, error)
func (*FakeAppState) RemoveAccount ¶
func (fas *FakeAppState) RemoveAccount(address crypto.Address) error
func (*FakeAppState) SetStorage ¶
func (fas *FakeAppState) SetStorage(addr crypto.Address, key Word256, value Word256) error
func (*FakeAppState) UpdateAccount ¶
func (fas *FakeAppState) UpdateAccount(account *acm.Account) error
type Interface ¶ added in v0.23.0
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 ¶ added in v0.23.0
type Reader interface { GetStorage(address crypto.Address, key binary.Word256) binary.Word256 GetBalance(address crypto.Address) uint64 GetPermissions(address crypto.Address) permission.AccountPermissions GetCode(address crypto.Address) acm.Bytecode GetSequence(address crypto.Address) uint64 Exists(address crypto.Address) bool // GetBlockHash returns hash of the specific block GetBlockHash(blockNumber uint64) (binary.Word256, error) }
type SNativeContractDescription ¶
type SNativeContractDescription struct { // Comment describing purpose of SNative contract and reason for assembling // the particular functions Comment string // Name of the SNative contract Name string // contains filtered or unexported fields }
Metadata for SNative contract. Acts as a call target from the EVM. Can be used to generate bindings in a smart contract languages.
func NewSNativeContract ¶
func NewSNativeContract(comment, name string, functions ...*SNativeFunctionDescription) *SNativeContractDescription
Create a new SNative contract description object by passing a comment, name and a list of member functions descriptions
func (*SNativeContractDescription) Address ¶
func (contract *SNativeContractDescription) Address() (address crypto.Address)
We define the address of an SNative contact as the last 20 bytes of the sha3 hash of its name
func (*SNativeContractDescription) Dispatch ¶
func (contract *SNativeContractDescription) Dispatch(st Interface, caller crypto.Address, args []byte, gas *uint64, logger *logging.Logger) (output []byte, err error)
This function is designed to be called from the EVM once a SNative contract has been selected. It is also placed in a registry by registerSNativeContracts So it can be looked up by SNative address
func (*SNativeContractDescription) FunctionByID ¶
func (contract *SNativeContractDescription) FunctionByID(id abi.FunctionID) (*SNativeFunctionDescription, errors.CodedError)
Get function by calling identifier FunctionSelector
func (*SNativeContractDescription) FunctionByName ¶
func (contract *SNativeContractDescription) FunctionByName(name string) (*SNativeFunctionDescription, error)
Get function by name
func (*SNativeContractDescription) Functions ¶
func (contract *SNativeContractDescription) Functions() []*SNativeFunctionDescription
Get functions in order of declaration
type SNativeFunctionDescription ¶
type SNativeFunctionDescription struct { // Comment describing function's purpose, parameters, and return value Comment string // Function name (used to form signature) Name string // Function arguments Arguments reflect.Type // Function return values Returns reflect.Type // The abi Abi abi.FunctionSpec // Permissions required to call function PermFlag permission.PermFlag // Native function to which calls will be dispatched when a containing F func(stateWriter Interface, caller crypto.Address, gas *uint64, logger *logging.Logger, v interface{}) (interface{}, error) }
Metadata for SNative functions. Act as call targets for the EVM when collected into an SNativeContractDescription. Can be used to generate bindings in a smart contract languages.
func (*SNativeFunctionDescription) NArgs ¶
func (function *SNativeFunctionDescription) NArgs() int
Get number of function arguments
func (*SNativeFunctionDescription) Signature ¶
func (function *SNativeFunctionDescription) Signature() string
Get function signature
func (*SNativeFunctionDescription) String ¶ added in v0.23.0
func (fn *SNativeFunctionDescription) String() string
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Not goroutine safe
func (*Stack) PopAddress ¶ added in v0.23.0
func (*Stack) PopBigIntSigned ¶
func (*Stack) PushAddress ¶ added in v0.23.0
func (*Stack) PushBigInt ¶
Pushes the bigInt as a Word256 encoding negative values in 32-byte twos complement and returns the encoded result
type State ¶ added in v0.23.0
type State struct {
// contains filtered or unexported fields
}
func NewState ¶ added in v0.23.0
func NewState(st acmstate.ReaderWriter, blockHashGetter func(height uint64) []byte, cacheOptions ...acmstate.CacheOption) *State
func (*State) AddToBalance ¶ added in v0.23.0
func (*State) CreateAccount ¶ added in v0.23.0
func (*State) Error ¶ added in v0.23.0
func (st *State) Error() errors.CodedError
func (*State) GetBalance ¶ added in v0.23.0
func (*State) GetBlockHash ¶ added in v0.24.0
func (*State) GetPermissions ¶ added in v0.23.0
func (st *State) GetPermissions(address crypto.Address) permission.AccountPermissions
func (*State) GetSequence ¶ added in v0.23.0
func (*State) GetStorage ¶ added in v0.23.0
func (*State) NewCache ¶ added in v0.23.0
func (st *State) NewCache(cacheOptions ...acmstate.CacheOption) Interface
func (*State) RemoveAccount ¶ added in v0.23.0
func (*State) RemoveRole ¶ added in v0.23.0
func (*State) SetPermission ¶ added in v0.23.0
func (*State) SetStorage ¶ added in v0.23.0
func (*State) SubtractFromBalance ¶ added in v0.23.0
func (*State) Sync ¶ added in v0.23.0
func (st *State) Sync() errors.CodedError
func (*State) UnsetPermission ¶ added in v0.23.0
func (st *State) UnsetPermission(address crypto.Address, permFlag permission.PermFlag)
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
func (*VM) Call ¶
func (vm *VM) Call(callState Interface, eventSink EventSink, caller, callee crypto.Address, code, input []byte, value uint64, gas *uint64) (output []byte, err errors.CodedError)
CONTRACT state is aware of caller and callee, so we can just mutate them. CONTRACT code and input are not mutated. CONTRACT returned 'ret' is a new compact slice. value: To be transferred from caller to callee. Refunded upon errors.CodedError. gas: Available gas. No refunds for gas. code: May be nil, since the CALL opcode may be used to send value from contracts to accounts
type Writer ¶ added in v0.23.0
type Writer interface { CreateAccount(address crypto.Address) InitCode(address crypto.Address, code []byte) RemoveAccount(address crypto.Address) SetStorage(address crypto.Address, key, value binary.Word256) AddToBalance(address crypto.Address, amount uint64) SubtractFromBalance(address crypto.Address, amount uint64) SetPermission(address crypto.Address, permFlag permission.PermFlag, value bool) UnsetPermission(address crypto.Address, permFlag permission.PermFlag) AddRole(address crypto.Address, role string) bool RemoveRole(address crypto.Address, role string) bool }