Class/Object

sigmastate.interpreter

CErgoTreeEvaluator

Related Docs: object CErgoTreeEvaluator | package interpreter

Permalink

class CErgoTreeEvaluator extends ErgoTreeEvaluator

Implements a simple and fast direct-style interpreter of ErgoTrees.

### Motivation ErgoTree is a simple declarative intermediate representation for Ergo contracts. It is designed to be compact in serialized form and directly executable, i.e. no additional transformation is necessary before it can be efficiently executed.

This class implements a big-step recursive interpreter that works directly with ErgoTree HOAS. Because of this the evaluator is very simple and follows denotational semantics of ErgoTree (see https://ergoplatform.org/docs/ErgoTree.pdf). Or, the other way around, this implementation of ErgoTreeEvaluator is purely functional with immutable data structures and can be used as definition of ErgoTree's semantics.

### Implementation ErgoTreeEvaluator takes ErgoTree directly as it is deserialized as part of a transaction. No additional transformation is performed. ErgoTree is interpreted directly and all the intermediate data is stored in the runtime types. The runtime types are such types as sigma.Coll, sigma.SigmaProp, sigma.AvlTree, BigInt, etc. It also use immutable Map to keep current DataEnv of computed ValDefs, as result only addition is used from the map, and deletion is essentially a garbage collection.

### Performance Since this interpreter directly works with SigmaDsl types (Coll, BigInt, SigmaProp etc), it turns out to be very fast. Since it also does JIT style costing instead of AOT style, it is 5-6x faster than existing implementation.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. CErgoTreeEvaluator
  2. ErgoTreeEvaluator
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new CErgoTreeEvaluator(context: Context, constants: Seq[Constant[SType]], coster: CostAccumulator, profiler: Profiler, settings: EvalSettings)

    Permalink

    context

    Represents blockchain data context for ErgoTree evaluation

    constants

    Segregated constants from ErgoTree, to lookup them from ConstantPlaceholder evaluation.

    coster

    Accumulates computation costs.

    profiler

    Performs operations profiling and time measurements (if enabled in settings).

    settings

    Settings to be used during evaluation.

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def addCost(costInfo: OperationCostInfo[FixedCost]): Unit

    Permalink
    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  5. def addCost(costKind: FixedCost, opDesc: OperationDesc): Unit

    Permalink

    Adds the given cost to the coster.

    Adds the given cost to the coster. If tracing is enabled, associates the cost with the given operation.

    costKind

    kind of the cost to be added to coster

    opDesc

    operation descriptor to associate the cost with (when costTracingEnabled)

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  6. def addFixedCost(costInfo: OperationCostInfo[FixedCost])(block: ⇒ Unit): Unit

    Permalink
    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  7. def addFixedCost(costKind: FixedCost, opDesc: OperationDesc)(block: ⇒ Unit): Unit

    Permalink

    costKind

    kind of the cost to be added to coster

    opDesc

    the operation descriptor to associate the cost with (when costTracingEnabled)

    block

    operation executed under the given cost

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  8. def addSeqCost(costInfo: OperationCostInfo[PerItemCost])(block: () ⇒ Int): Unit

    Permalink

    Adds the cost to the coster.

    Adds the cost to the coster. See the other overload for details.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  9. def addSeqCost(costKind: PerItemCost, opDesc: OperationDesc)(block: () ⇒ Int): Unit

    Permalink

    Adds the cost to the coster.

    Adds the cost to the coster. If tracing is enabled, creates a new cost item with the given operation descriptor and cost kind. If time measuring is enabled also performs profiling.

    WARNING: The cost is accumulated AFTER the block is executed. Each usage of this method should be accompanied with a proof of why this cannot lead to unbounded execution (see all usages).

    costKind

    the cost descriptor to be used to compute the cost based on the actual number of items returned by the block

    opDesc

    the operation to associate the cost with (when costTracingEnabled)

    block

    operation executed under the given cost descriptors, returns the actual number of items processed

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  10. def addSeqCost[R](costInfo: OperationCostInfo[PerItemCost], nItems: Int)(block: () ⇒ R): R

    Permalink

    Adds the cost to the coster.

    Adds the cost to the coster. See the other overload for details.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  11. def addSeqCost[R](costKind: PerItemCost, nItems: Int, opDesc: OperationDesc)(block: () ⇒ R): R

    Permalink

    Adds the given cost to the coster.

    Adds the given cost to the coster. If tracing is enabled, creates a new cost item with the given operation.

    R

    result type of the operation

    costKind

    the cost to be added to coster for each item

    nItems

    the number of items

    opDesc

    the operation to associate the cost with (when costTracingEnabled)

    block

    operation executed under the given cost

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  12. def addSeqCostNoOp(costKind: PerItemCost, nItems: Int, opDesc: OperationDesc): Unit

    Permalink

    costKind

    the cost to be added to coster for each item

    nItems

    the number of items

    opDesc

    the operation to associate the cost with (when costTracingEnabled)

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  13. def addTypeBasedCost[R](costKind: TypeBasedCost, tpe: SType, opDesc: OperationDesc)(block: () ⇒ R): R

    Permalink

    Add the cost given by the cost descriptor and the type to the accumulator and associate it with this operation descriptor.

    Add the cost given by the cost descriptor and the type to the accumulator and associate it with this operation descriptor.

    costKind

    descriptor of the cost

    tpe

    specific type for which the cost should be computed by this descriptor (see costFunc method)

    opDesc

    operation which is associated with this cost

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  14. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  15. def clearTrace(): Unit1[CostItem]

    Permalink

    Clears the accumulated trace of this evaluator.

  16. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. val constants: Seq[Constant[SType]]

    Permalink

    Segregated constants from ErgoTree, to lookup them from ConstantPlaceholder evaluation.

    Segregated constants from ErgoTree, to lookup them from ConstantPlaceholder evaluation.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  18. def contains_eval(mc: MethodCall, tree: AvlTree, key: Coll[Byte], proof: Coll[Byte]): Boolean

    Permalink

    Implements evaluation of AvlTree.contains method call ErgoTree node.

    Implements evaluation of AvlTree.contains method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  19. val context: Context

    Permalink

    Represents blockchain data context for ErgoTree evaluation

    Represents blockchain data context for ErgoTree evaluation

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  20. val coster: CostAccumulator

    Permalink

    Accumulates computation costs.

    Accumulates computation costs.

    Attributes
    protected
  21. def createTreeVerifier(tree: AvlTree, proof: Coll[Byte]): AvlTreeVerifier

    Permalink

    Create an instance of AvlTreeVerifier for the given tree and proof.

    Create an instance of AvlTreeVerifier for the given tree and proof.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  22. def createVerifier(tree: AvlTree, proof: Coll[Byte]): CAvlTreeVerifier

    Permalink

    Creates sigma.eval.AvlTreeVerifier for the given tree and proof.

  23. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  25. def eval(env: DataEnv, exp: SValue): Any

    Permalink

    Evaluates the given expression in the given data environment.

  26. def evalWithCost[A](env: DataEnv, exp: SValue): JitEvalResult[A]

    Permalink

    Evaluates the given expression in the given data environment and accrue the cost into the coster of this evaluator.

    Evaluates the given expression in the given data environment and accrue the cost into the coster of this evaluator.

    returns

    the value of the expression and the total accumulated cost in the coster. The returned cost includes the initial cost accumulated in the coster prior to calling this method.

  27. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. def getAccumulatedCost: JitCost

    Permalink

    Returns currently accumulated JIT cost in this evaluator.

  29. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  30. def getCostTrace(): Seq[CostItem]

    Permalink

    Returns the currently accumulated trace of cost items in this evaluator.

    Returns the currently accumulated trace of cost items in this evaluator. A new array is allocated and returned, the evaluator state is unaffected.

  31. def getMany_eval(mc: MethodCall, tree: AvlTree, keys: Coll[Coll[Byte]], proof: Coll[Byte]): Coll[Option[Coll[Byte]]]

    Permalink

    Implements evaluation of AvlTree.getMany method call ErgoTree node.

    Implements evaluation of AvlTree.getMany method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  32. def get_eval(mc: MethodCall, tree: AvlTree, key: Coll[Byte], proof: Coll[Byte]): Option[Coll[Byte]]

    Permalink

    Implements evaluation of AvlTree.get method call ErgoTree node.

    Implements evaluation of AvlTree.get method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  33. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  34. def insert_eval(mc: MethodCall, tree: AvlTree, entries: KeyValueColl, proof: Coll[Byte]): Option[AvlTree]

    Permalink

    Implements evaluation of AvlTree.insert method call ErgoTree node.

    Implements evaluation of AvlTree.insert method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  35. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  36. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  37. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  38. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  39. val profiler: Profiler

    Permalink

    Performs operations profiling and time measurements (if enabled in settings).

    Performs operations profiling and time measurements (if enabled in settings).

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  40. def remove_eval(mc: MethodCall, tree: AvlTree, operations: Coll[Coll[Byte]], proof: Coll[Byte]): Option[AvlTree]

    Permalink

    Implements evaluation of AvlTree.remove method call ErgoTree node.

    Implements evaluation of AvlTree.remove method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  41. val settings: EvalSettings

    Permalink

    Settings to be used during evaluation.

    Settings to be used during evaluation.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  42. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  43. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  44. def update_eval(mc: MethodCall, tree: AvlTree, operations: KeyValueColl, proof: Coll[Byte]): Option[AvlTree]

    Permalink

    Implements evaluation of AvlTree.update method call ErgoTree node.

    Implements evaluation of AvlTree.update method call ErgoTree node.

    Definition Classes
    CErgoTreeEvaluatorErgoTreeEvaluator
  45. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ErgoTreeEvaluator

Inherited from AnyRef

Inherited from Any

Ungrouped