Documentation ¶
Index ¶
- Constants
- Variables
- func AssembleString(text string) ([]byte, error)
- func Check(program []byte, params EvalParams) (cost int, err error)
- func Disassemble(program []byte) (text string, err error)
- func Eval(program []byte, params EvalParams) (pass bool, err error)
- func HashProgram(program []byte) crypto.Digest
- func OpCost(opName string) int
- func OpDoc(opName string) string
- func OpDocExtra(opName string) string
- func OpImmediateNote(opName string) string
- func OpSize(opName string) int
- func TypeNameDescription(typeName string) string
- type EvalParams
- type GlobalField
- type Msg
- type OpGroup
- type OpSpec
- type OpStream
- func (ops *OpStream) Arg(val uint64) error
- func (ops *OpStream) Assemble(fin io.Reader) error
- func (ops *OpStream) ByteLiteral(val []byte) error
- func (ops *OpStream) Bytec(constIndex uint) error
- func (ops *OpStream) Bytes() (program []byte, err error)
- func (ops *OpStream) Global(val uint64) error
- func (ops *OpStream) Gtxn(gid, val uint64) error
- func (ops *OpStream) Intc(constIndex uint) error
- func (ops *OpStream) ReferToLabel(sourceLine, pc int, label string)
- func (ops *OpStream) SetLabelHere(label string) error
- func (ops *OpStream) Txn(val uint64) error
- func (ops *OpStream) Uint(val uint64) error
- type PanicError
- type Program
- type StackType
- type TxnField
- type Writer
Constants ¶
const AssemblerDefaultVersion = 1
AssemblerDefaultVersion what version of code do we emit by default
const EvalMaxArgs = 255
EvalMaxArgs is the maximum number of arguments to an LSig
const EvalMaxScratchSize = 255
EvalMaxScratchSize is the maximum number of scratch slots.
const EvalMaxVersion = 1
EvalMaxVersion is the max version we can interpret and run
const MaxStackDepth = 1000
MaxStackDepth should move to consensus params
Variables ¶
var AccountFieldNames = []string{
"Balance",
}
AccountFieldNames are arguments to the 'account' opcode
var GlobalFieldDocs map[string]string
GlobalFieldDocs are notes on fields available in `global`
var GlobalFieldNames []string
GlobalFieldNames are arguments to the 'global' opcode
var GlobalFieldTypes []StackType
GlobalFieldTypes is StackUint64 StackBytes in parallel with GlobalFieldNames
var OpGroupList = []OpGroup{ {"Arithmetic", []string{"sha256", "keccak256", "sha512_256", "ed25519verify", "+", "-", "/", "*", "<", ">", "<=", ">=", "&&", "||", "==", "!=", "!", "len", "itob", "btoi", "%", "|", "&", "^", "~", "mulw"}}, {"Loading Values", []string{"intcblock", "intc", "intc_0", "intc_1", "intc_2", "intc_3", "bytecblock", "bytec", "bytec_0", "bytec_1", "bytec_2", "bytec_3", "arg", "arg_0", "arg_1", "arg_2", "arg_3", "txn", "gtxn", "global", "load", "store"}}, {"Flow Control", []string{"err", "bnz", "pop", "dup"}}, }
OpGroupList is groupings of ops for documentation purposes.
var OpSpecs = []OpSpec{ {0x00, "err", opErr, nil, nil}, {0x01, "sha256", opSHA256, oneBytes, oneBytes}, {0x02, "keccak256", opKeccak256, oneBytes, oneBytes}, {0x03, "sha512_256", opSHA512_256, oneBytes, oneBytes}, {0x04, "ed25519verify", opEd25519verify, threeBytes, oneInt}, {0x08, "+", opPlus, twoInts, oneInt}, {0x09, "-", opMinus, twoInts, oneInt}, {0x0a, "/", opDiv, twoInts, oneInt}, {0x0b, "*", opMul, twoInts, oneInt}, {0x0c, "<", opLt, twoInts, oneInt}, {0x0d, ">", opGt, twoInts, oneInt}, {0x0e, "<=", opLe, twoInts, oneInt}, {0x0f, ">=", opGe, twoInts, oneInt}, {0x10, "&&", opAnd, twoInts, oneInt}, {0x11, "||", opOr, twoInts, oneInt}, {0x12, "==", opEq, twoAny, oneInt}, {0x13, "!=", opNeq, twoAny, oneInt}, {0x14, "!", opNot, oneInt, oneInt}, {0x15, "len", opLen, oneBytes, oneInt}, {0x16, "itob", opItob, oneInt, oneBytes}, {0x17, "btoi", opBtoi, oneBytes, oneInt}, {0x18, "%", opModulo, twoInts, oneInt}, {0x19, "|", opBitOr, twoInts, oneInt}, {0x1a, "&", opBitAnd, twoInts, oneInt}, {0x1b, "^", opBitXor, twoInts, oneInt}, {0x1c, "~", opBitNot, oneInt, oneInt}, {0x1d, "mulw", opMulw, twoInts, twoInts}, {0x20, "intcblock", opIntConstBlock, nil, nil}, {0x21, "intc", opIntConstLoad, nil, oneInt}, {0x22, "intc_0", opIntConst0, nil, oneInt}, {0x23, "intc_1", opIntConst1, nil, oneInt}, {0x24, "intc_2", opIntConst2, nil, oneInt}, {0x25, "intc_3", opIntConst3, nil, oneInt}, {0x26, "bytecblock", opByteConstBlock, nil, nil}, {0x27, "bytec", opByteConstLoad, nil, oneBytes}, {0x28, "bytec_0", opByteConst0, nil, oneBytes}, {0x29, "bytec_1", opByteConst1, nil, oneBytes}, {0x2a, "bytec_2", opByteConst2, nil, oneBytes}, {0x2b, "bytec_3", opByteConst3, nil, oneBytes}, {0x2c, "arg", opArg, nil, oneBytes}, {0x2d, "arg_0", opArg0, nil, oneBytes}, {0x2e, "arg_1", opArg1, nil, oneBytes}, {0x2f, "arg_2", opArg2, nil, oneBytes}, {0x30, "arg_3", opArg3, nil, oneBytes}, {0x31, "txn", opTxn, nil, oneAny}, {0x32, "global", opGlobal, nil, oneAny}, {0x33, "gtxn", opGtxn, nil, oneAny}, {0x34, "load", opLoad, nil, oneAny}, {0x35, "store", opStore, oneAny, nil}, {0x40, "bnz", opBnz, oneInt, nil}, {0x48, "pop", opPop, oneAny, nil}, {0x49, "dup", opDup, oneAny, twoAny}, }
OpSpecs is the table of operations that can be assembled and evaluated.
Any changes should be reflected in README.md which serves as the language spec.
var TxnFieldDocs map[string]string
TxnFieldDocs are notes on fields available by `txn` and `gtxn`
var TxnFieldNames []string
TxnFieldNames are arguments to the 'txn' and 'txnById' opcodes
var TxnFieldTypes []StackType
TxnFieldTypes is StackBytes or StackUint64 parallel to TxnFieldNames
var TxnTypeNames = []string{ string(protocol.UnknownTx), string(protocol.PaymentTx), string(protocol.KeyRegistrationTx), string(protocol.AssetConfigTx), string(protocol.AssetTransferTx), string(protocol.AssetFreezeTx), }
TxnTypeNames is the values of Txn.Type in enum order
Functions ¶
func AssembleString ¶
AssembleString takes an entire program in a string and assembles it to bytecode
func Check ¶
func Check(program []byte, params EvalParams) (cost int, err error)
Check should be faster than Eval. Returns 'cost' which is an estimate of relative execution time.
func Disassemble ¶
Disassemble produces a text form of program bytes. AssembleString(Disassemble()) should result in the same program bytes.
func Eval ¶
func Eval(program []byte, params EvalParams) (pass bool, err error)
Eval checks to see if a transaction passes logic A program passes succesfully if it finishes with one int element on the stack that is non-zero.
func HashProgram ¶
HashProgram takes program bytes and returns the Digest This Digest can be used as an Address for a logic controlled account.
func OpDocExtra ¶
OpDocExtra returns extra documentation text about an op
func OpImmediateNote ¶
OpImmediateNote returns a short string about immediate data which follows the op byte
func TypeNameDescription ¶
TypeNameDescription returns extra description about a low level protocol transaction Type string
Types ¶
type EvalParams ¶
type EvalParams struct { // the transaction being evaluated Txn *transactions.SignedTxn Proto *config.ConsensusParams Trace io.Writer TxnGroup []transactions.SignedTxnWithAD // GroupIndex should point to Txn within TxnGroup GroupIndex int FirstValidTimeStamp uint64 Logger logging.Logger }
EvalParams contains data that comes into condition evaluation.
type GlobalField ¶
type GlobalField int
GlobalField is an enum for `global` opcode
const ( // MinTxnFee ConsensusParams.MinTxnFee MinTxnFee GlobalField = iota // MinBalance ConsensusParams.MinBalance MinBalance // MaxTxnLife ConsensusParams.MaxTxnLife MaxTxnLife // ZeroAddress [32]byte{0...} ZeroAddress // GroupSize len(txn group) GroupSize )
func (GlobalField) String ¶
func (i GlobalField) String() string
type Msg ¶
type Msg struct { ProgramHash crypto.Digest `codec:"p"` Data []byte `codec:"d"` // contains filtered or unexported fields }
Msg is data meant to be signed and then verified with the ed25519verify opcode.
type OpGroup ¶
OpGroup is a grouping of ops for documentation purposes. e.g. "Arithmetic", ["+", "-", ...]
type OpSpec ¶
type OpSpec struct { Opcode byte Name string Args []StackType // what gets popped from the stack Returns []StackType // what gets pushed to the stack // contains filtered or unexported fields }
OpSpec defines one byte opcode
type OpStream ¶
type OpStream struct { Out bytes.Buffer Version uint64 Trace io.Writer // contains filtered or unexported fields }
OpStream is destination for program and scratch space
func (*OpStream) ByteLiteral ¶
ByteLiteral writes opcodes and data for loading a []byte literal Values are accumulated so that they can be put into a bytecblock
func (*OpStream) ReferToLabel ¶
ReferToLabel records an opcode label refence to resolve later
func (*OpStream) SetLabelHere ¶
SetLabelHere inserts a label reference to point to the next instruction
type PanicError ¶
type PanicError struct { PanicValue interface{} StackTrace string }
PanicError wraps a recover() catching a panic()
func (PanicError) Error ¶
func (pe PanicError) Error() string
type Program ¶
type Program []byte
Program is byte code to be interpreted for validating transactions.
type StackType ¶
type StackType byte
StackType describes the type of a value on the operand stack
const StackAny StackType = 1
StackAny in an OpSpec shows that the op pops or yield any type
const StackBytes StackType = 3
StackBytes in an OpSpec shows that the op pops or yields a []byte
const StackNone StackType = 0
StackNone in an OpSpec shows that the op pops or yields nothing
const StackUint64 StackType = 2
StackUint64 in an OpSpec shows that the op pops or yields a uint64
type TxnField ¶
type TxnField int
TxnField is an enum type for `txn` and `gtxn`
const ( // Sender Transaction.Sender Sender TxnField = iota // Fee Transaction.Fee Fee // FirstValid Transaction.FirstValid FirstValid // FirstValidTime Block[Transaction.FirstValid].TimeStamp FirstValidTime // LastValid Transaction.LastValid LastValid // Note Transaction.Note Note // Lease Transaction.Lease Lease // Receiver Transaction.Receiver Receiver // Amount Transaction.Amount Amount // CloseRemainderTo Transaction.CloseRemainderTo CloseRemainderTo // VotePK Transaction.VotePK VotePK // SelectionPK Transaction.SelectionPK SelectionPK // VoteFirst Transaction.VoteFirst VoteFirst // VoteLast Transaction.VoteLast VoteLast // VoteKeyDilution Transaction.VoteKeyDilution VoteKeyDilution // Type Transaction.Type Type // TypeEnum int(Transaction.Type) TypeEnum // XferAsset Transaction.XferAsset XferAsset // AssetAmount Transaction.AssetAmount AssetAmount // AssetSender Transaction.AssetSender AssetSender // AssetReceiver Transaction.AssetReceiver AssetReceiver // AssetCloseTo Transaction.AssetCloseTo AssetCloseTo // GroupIndex i for txngroup[i] == Txn GroupIndex // TxID Transaction.ID() TxID )