Skip to content

Commit 334149b

Browse files
committed
documented how propBytes can be compared with propositionBytes
1 parent 17f00a4 commit 334149b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/LangSpec.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,21 @@ trait SigmaProp {
480480
* 2. new ErgoTree created with with ErgoTree.DefaultHeader, EmptyConstant and SigmaPropConstant as the root
481481
*
482482
* Thus obtained ErgoTree is serialized using DefaultSerializer and compared with `box.propositionBytes`.
483+
* Here, propBytes uses very specific ErgoTree with header == 0, and hence ErgoTree.version == 0.
484+
* However, `box.propositionBytes`, contain bytes of ErgoTree from `box`, and version of that
485+
* tree depends on how the `box` was created.
486+
* A better way to compare `box.propositionBytes` and `prop.propBytes` is to use the following code:
487+
* ```
488+
* val propBytes = prop.propBytes
489+
* val treeBytes = box.propositionBytes
490+
* if (treeBytes(0) == 0) {
491+
* treeBytes == propBytes
492+
* } else {
493+
* // offset = 1 + <number of VLQ encoded bytes to store propositionBytes.size>
494+
* val offset = if (propositionBytes.size > 127) 3 else 2
495+
* propBytes.slice(1, propBytes.size) == propositionBytes.slice(offset, propositionBytes.size)
496+
* }
497+
* ```
483498
*/
484499
def propBytes: Coll[Byte]
485500

0 commit comments

Comments
 (0)