Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteNative(app *APP)
- func GasBlockHash(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasCheckSign(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasContractStorageGet(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasContractStoragePureGet(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasEcrecover(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetBalance(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetCoinbase(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetGasLimit(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetNumber(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetTimestamp(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetTxGasPrice(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasGetTxOrigin(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasIssue(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasNotify(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasNow(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasSelfDestruct(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStorageDel(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStorageGet(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStoragePureGet(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStoragePureSetBytes(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStoragePureSetString(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStorageSet(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasStorageSetBytes(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasTokenAddress(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasTokenBalance(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasTransfer(eng *Engine, index int64, args []uint64) (uint64, error)
- func GasTransferToken(eng *Engine, index int64, args []uint64) (uint64, error)
- func GoExit(cvm *C.vm_t, cstatus C.int32_t)
- func GoFunc(cvm *C.vm_t, cname *C.char, cArgn C.int32_t, cArgs *C.uint64_t) uint64
- func GoGrowMemory(cvm *C.vm_t, pages C.int32_t)
- func GoPanic(cvm *C.vm_t, cmsg *C.char)
- func GoRevert(cvm *C.vm_t, cmsg *C.char)
- func IsWasmContract(code []byte) bool
- func MakeGasLog(n uint64) gasFunc
- func ParseInitArgsAndCode(data []byte) ([]byte, []byte, error)
- func ParseInput(rinput []byte) (string, string, error)
- func RefreshApp(app *APP)
- func RemoveCache(name string)
- func SafeAdd(x, y uint64) (uint64, bool)
- func SafeMul(x, y uint64) (uint64, bool)
- func StopAots()
- func ToWordSize(size uint64) uint64
- func TrimBuffToString(bytes []byte) string
- type APP
- func (app *APP) Clone(eng *Engine) *APP
- func (app *APP) Close()
- func (app *APP) GetEntryFunction() int64
- func (app *APP) GetExportFunction(fnName string) int64
- func (app *APP) GetStartFunction() int64
- func (app *APP) Printf(f string, args ...interface{})
- func (app *APP) Run(action, args string) (uint64, error)
- func (app *APP) RunF(fnIndex int64, args ...uint64) (uint64, error)
- func (app *APP) String() string
- type AccountRef
- type AotService
- type Args
- type Contract
- func (c *Contract) Address() types.Address
- func (c *Contract) AsDelegate() *Contract
- func (c *Contract) Caller() types.Address
- func (c *Contract) SetCallCode(addr []byte, hash []byte, code []byte)
- func (c *Contract) SetCode(hash types.Hash, code []byte)
- func (c *Contract) UseGas(gas uint64) (ok bool)
- func (c *Contract) Value() *big.Int
- type ContractInfo
- type ContractRef
- type Engine
- func (e *Engine) AddFee(fee uint64)
- func (eng *Engine) AppByName(name string) *APP
- func (e *Engine) CalFee(realCost uint64, currentFee uint64)
- func (eng *Engine) Caller() []byte
- func (eng *Engine) EnvTable() *EnvTable
- func (eng *Engine) Gas() uint64
- func (eng *Engine) GasUsed() uint64
- func (e *Engine) GetFee() uint64
- func (eng *Engine) IsTracing() bool
- func (eng *Engine) Logger() log.Logger
- func (eng *Engine) NewApp(name string, code []byte, debug bool) (*APP, error)
- func (eng *Engine) PopAppFrame() (*APP, int)
- func (eng *Engine) PushAppFrame(app *APP) (int, error)
- func (eng *Engine) RemoveCache(name string)
- func (eng *Engine) Run(app *APP, input []byte) (uint64, error)
- func (eng *Engine) RunningAppFrame() (*APP, int)
- func (e *Engine) SetFee(fee uint64)
- func (eng *Engine) SetTrace(isTrace bool)
- func (eng *Engine) Trace(msg string, v ...interface{})
- func (eng *Engine) UseGas(cost uint64) bool
- type EnvFunc
- type EnvTable
- type Error
- type GasTable
- type Native
- type Param
- type Result
- type StateDB
- type TCAbort
- type TCAssert
- type TCAtof32
- type TCAtof64
- type TCAtoi
- type TCAtoi64
- type TCBigIntAdd
- type TCBigIntCmp
- type TCBigIntDiv
- type TCBigIntMod
- type TCBigIntMul
- type TCBigIntSub
- type TCBigIntToInt64
- type TCCallContract
- type TCCalloc
- type TCDelegateCallContract
- type TCExit
- type TCFree
- type TCGasLeft
- type TCGetMsgData
- type TCGetMsgGas
- type TCGetMsgSender
- type TCGetMsgSign
- type TCGetSelfAddress
- type TCI64toa
- type TCIsHexAddress
- type TCItoa
- type TCJSONGetAddress
- type TCJSONGetBigInt
- type TCJSONGetDouble
- type TCJSONGetFloat
- type TCJSONGetInt
- type TCJSONGetInt64
- type TCJSONGetObject
- type TCJSONGetString
- type TCJSONNewObject
- type TCJSONParse
- type TCJSONPutAddress
- type TCJSONPutBigInt
- type TCJSONPutDouble
- type TCJSONPutFloat
- type TCJSONPutInt
- type TCJSONPutInt64
- type TCJSONPutObject
- type TCJSONPutString
- type TCJSONToString
- type TCKeccak256
- type TCMalloc
- type TCMemcmp
- type TCMemcpy
- type TCMemmove
- type TCMemset
- type TCPayable
- type TCPrints
- type TCPrintsl
- type TCRealloc
- type TCRequire
- type TCRequireWithMsg
- type TCRevert
- type TCRevertWithMsg
- type TCRipemd160
- type TCSha256
- type TCStrcmp
- type TCStrconcat
- type TCStrcpy
- type TCStrlen
Constants ¶
const ( GasQuickStep uint64 = 2 GasFastestStep uint64 = 3 GasFastStep uint64 = 5 GasMidStep uint64 = 8 GasSlowStep uint64 = 10 GasExtStep uint64 = 20 GasReturn uint64 = 0 GasStop uint64 = 0 GasContractByte uint64 = 200 )
const ( GasLimitBoundDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations. MinGasLimit uint64 = 5000 // Minimum the gas limit may ever be. GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block. MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis. ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction. SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added. CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero. CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior. TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions. TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions. TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions. QuadCoeffDiv uint64 = 512 // Divisor for the quadratic particle of the memory cost equation. SstoreSetGas uint64 = 5000 // Once per SLOAD operation. LogDataGas uint64 = 8 // Per byte in a LOG* operation's data. CallStipend uint64 = 2300 // Free gas given at beginning of call. Sha3Gas uint64 = 30 // Once per SHA3 operation. Sha3WordGas uint64 = 6 // Once per word of the SHA3 operation's data. SstoreResetGas uint64 = 5000 // Once per SSTORE operation if the zeroness changes from zero. SstoreClearGas uint64 = 5000 // Once per SSTORE operation if the zeroness doesn't change. SstoreRefundGas uint64 = 15000 // Once per SSTORE operation if the zeroness changes to zero. JumpdestGas uint64 = 1 // Refunded gas, once per SSTORE operation if the zeroness changes to zero. EpochDuration uint64 = 30000 // Duration between proof-of-work epochs. CallGas uint64 = 40 // Once per CALL operation & message call transaction. CreateDataGas uint64 = 200 // CallCreateDepth uint64 = 1024 // Maximum depth of call/create stack. ExpGas uint64 = 10 // Once per EXP instruction LogGas uint64 = 375 // Per LOG* operation. CopyGas uint64 = 3 // StackLimit uint64 = 1024 // Maximum size of VM stack allowed. TierStepGas uint64 = 0 // Once per operation, for a selection of them. LogTopicGas uint64 = 375 // Multiplied by the * of the LOG*, per LOG transaction. e.g. LOG0 incurs 0 * c_txLogTopicGas, LOG4 incurs 4 * c_txLogTopicGas. CreateGas uint64 = 32000 // Once per CREATE operation & contract-creation transaction. SuicideRefundGas uint64 = 24000 // Refunded following a suicide operation. MemoryGas uint64 = 3 // Times the address of the (highest referenced byte in memory + 1). NOTE: referencing happens on read, write and in instructions such as RETURN and CALL. TxDataNonZeroGas uint64 = 68 // Per byte of data attached to a transaction that is not equal to zero. NOTE: Not payable on data of calls between transactions. MaxCodeSize = 1024 * 1024 // Maximum bytecode to permit for a wasm contract 1M PrintWordGas uint64 = 1 MemWordGas uint64 = 1 IssueGas uint64 = 4000 HashSetGas uint64 = 96 AddrSetGas uint64 = 60 JsonGas uint64 = 500 EcrecoverGas uint64 = 3000 // Elliptic curve sender recovery gas price Sha256BaseGas uint64 = 60 // Base price for a SHA256 operation Sha256PerWordGas uint64 = 12 // Per-word price for a SHA256 operation Ripemd160BaseGas uint64 = 600 // Base price for a RIPEMD160 operation Ripemd160PerWordGas uint64 = 120 // Per-word price for a RIPEMD160 operation IdentityBaseGas uint64 = 15 // Base price for a data copy operation IdentityPerWordGas uint64 = 3 // Per-work price for a data copy operation ModExpQuadCoeffDiv uint64 = 20 // Divisor for the quadratic particle of the big int modular exponentiation Bn256AddGas uint64 = 500 // Gas needed for an elliptic curve addition Bn256ScalarMulGas uint64 = 40000 // Gas needed for an elliptic curve scalar multiplication Bn256PairingBaseGas uint64 = 100000 // Base price for an elliptic curve pairing check Bn256PairingPerPointGas uint64 = 80000 // Per-point price for an elliptic curve pairing check )
const (
/*
For c/c++:
char * thunderchain_main(char *action, char *arg);
*/
APPEntry = "thunderchain_main"
)
const TCVM_AOTS_ENABLE = "TCVM_AOTS_ENABLE"
Env Variable
const TCVM_AOTS_KEEP_CSOURCE = "TCVM_AOTS_KEEP_CSOURCE"
const TCVM_AOTS_ROOT = "TCVM_AOTS_ROOT"
Variables ¶
var ( ErrNoAppEntry = fmt.Errorf("no AppEntry(%s)", APPEntry) ErrAppInput = fmt.Errorf("invalid app input") WasmBytes = []byte{0x00, 0x61, 0x73, 0x6d} )
var ( ErrOverFrame = errors.New("engine: recursive overflow") ErrEmptyFrame = errors.New("engine: empty frame") ErrInitEngine = errors.New("engine: init failed") ErrMemoryGet = errors.New("memory get* failed") ErrMemorySet = errors.New("memory set* failed") ErrGasOverflow = errors.New("gas overflow (uint64)") ErrContractAbort = errors.New("contract abort") ErrInvalidApiArgs = errors.New("invalid api args") ErrBalanceNotEnough = errors.New("insufficient balance in api") ErrContractNotPayable = errors.New("contract not payable") ErrInvalidEnvArgs = errors.New("invalid env args") ErrMallocMemory = errors.New("malloc() failed in api") ErrCallDepth = errors.New("vm: max call depth exceeded") ErrContractNoCode = errors.New("vm: contract no code") ErrCodeStoreOutOfGas = errors.New("vm: contract creation code storage out of gas") ErrExecutionReverted = errors.New("vm: execution reverted") ErrMaxCodeSizeExceeded = errors.New("vm: max code size exceeded") ErrInsufficientBalance = errors.New("vm: insufficient balance in transfer") ErrContractAddressCollision = errors.New("vm: contract address collision") ErrReturnDataOutOfBounds = errors.New("vm: return data out of bounds") ErrTraceLimitReached = errors.New("vm: the number of logs reached the specified limit") ErrWriteProtection = errors.New("vm: write protection") ErrContractRequire = errors.New("vm: contract require fail") ErrContractAssert = errors.New("vm: contract assert fail") ErrOutOfGas = errors.New("vm: out of gas") ErrExecutionExit = errors.New("vm: execution exit") )
var ( DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations. GenesisDifficulty = big.NewInt(131072) // Difficulty of the Genesis block. MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. TsVersion1Sec = big.NewInt(1541289540) //2018-11-03 23:59:00 UTC TsVersion2Sec = big.NewInt(1543536000) //2018-11-30 00:00:00 UTC SignParam = big.NewInt(30261) TargetGasLimit = GenesisGasLimit // The artificial target )
var (
AppCache *sync.Map
)
var GasTableEIP158 = GasTable{
ExtcodeSize: 700,
ExtcodeCopy: 700,
ExpByte: 50,
Balance: 400,
SLoad: 200,
Calls: 700,
Suicide: 5000,
CreateBySuicide: 25000,
}
var THUNDERCHAINID = SignParam.Int64()
const THUNDERCHAINID = 30261
Functions ¶
func GasContractStorageGet ¶
func GasContractStoragePureGet ¶ added in v0.2.1
func GasGetTimestamp ¶
func GasGetTxGasPrice ¶
func GasSelfDestruct ¶
func GasStoragePureGet ¶
func GasStoragePureSetBytes ¶
func GasStoragePureSetString ¶
func GasStorageSetBytes ¶
func GasTokenAddress ¶
func GasTokenBalance ¶
func GasTransferToken ¶
func MakeGasLog ¶
func MakeGasLog(n uint64) gasFunc
func RemoveCache ¶ added in v0.3.6
func RemoveCache(name string)
func ToWordSize ¶
toWordSize returns the ceiled word size required for memory expansion.
Types ¶
type APP ¶
type APP struct { Name string Debug bool Module *wasm.Module VM *exec.VM VmProcess *exec.Process Eng *Engine IsPreRun bool EntryFunc string // contains filtered or unexported fields }
func (*APP) GetEntryFunction ¶
GetEntryFunction Get Function Index for APPEntry
func (*APP) GetExportFunction ¶
GetExportFunction Get Function Index of specific fnName
func (*APP) GetStartFunction ¶
GetStartFunction Get Function Index of Start function.
type AccountRef ¶
AccountRef implements ContractRef.
Account references are used during EVM initialisation and it's primary use is to fetch addresses. Removing this object proves difficult because of the cached jump destinations which are fetched from the parent contract (i.e. the caller), which is a ContractRef.
func (AccountRef) Address ¶
func (ar AccountRef) Address() types.Address
Address casts AccountRef to a Address
type AotService ¶ added in v0.3.6
type AotService struct {
// contains filtered or unexported fields
}
AotService --
func NewAotService ¶ added in v0.3.6
func NewAotService(path string, keepSrouce bool) *AotService
NewAotService --
type Contract ¶
type Contract struct { // CallerAddress is the result of the caller which initialised this // contract. However when the "call method" is delegated this value // needs to be initialised to that of the caller's caller. CallerAddress types.Address Self ContractRef Code []byte CodeHash types.Hash CodeAddr *types.Address Input []byte Gas uint64 DelegateCall bool CreateCall bool // contains filtered or unexported fields }
Contract represents an ethereum contract in the state database. It contains the the contract code, calling arguments. Contract implements ContractRef
func NewContract ¶
NewContract returns a new contract environment for the execution of EVM.
func NewContractInner ¶
func NewContractInner(caller ContractRef, object ContractRef, value *big.Int, gas uint64) *Contract
NewContract returns a new contract environment for the execution of call-contract.
func (*Contract) AsDelegate ¶
AsDelegate sets the contract to be a delegate call and returns the current contract (for chaining calls)
func (*Contract) Caller ¶
Caller returns the caller of the contract.
Caller will recursively call caller when the contract is a delegate call, including that of caller's caller.
func (*Contract) SetCallCode ¶
SetCallCode sets the code of the contract and address of the backing data object
type ContractInfo ¶ added in v0.3.6
type ContractInfo struct { Type string `json:"t"` Path string `json:"p"` MD5 [16]byte `json:"md5"` Err string `json:"e"` }
ContractInfo --
type ContractRef ¶
ContractRef is a reference to the contract's backing object
type Engine ¶
type Engine struct { State StateDB AppCache *sync.Map Env *EnvTable AppFrames []*APP FrameIndex int Contract *Contract Ctx interface{} // contains filtered or unexported fields }
func (*Engine) PopAppFrame ¶
func (*Engine) RemoveCache ¶ added in v0.3.6
func (*Engine) RunningAppFrame ¶
type EnvTable ¶
type EnvTable struct { Exports wasm.SectionExports Module wasm.Module // contains filtered or unexported fields }
EnvTable stand for env's info which we will register for wasm module before it run.
func (*EnvTable) GetFuncByName ¶
GetFuncByName Get env function by name
func (*EnvTable) RegisterFunc ¶
RegisterFunc Register env function for wasm module
func (*EnvTable) RegisterGlobal ¶
RegisterGlobal Register env global for wasm module
type GasTable ¶
type GasTable struct { ExtcodeSize uint64 ExtcodeCopy uint64 ExpByte uint64 Balance uint64 SLoad uint64 Calls uint64 Suicide uint64 // CreateBySuicide occurs when the // refunded account is one that does // not exist. This logic is similar // to call. May be left nil. Nil means // not charged. CreateBySuicide uint64 }
GasTable organizes gas prices for different phases.
type Native ¶ added in v0.3.6
type Native struct {
// contains filtered or unexported fields
}
Native --
type TCBigIntAdd ¶
type TCBigIntAdd struct{}
type TCBigIntCmp ¶
type TCBigIntCmp struct{}
type TCBigIntDiv ¶
type TCBigIntDiv struct{}
type TCBigIntMod ¶
type TCBigIntMod struct{}
type TCBigIntMul ¶
type TCBigIntMul struct{}
type TCBigIntSub ¶
type TCBigIntSub struct{}
type TCBigIntToInt64 ¶
type TCBigIntToInt64 struct{}
type TCCallContract ¶
type TCCallContract struct{}
---------------------------------------------
type TCDelegateCallContract ¶
type TCDelegateCallContract struct{}
type TCGetMsgData ¶
type TCGetMsgData struct{}
type TCGetMsgGas ¶
type TCGetMsgGas struct{}
type TCGetMsgSender ¶
type TCGetMsgSender struct{}
type TCGetMsgSign ¶
type TCGetMsgSign struct{}
type TCGetSelfAddress ¶
type TCGetSelfAddress struct{}
type TCIsHexAddress ¶
type TCIsHexAddress struct{}
type TCJSONGetAddress ¶
type TCJSONGetAddress struct{}
type TCJSONGetBigInt ¶
type TCJSONGetBigInt struct{}
type TCJSONGetDouble ¶
type TCJSONGetDouble struct{}
type TCJSONGetFloat ¶
type TCJSONGetFloat struct{}
type TCJSONGetInt ¶
type TCJSONGetInt struct{}
type TCJSONGetInt64 ¶
type TCJSONGetInt64 struct{}
type TCJSONGetObject ¶
type TCJSONGetObject struct{}
type TCJSONGetString ¶
type TCJSONGetString struct{}
type TCJSONNewObject ¶
type TCJSONNewObject struct{}
type TCJSONParse ¶
type TCJSONParse struct{}
type TCJSONPutAddress ¶
type TCJSONPutAddress struct{}
type TCJSONPutBigInt ¶
type TCJSONPutBigInt struct{}
type TCJSONPutDouble ¶
type TCJSONPutDouble struct{}
type TCJSONPutFloat ¶
type TCJSONPutFloat struct{}
type TCJSONPutInt ¶
type TCJSONPutInt struct{}
type TCJSONPutInt64 ¶
type TCJSONPutInt64 struct{}
type TCJSONPutObject ¶
type TCJSONPutObject struct{}
type TCJSONPutString ¶
type TCJSONPutString struct{}
type TCJSONToString ¶
type TCJSONToString struct{}
type TCKeccak256 ¶
type TCKeccak256 struct{}
type TCRequireWithMsg ¶
type TCRequireWithMsg struct{}
type TCRevertWithMsg ¶
type TCRevertWithMsg struct{}
type TCRipemd160 ¶
type TCRipemd160 struct{}
type TCStrconcat ¶
type TCStrconcat struct{}