Documentation ¶
Index ¶
- Constants
- Variables
- func HasPermission(appState AppState, acc *Account, perm ptypes.PermFlag) bool
- func RegisterNativeContract(addr Word256, fn NativeContract) bool
- func RegisteredNativeContract(address Word256) bool
- func S256(x *big.Int) *big.Int
- func SNativeContracts() map[string]*SNativeContractDescription
- func SetDebug(d bool)
- func U256(x *big.Int) *big.Int
- func ValidPermN(n ptypes.PermFlag) bool
- type Account
- type AppState
- type Debug
- type ErrInvalidPermission
- type ErrPermission
- type FakeAppState
- func (fas *FakeAppState) CreateAccount(creator *Account) *Account
- func (fas *FakeAppState) GetAccount(addr Word256) *Account
- func (fas *FakeAppState) GetStorage(addr Word256, key Word256) Word256
- func (fas *FakeAppState) RemoveAccount(account *Account)
- func (fas *FakeAppState) SetStorage(addr Word256, key Word256, value Word256)
- func (fas *FakeAppState) UpdateAccount(account *Account)
- type Memory
- type NativeContract
- type Params
- type SNativeContractDescription
- func (contract *SNativeContractDescription) Address() abi.Address
- func (contract *SNativeContractDescription) AddressBytes() []byte
- func (contract *SNativeContractDescription) AddressWord256() Word256
- func (contract *SNativeContractDescription) Dispatch(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error)
- func (contract *SNativeContractDescription) FunctionByID(id abi.FunctionSelector) (*SNativeFunctionDescription, error)
- 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) PopBytes() []byte
- func (st *Stack) Print(n int)
- func (st *Stack) Push(d Word256)
- func (st *Stack) Push64(i int64)
- func (st *Stack) PushBytes(bz []byte)
- func (st *Stack) Swap(n int)
- type VM
Constants ¶
const ( GasSha3 int64 = 1 GasGetAccount int64 = 1 GasStorageUpdate int64 = 1 GasBaseOp int64 = 0 // TODO: make this 1 GasStackOp int64 = 1 GasEcRecover int64 = 1 GasSha256Word int64 = 1 GasSha256Base int64 = 1 GasRipemd160Word int64 = 1 GasRipemd160Base int64 = 1 GasIdentityWord int64 = 1 GasIdentityBase int64 = 1 )
Variables ¶
var ( ErrUnknownAddress = errors.New("Unknown address") ErrInsufficientBalance = errors.New("Insufficient balance") ErrInvalidJumpDest = errors.New("Invalid jump dest") ErrInsufficientGas = errors.New("Insufficient gas") ErrMemoryOutOfBounds = errors.New("Memory out of bounds") ErrCodeOutOfBounds = errors.New("Code out of bounds") ErrInputOutOfBounds = errors.New("Input out of bounds") ErrCallStackOverflow = errors.New("Call stack overflow") ErrCallStackUnderflow = errors.New("Call stack underflow") ErrDataStackOverflow = errors.New("Data stack overflow") ErrDataStackUnderflow = errors.New("Data stack underflow") ErrInvalidContract = errors.New("Invalid contract") ErrNativeContractCodeCopy = errors.New("Tried to copy native contract code") )
Functions ¶
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 RegisterNativeContract ¶
func RegisterNativeContract(addr Word256, fn NativeContract) bool
func RegisteredNativeContract ¶
func RegisteredNativeContract(address Word256) bool
func SNativeContracts ¶
func SNativeContracts() map[string]*SNativeContractDescription
Returns a map of all SNative contracts defined indexed by name
func ValidPermN ¶
Checks if a permission flag is valid (a known base chain or snative permission)
Types ¶
type Account ¶
type Account struct { Address Word256 Balance int64 Code []byte Nonce int64 Other interface{} // For holding all other data. Permissions ptypes.AccountPermissions }
type ErrInvalidPermission ¶
type ErrInvalidPermission struct { Address Word256 SNative string }
func (ErrInvalidPermission) Error ¶
func (e ErrInvalidPermission) Error() string
type ErrPermission ¶
type ErrPermission struct {
// contains filtered or unexported fields
}
func (ErrPermission) Error ¶
func (err ErrPermission) Error() string
type FakeAppState ¶
type FakeAppState struct {
// contains filtered or unexported fields
}
func (*FakeAppState) CreateAccount ¶
func (fas *FakeAppState) CreateAccount(creator *Account) *Account
func (*FakeAppState) GetAccount ¶
func (fas *FakeAppState) GetAccount(addr Word256) *Account
func (*FakeAppState) GetStorage ¶
func (fas *FakeAppState) GetStorage(addr Word256, key Word256) Word256
func (*FakeAppState) RemoveAccount ¶
func (fas *FakeAppState) RemoveAccount(account *Account)
func (*FakeAppState) SetStorage ¶
func (fas *FakeAppState) SetStorage(addr Word256, key Word256, value Word256)
func (*FakeAppState) UpdateAccount ¶
func (fas *FakeAppState) UpdateAccount(account *Account)
type Memory ¶ added in v0.17.0
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 int64) ([]byte, error) // 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 int64, value []byte) error // 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() int64 }
Interface for a bounded linear memory indexed by a single int64 parameter for each byte in the memory.
func DefaultDynamicMemoryProvider ¶ added in v0.17.0
func DefaultDynamicMemoryProvider() Memory
func NewDynamicMemory ¶ added in v0.17.0
type NativeContract ¶
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() abi.Address
We define the address of an SNative contact as the last 20 bytes of the sha3 hash of its name
func (*SNativeContractDescription) AddressBytes ¶
func (contract *SNativeContractDescription) AddressBytes() []byte
Get address as a byte slice
func (*SNativeContractDescription) AddressWord256 ¶
func (contract *SNativeContractDescription) AddressWord256() Word256
Get address as a left-padded Word256
func (*SNativeContractDescription) Dispatch ¶
func (contract *SNativeContractDescription) Dispatch(appState AppState, caller *Account, args []byte, gas *int64) (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.FunctionSelector) (*SNativeFunctionDescription, error)
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 (used to form signature) Args []abi.Arg // Function return value Return abi.Return // Permissions required to call function PermFlag ptypes.PermFlag // Native function to which calls will be dispatched when a containing // contract is called with a FunctionSelector matching this NativeContract F NativeContract }
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) ID ¶
func (function *SNativeFunctionDescription) ID() abi.FunctionSelector
Get function calling identifier FunctionSelector
func (*SNativeFunctionDescription) NArgs ¶
func (function *SNativeFunctionDescription) NArgs() int
Get number of function arguments
func (*SNativeFunctionDescription) Signature ¶
func (function *SNativeFunctionDescription) Signature() string
Get function signature
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
func (*VM) Call ¶
func (vm *VM) Call(caller, callee *Account, code, input []byte, value int64, gas *int64) (output []byte, err error)
CONTRACT appState 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 error. 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
func (*VM) DelegateCall ¶
func (vm *VM) DelegateCall(caller, callee *Account, code, input []byte, value int64, gas *int64) (output []byte, err error)
DelegateCall is executed by the DELEGATECALL opcode, introduced as off Ethereum Homestead. The intent of delegate call is to run the code of the callee in the storage context of the caller; while preserving the original caller to the previous callee. Different to the normal CALL or CALLCODE, the value does not need to be transferred to the callee.