Class/Object

sigmastate.interpreter

ErgoTreeEvaluator

Related Docs: object ErgoTreeEvaluator | package interpreter

Permalink

class ErgoTreeEvaluator extends AnyRef

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 special.collection.Coll, special.sigma.SigmaProp, special.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
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ErgoTreeEvaluator
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ErgoTreeEvaluator(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. final def addCost(costInfo: OperationCostInfo[FixedCost]): Unit

    Permalink
    Annotations
    @inline()
  5. final 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)

  6. final def addFixedCost(costInfo: OperationCostInfo[FixedCost])(block: ⇒ Unit): Unit

    Permalink
    Annotations
    @inline()
  7. final def addFixedCost(costKind: FixedCost, opDesc: OperationDesc)(block: ⇒ Unit): 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

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

    block

    operation executed under the given cost

  8. final 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.

  9. final 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

  10. final 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.

    Annotations
    @inline()
  11. final 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

  12. final def addSeqCostNoOp(costKind: PerItemCost, nItems: Int, opDesc: OperationDesc): Unit

    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.

    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)

  13. final 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

    Annotations
    @inline()
  14. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  15. def clone(): AnyRef

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

    Permalink

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

  17. val context: Context

    Permalink

    Represents blockchain data context for ErgoTree evaluation

  18. val coster: CostAccumulator

    Permalink

    Accumulates computation costs.

    Accumulates computation costs.

    Attributes
    protected
  19. final def eq(arg0: AnyRef): Boolean

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

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

    Permalink

    Evaluates the given expression in the given data environment.

  22. def evalWithCost(env: DataEnv, exp: SValue): (Any, Int)

    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.

  23. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  24. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  25. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  26. final def isInstanceOf[T0]: Boolean

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

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

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

    Permalink
    Definition Classes
    AnyRef
  30. val profiler: Profiler

    Permalink

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

  31. val settings: EvalSettings

    Permalink

    Settings to be used during evaluation.

  32. final def synchronized[T0](arg0: ⇒ T0): T0

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

    Permalink
    Definition Classes
    AnyRef → Any
  34. final def wait(): Unit

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

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

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

Inherited from AnyRef

Inherited from Any

Ungrouped