ZcashFoundation / zebra

Zcash - Financial Privacy in Rust 🦓
https://zfnd.org/zebra/
Apache License 2.0
412 stars 106 forks source link

fix(test): Update the reference Sapling treestate #9051

Closed upbqdn closed 40 minutes ago

upbqdn commented 12 hours ago

Motivation

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

Specifications & References

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:

And the second one, produced by Zebra:

Note that both serializations represent the same treestate.

Solution

Replace the first string by the second one in the test vector.

Tests

Follow-up Work

PR Author's Checklist

PR Reviewer's Checklist

mpguerra commented 2 hours ago

@mergify refresh

mergify[bot] commented 2 hours ago

refresh

✅ Pull request refreshed

gustavovalverde commented 1 hour ago

@mergify refresh

mergify[bot] commented 1 hour ago

refresh

✅ Pull request refreshed

mpguerra commented 1 hour ago

@mergify queue

mergify[bot] commented 1 hour ago

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at *5f2f97209e96d7e3c9fa3d47f72e5aa134c877fd*