(Technical): How can I get a single `incrementalmerkletree::BridgeTree` from a collection of `IncrementalWitness<Node>`

The new incrementalwitnesstree package seems very cool and fast. I’d love to use it, but I’m not 100% sure how to.

Zecwallet maintains a collection of IncrementalWitness<Node>, one for each note that the user has. It then increments this by calling ::append(Node) for each Sapling output. This is duplicated one for each note that user has.

I’d like to change this to use a single incrementalwitnesstree::BridgeTree, but I’m not clear how I’d construct a single BridgeTree using all of the IncrementalWitness<Node> in the user’s wallet.

I can construct a NonEmptyFrontier from each of the CommitmentTree<Node>, and then fuse() them together, calling witness() each time to mark that node for witnessing when the note is spent.

But how can I get the frontier from the IncrementalWitness? i.e., How can I get the tree state at the time the note was created from a IncrementalWitness<Node>? Am I understanding this correctly?

1 Like

The design of the Merkle Tree API has changed with incrementalmerkletree. Previously, every note witness was independent as IncrementalWitness<Node>. They could be serialized and stored individually.
In the new design, there is a shared BridgeTree and witnesses are “references” to the same tree. You just need to keep their position which is returned when a node is appended.

1 Like

Right. I guess my question is how can I switch a users wallet to the new design without a rescan?

If we force a rescan, then it’s simple enough. We just switch to the new design. But without a rescan - can I construct the new incrementalmerkletree from just a collection of old incrementalwitness?