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

Save roots of complete 2^16 subtrees within the Sapling commitment trees #6335

Closed
str4d opened this issue Jan 10, 2023 · 0 comments · Fixed by #6691
Closed

Save roots of complete 2^16 subtrees within the Sapling commitment trees #6335

str4d opened this issue Jan 10, 2023 · 0 comments · Fixed by #6691
Assignees
Labels
A-light-clients Area: Light clients A-orchard Area: Orchard protocol A-sapling Area: Sapling protocol
Milestone

Comments

@str4d
Copy link
Contributor

str4d commented Jan 10, 2023

In order to use shardtree efficiently in a mobile client, lightwalletd needs to be able to supply it with information about roots of 216 subtrees within the commitment tree. We need zcashd to store this information.

Currently, zcashd stores an IncrementalMerkleTree state as of the end of every block. This is a tree frontier, onto which new leaves can be appended to move the frontier forward, but that does not store any information allowing leaf removals.

We only need to store the roots of the 216 subtrees:

  • Smaller subtrees will be reconstructed by fetching the stream of note commitments within the subtree, which is at most 2MiB of leaf hashes (plus metadata).
  • Larger subtree roots can be constructed from the 216 subtree roots, which is at most 2MiB of hashes.

Additionally, because this is at most 2MiB of data, and we'll want it for the internal Orchard wallet eventually, we will just collect these roots for all nodes (not just when the -lightwalletd option is specified).

  • When a block append causes a subtree to be completed, zcashd should store:
    • The index of the subtree.
      • Zero-indexed from the left; this can be derived from the position of any leaf within the subtree.
    • The root of the subtree
    • The height of block that completed this subtree
      • Either the position of the frontier at the end of the block is precisely on the 216 subtree boundary (the last leaf appended is part of the subtree), or it is somewhere within the next subtree (as a block is not large enough to contain sufficient note commitments to cross multiple 216 subtrees).
  • When a block rewind uncompletes a subtree, we should remove its root from the coins DB.
  • On start, when the coins DB is loaded, if there are no stored roots, scan the commitment tree frontiers stored in the coins DB from Sapling activation, finding the 216 roots (by observing when the hash at position 16 changes across a block boundary), and storing them in the database.
@str4d str4d added A-sapling Area: Sapling protocol P-orchard labels Jan 10, 2023
@str4d str4d changed the title Save roots of complete 2<sup>16</sup> subtrees within the Sapling and Orchard commitment trees Save roots of complete 2^16 subtrees within the Sapling and Orchard commitment trees Jan 10, 2023
@str4d str4d added the A-light-clients Area: Light clients label Jan 10, 2023
@str4d str4d added this to the Release 5.5.0 milestone Jan 12, 2023
@nuttycom nuttycom modified the milestones: Release 5.5.0, Pre-DAG-Sync Jan 26, 2023
@nuttycom nuttycom modified the milestones: Release 5.5.0, Release 5.6.0 Mar 6, 2023
@nuttycom nuttycom changed the title Save roots of complete 2^16 subtrees within the Sapling and Orchard commitment trees Save roots of complete 2^16 subtrees within the Sapling commitment trees Mar 9, 2023
@daira daira added A-orchard Area: Orchard protocol and removed P-orchard labels Jan 29, 2024
@str4d str4d reopened this Feb 3, 2024
@str4d str4d closed this as completed Feb 3, 2024
@str4d str4d reopened this Feb 3, 2024
@str4d str4d closed this as completed Feb 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-light-clients Area: Light clients A-orchard Area: Orchard protocol A-sapling Area: Sapling protocol
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants