Class/Object

sigmastate.serialization

ErgoTreeSerializer

Related Docs: object ErgoTreeSerializer | package serialization

Permalink

class ErgoTreeSerializer extends AnyRef

Rationale for soft-forkable ErgoTree serialization. There are 2 points:

1) we can make size bit obligatory, i.e. always save total size of script body (in this case we don't need size bit in the header). This will allow to always skip right number of bytes in case of any exception (including ValidationException) thrown during deserialization and produce UnparsedErgoTree. The decision about soft-fork can be done later. But is looks like this is not necessary if we do as described below.

2) HeaderVersionCheck: we can also strictly check during deserialization the content of the script against version number in the header. Thus if the header have vS, then script is allowed to have instructions from versions from v1 to vS. On a node vN, N > S, this should also be enforced, i.e. vN node will reject scripts as invalid if the script has vS in header and vS+1 instruction in body.

Keeping this in mind, if we have a vN node and a script with vS in its header then: During script deserialization: 1) if vN >= vS then the node knows all the instructions and should check that only instructions up to vS are used in the script. It either parses successfully or throws MalformedScriptException. If during the process some unknown instruction is encountered (i.e. ValidationException is thrown), this cannot be a soft-fork, because vN >= vS guarantees that all instructions are known, thus the script is malformed.

2) if vN < vS then the vN node is expecting unknown instructions. If the script is parsed successfully, then vN subset of the language is used and script is accepted for execution else if ValidationException is thrown then UnparsedErgoTree is created, delaying decision about soft-fork until stateful validation. if bodySize is stored then script body is skipped and whole TX deserialization continues. otherwise we cannot skip the body which leads to whole TX to be rejected (CannotSkipScriptException) else if some other exception is thrown then the whole TX is rejected due to said exception.

In the stateful context: if vN >= vS then we can execute script, but we do additional check if vS > the current version of protocol (vP) then the script is rejected as invalid because its version exceeds the current consensus version of the protocol else the script can be executed if vN < vS then if we have Right(tree) the script is executed if Left(UnparsedErgoTree()) then check soft fork and either execute or throw

Proposition: CannotSkipScriptException can only happen on < 10% of the nodes, which is safe for consensus. Proof. If follows from the fact that vN >= vS nodes will reject the script until new vP is upgraded to vS, which means the majority has upgraded to at least vS Thus, before vP is upgraded to vS, majority reject (either because they cannot parse, or because vP is not actualized) after that majority accept (however old nodes still reject but they are < 10%) End of proof.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ErgoTreeSerializer
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ErgoTreeSerializer()

    Permalink

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 asInstanceOf[T0]: T0

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @throws( ... )
  6. def deserializeErgoTree(r: SigmaByteReader, maxTreeSizeBytes: Int): ErgoTree

    Permalink
  7. def deserializeErgoTree(bytes: Array[Byte]): ErgoTree

    Permalink

    Default deserialization of ErgoTree (should be inverse to serializeErgoTree).

    Default deserialization of ErgoTree (should be inverse to serializeErgoTree). Doesn't apply any transformations to the parsed tree.

  8. def deserializeHeaderWithTreeBytes(r: SigmaByteReader): (Byte, Option[Int], IndexedSeq[Constant[SType]], Array[Byte])

    Permalink

    Deserialize header and constant sections, but output the rest of the bytes as separate array.

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate()
  13. final def isInstanceOf[T0]: Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate()
  17. def serializeErgoTree(ergoTree: ErgoTree): Array[Byte]

    Permalink

    Default serialization of ErgoTree.

    Default serialization of ErgoTree. Doesn't apply any transformations and guarantee to preserve original structure after deserialization.

  18. def substituteConstants(scriptBytes: Array[Byte], positions: Array[Int], newVals: Array[Value[SType]])(implicit vs: SigmaValidationSettings): Array[Byte]

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  21. final def wait(arg0: Long, arg1: Int): Unit

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(): Unit

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

Deprecated Value Members

  1. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @Deprecated @deprecated @throws( classOf[java.lang.Throwable] )
    Deprecated

    (Since version ) see corresponding Javadoc for more information.

Inherited from AnyRef

Inherited from Any

Ungrouped