From 8d73c15de2f3ff6fb99c76f00eb08d9d1043d976 Mon Sep 17 00:00:00 2001 From: Marek Date: Thu, 21 Nov 2024 17:05:47 +0100 Subject: [PATCH 1/2] Update the reference Sapling treestate Zebra's treestate serialization differs from `zcashd` in the following way: `zcashd` omits the serialization of empty trailing ommers, while Zebra doesn't. This means that `zcashd` serializes the Sapling treestate for height 419_201 as 019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d9310002000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d Whereas Zebra serializes it as 019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931001f000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d0000000000000000000000000000000000000000000000000000000000 Serialization Format ==================== The serialized treestate consists of optional, hex-encoded, 32-byte hashes. If the hash is not present, it is serialized as byte 0, i.e., `0x00`. If the hash is present, it is prefixed by byte 1, i.e. `0x01`. The first two hashes in the serialized treestate are the treestate's left and right leaves. These are followed by the serialized length of the vector of ommers. This length is serialized as 1, 3, 5, or 9 bytes. If the length is less than 253, it is serialized as a single byte. The length is then followed by the serialized ommers. We can now parse the first string, produced by `zcashd`: - `0119eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931` is the serialized left leaf, - `00` is the serialized right leaf, - `02` is the serialized length of the vector of ommers, - `00` is the serialized first ommer, - `0150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d` is the serialized second ommer. And the second one, produced by Zebra: - `0119eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931` is the serialized left leaf, - `00` is the serialized right leaf, - `1f` is the serialized length of the vector of ommers, - `00` is the serialized first ommer, - `0150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d` is the serialized second ommer - `0000000000000000000000000000000000000000000000000000000000` are the remaining 29 serialized ommers. Note that both serializations represent the same treestate. --- zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt b/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt index c6cd1b532c0..1fbaf976145 100644 --- a/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt +++ b/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt @@ -1 +1 @@ -019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d9310002000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d \ No newline at end of file +019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931001f000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d0000000000000000000000000000000000000000000000000000000000 From 7c1a61783318e19c0fa8f68778f4542ae44119a4 Mon Sep 17 00:00:00 2001 From: Marek Date: Fri, 22 Nov 2024 02:36:33 +0100 Subject: [PATCH 2/2] Remove a new line char --- zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt b/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt index 1fbaf976145..7ce9416012a 100644 --- a/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt +++ b/zebra-test/src/vectors/sapling-treestate-main-0-419-201.txt @@ -1 +1 @@ -019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931001f000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d0000000000000000000000000000000000000000000000000000000000 +019eb30778ddeea84c72e69e07a1689f3c8def3dc0a1939f0edcbe47279069d931001f000150715810d52caf35471d10feb487213fbd95ff209122225b7b65d27a7fb1a44d0000000000000000000000000000000000000000000000000000000000 \ No newline at end of file