Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Nov 22, 2024

Conversation

upbqdn
Copy link
Member

@upbqdn upbqdn commented Nov 22, 2024

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:

  • 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.

Solution

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

Tests

  • None.

Follow-up Work

  • None.

PR Author's Checklist

  • The PR name will make sense to users.
  • The PR provides a CHANGELOG summary.
  • The solution is tested.
  • The documentation is up to date.
  • The PR has a priority label.

PR Reviewer's Checklist

  • The PR Author's checklist is complete.
  • The PR resolves the issue.

@upbqdn upbqdn added C-bug Category: This is a bug C-testing Category: These are tests P-Critical 🚑 labels Nov 22, 2024
@upbqdn upbqdn self-assigned this Nov 22, 2024
@upbqdn upbqdn requested a review from a team as a code owner November 22, 2024 00:18
@upbqdn upbqdn requested review from oxarbitrage and removed request for a team November 22, 2024 00:18
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Nov 22, 2024
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.
@upbqdn upbqdn force-pushed the fix-treestate-test-vector branch from c6c6cbd to 8d73c15 Compare November 22, 2024 00:23
Copy link
Contributor

@arya2 arya2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good once the extra newline is removed. Thank you for the CI fix!

@mpguerra mpguerra enabled auto-merge (squash) November 22, 2024 10:33
@mpguerra
Copy link
Contributor

@mergify refresh

Copy link
Contributor

mergify bot commented Nov 22, 2024

refresh

✅ Pull request refreshed

@gustavovalverde
Copy link
Member

@mergify refresh

Copy link
Contributor

mergify bot commented Nov 22, 2024

refresh

✅ Pull request refreshed

@mpguerra
Copy link
Contributor

@mergify queue

Copy link
Contributor

mergify bot commented Nov 22, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 5f2f972

mergify bot added a commit that referenced this pull request Nov 22, 2024
@mergify mergify bot merged commit 5f2f972 into main Nov 22, 2024
146 checks passed
@mergify mergify bot deleted the fix-treestate-test-vector branch November 22, 2024 12:15
@arya2 arya2 mentioned this pull request Dec 5, 2024
45 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug C-testing Category: These are tests C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG P-Critical 🚑
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants