# Membership Proofs at Historical Heights

At the voting snapshot height, the wallet must construct Merkle witnesses (authentication paths) for each of its Orchard notes. The anchor (tree root) is fixed by the voting protocol, and witnesses are only valid relative to a specific root.

To construct the witnesses at a historical height, we need a sibling path from the leaf to the root at the voting snapshot height.

Notes may be in different shards, and the tree may have advanced past the [pruning depth of 100 checkpoints](https://github.com/valargroup/librustzcash/blob/14c9cbc38fe6fab9b1ce8b4f10813de4ae54ae8e/zcash_client_sqlite/src/lib.rs#L167-L170), having pruned the tree elements necessary for witness construction.

## Reconstruction Mechanism

To construct witnesses at a historical height, we need three components:

1. **Authentication path within each note's shard.** The scanner marks the wallet's notes as `MARKED`. This prevents them and their siblings within a shard from being pruned.
2. **Cap** — the upper tree above the shard level.
3. **Frontier** — the right edge at the historical height. It lets `ShardTree` know exactly where the tree ended at the historical height.

We copy the wallet's Orchard shard data into an ephemeral in-memory database, insert the provided frontier from `lightwalletd` at that height as a checkpoint, and generate a witness for each of the given note positions.

It is assumed that the caller provides the valid frontier at the given height.

The reason for this reconstruction is that the wallet automatically prunes the tree after `PRUNING_DEPTH` of 100 checkpoints/heights. The availability of all three components above allows us to reconstruct sufficient tree structure for generating witnesses.

## Risk Analysis: Note Spend After Voting Snapshot

Let height X be the voting snapshot height. Consider the following sequence:

1. **Height ≤ X:** Note received — added to the local commitment tree.
2. **Height X + 50:** Note spent — marked for pruning from the local commitment tree.
3. **Height X + 100:** Wallet starts constructing a delegation to vote at height X. It needs to construct a witness at height X for the note that was later spent.

### Concern

What if the note's witness was removed from the tree after it was spent at step 2?

### Why This Is Not a Problem

* [`MARKED`](https://github.com/zcash/incrementalmerkletree/blob/edf24f2b2e727776e290f292d831d4ac61c3e1bd/incrementalmerkletree/src/lib.rs#L100-L102) means that retention will be preserved in the tree during pruning. Retention may only be explicitly removed.
* The only way to explicitly remove a mark is by calling [`remove_mark`](https://github.com/zcash/incrementalmerkletree/blob/edf24f2b2e727776e290f292d831d4ac61c3e1bd/shardtree/src/lib.rs#L1395-L1405). This function is [never called](https://github.dev/valargroup/Shielded-Vote) in our codebase.
* Marking an Orchard note as spent [does not unmark](https://github.com/valargroup/librustzcash/blob/4b690e6ca8c809693b4119c17500ac724494cd87/zcash_client_sqlite/src/wallet/orchard.rs#L481-L505) the note in the incremental tree.
* The checkpoint pruning logic only prunes nodes that have been explicitly [tagged by `remove_mark`](https://github.com/zcash/incrementalmerkletree/blob/edf24f2b2e727776e290f292d831d4ac61c3e1bd/shardtree/src/lib.rs#L1431-L1434).

Therefore, `MARKED` notes stay in the tree permanently. A note that was received before the snapshot and spent afterward will always have its shard data available for witness reconstruction.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://valargroup.gitbook.io/shielded-vote-docs/appendices/membership-proofs-at-historical-heights.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
