Documentation ¶
Index ¶
- Constants
- func SetDebug(isDebug bool)
- type Account
- type Address
- type Blockchain
- type Cache
- func (cache *Cache) AddLog(log *Log)
- func (cache *Cache) Exist(addr Address) bool
- func (cache *Cache) GetAccount(addr Address) Account
- func (cache *Cache) GetNonce(address Address) uint64
- func (cache *Cache) GetStorage(address Address, key core.Word256) []byte
- func (cache *Cache) HasSuicide(addr Address) bool
- func (cache *Cache) SetStorage(address Address, key core.Word256, value []byte)
- func (cache *Cache) Suicide(address Address) error
- func (cache *Cache) Sync()
- func (cache *Cache) UpdateAccount(account Account) error
- type Context
- type DB
- type EVM
- type Log
- type Memory
- type OpCode
- type Stack
- func (st *Stack) Dup(n int)
- func (st *Stack) Len() int
- func (st *Stack) Peek() core.Word256
- func (st *Stack) PeekBigInt() *big.Int
- func (st *Stack) Pop() core.Word256
- func (st *Stack) PopAddress() Address
- func (st *Stack) PopBigInt() *big.Int
- func (st *Stack) PopBytes() []byte
- func (st *Stack) PopUint64() uint64
- func (st *Stack) Print(n int)
- func (st *Stack) Push(word core.Word256)
- func (st *Stack) PushAddress(address Address)
- func (st *Stack) PushBigInt(bigInt *big.Int)
- func (st *Stack) PushBytes(bz []byte)
- func (st *Stack) PushUint64(i uint64)
- func (st *Stack) Swap(n int)
- type WriteBatch
Constants ¶
const ( DefaultStackCapacity uint64 = 1024 DefaultMaxStackCapacity uint64 = 32 * 1024 MaxCodeSize int = 24576 )
Here defines some default stack capacity variables
const (
SHA3 = 0x20
)
20s: SHA3
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Account ¶
type Account interface { GetAddress() Address GetBalance() uint64 AddBalance(balance uint64) error SubBalance(balance uint64) error GetCode() []byte SetCode(code []byte) // GetCodeHash return the hash of account code, please return [32]byte, // and return [32]byte{0, ..., 0} if code is empty GetCodeHash() []byte GetNonce() uint64 SetNonce(nonce uint64) // Suicide will suicide an account Suicide() HasSuicide() bool Copy() Account }
Account describe what function that account should provide
type Address ¶
type Address interface { // It would be better if length = 32 // 1. Add zero in left if length < 32 // 2. Remove left byte if length > 32(however, this may be harm) Bytes() []byte }
Address describe what functions that an Address implementation should provide
type Blockchain ¶
type Blockchain interface { // GetBlockHash return ZeroWord256 if num > 256 or num > max block height GetBlockHash(num uint64) []byte // CreateAddress will be called by CREATE Opcode CreateAddress(caller Address, nonce uint64) Address // Create2Address will be called by CREATE2 Opcode Create2Address(caller Address, salt, code []byte) Address // Note: NewAccount will create a default account in Blockchain service, // but please do not append the account into db here NewAccount(address Address) Account // BytesToAddress provide a way convert bytes(normally [32]byte) to Address BytesToAddress(bytes []byte) Address }
Blockchain describe what function that blockchain system shoudld provide to support the evm
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache cache on a DB. It will simulate operate on a db, and sync to db if necessary. Note: It's not thread safety because now it will only be used in one thread.
func (*Cache) GetAccount ¶
GetAccount return the account of address
func (*Cache) GetStorage ¶
GetStorage returns the key of an address if exist, else returns an error
func (*Cache) HasSuicide ¶
HasSuicide return if an account has suicide
func (*Cache) SetStorage ¶
SetStorage set the storage of address NOTE: Set value to zero to remove. How should i understand this? TODO: Review this
func (*Cache) UpdateAccount ¶
UpdateAccount set account
type Context ¶
type Context struct { Input []byte Value uint64 Gas *uint64 BlockHeight uint64 BlockTime int64 Difficulty uint64 GasLimit uint64 GasPrice uint64 CoinBase []byte }
Context defines some context
type DB ¶
type DB interface { // Exist return if the account exist // Note: if account is suicided, return true Exist(address Address) bool // GetStorage return a default account if unexist GetAccount(address Address) Account // Note: GetStorage return nil if key is not exist GetStorage(address Address, key []byte) (value []byte) NewWriteBatch() WriteBatch }
DB describe what function that db should provide to support the evm
type EVM ¶
type EVM struct {
// contains filtered or unexported fields
}
EVM is the evm
func (*EVM) CallWithoutTransfer ¶
CallWithoutTransfer is call without transfer, and it will sync change to db if error is nil
type Log ¶
type Log struct { // Consensus field Address Address `json:"address"` // list of topics provided by the contract. Topics []core.Word256 `json:"topics"` // supplied by the contract, usually ABI-encoded Data []byte `json:"data"` // Derived fields, so the database should record the context to support these fields BlockNumber uint64 `json:"blockNumber"` // hash of the transaction TxHash []byte `json:"transactionHash"` // index of the transaction in the block TxIndex uint `json:"transactionIndex"` // hash of the block in which the transaction was included BlockHash []byte `json:"blockHash"` // index of the log in the block Index uint `json:"logIndex"` }
Log is the log of evm
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) (value []byte, gasCost uint64) // 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) (gasCost uint64) // 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 Len() uint64 CalMemGas(offset, length uint64) (uint64, error) }
Memory is the interface for a bounded linear memory indexed by a single *big.Int parameter for each byte in the memory.
func DefaultDynamicMemoryProvider ¶
DefaultDynamicMemoryProvider return to default DynamicMemory
func NewDynamicMemory ¶
NewDynamicMemory is the constrcutor of 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 OpCode ¶
type OpCode byte
OpCode is the type of operation code
0s: Stop and Arithmetic Operations
10s: Comparison & Bitwise Logic Opreations
const ( ADDRESS OpCode = 0x30 + iota BALANCE ORIGIN CALLER CALLVALUE CALLDATALOAD CALLDATASIZE CALLDATACOPY CODESIZE CODECOPY GASPRICE EXTCODESIZE EXTCODECOPY RETURNDATASIZE RETURNDATACOPY EXTCODEHASH )
30s: Environmental Information
const ( BLOCKHASH OpCode = 0x40 + iota COINBASE TIMESTAMP NUMBER DIFFICULTY GASLIMIT CHAINID SELFBALANCE )
40s: Block Information
const ( POP OpCode = 0x50 + iota MLOAD MSTORE MSTORE8 SLOAD SSTORE JUMP JUMPI PC MSIZE GAS JUMPDEST )
50s: Stack, Memory, Storage and Flow Operations
const ( PUSH1 OpCode = 0x60 + iota PUSH2 PUSH3 PUSH4 PUSH5 PUSH6 PUSH7 PUSH8 PUSH9 PUSH10 PUSH11 PUSH12 PUSH13 PUSH14 PUSH15 PUSH16 PUSH17 PUSH18 PUSH19 PUSH20 PUSH21 PUSH22 PUSH23 PUSH24 PUSH25 PUSH26 PUSH27 PUSH28 PUSH29 PUSH30 PUSH31 PUSH32 )
60s & 70s: Push Operations
const ( DUP1 OpCode = 0x80 + iota DUP2 DUP3 DUP4 DUP5 DUP6 DUP7 DUP8 DUP9 DUP10 DUP11 DUP12 DUP13 DUP14 DUP15 DUP16 )
80s: Duplication Operations
const ( SWAP1 OpCode = 0x90 + iota SWAP2 SWAP3 SWAP4 SWAP5 SWAP6 SWAP7 SWAP8 SWAP9 SWAP10 SWAP11 SWAP12 SWAP13 SWAP14 SWAP15 SWAP16 )
90s: Exchange Operations
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack is the stack that support the running of evm Note: The stack is not thread safety
func NewStack ¶
func NewStack(initialCapacity uint64, maxCapacity uint64, gas *uint64, errSink errors.Sink, toAddressFunc func(bytes []byte) Address) *Stack
NewStack is the constructor of Stack
func (*Stack) PeekBigInt ¶
PeekBigInt peek big int from stack
func (*Stack) PushAddress ¶
PushAddress push address into stack
func (*Stack) PushBigInt ¶
PushBigInt push the bigInt as a core.Word256 encoding negative values in 32-byte twos complement and returns the encoded result
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package abi implements the Ethereum ABI (Application Binary Interface).
|
Package abi implements the Ethereum ABI (Application Binary Interface). |
blake2b
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb.
|
Package blake2b implements the BLAKE2b hash algorithm defined by RFC 7693 and the extendable output function (XOF) BLAKE2Xb. |
bn256
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
|
Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. |
bn256/cloudflare
Package bn256 implements a particular bilinear group at the 128-bit security level.
|
Package bn256 implements a particular bilinear group at the 128-bit security level. |
bn256/google
Package bn256 implements a particular bilinear group.
|
Package bn256 implements a particular bilinear group. |
secp256k1
Package secp256k1 wraps the bitcoin secp256k1 C library.
|
Package secp256k1 wraps the bitcoin secp256k1 C library. |
Package rlp implements the RLP serialization format.
|
Package rlp implements the RLP serialization format. |