multiproof-rs
multiproof-rs copied to clipboard
Re-constructing paths of leaves during verification
This is more related to an EE wanting to do token transfers using this multiproof algorithm. I'm not sure if it makes sense to merge it in the repo.
EE receives an array of txes which include among other things a signature from sender and the address of the recipient. The EE also receives a multiproof. In order to make sure addresses of the sender and recipient of the tx corresponds to the leaves sent in the multiproof, the EE needs to re-construct the path to those leaves when it's verifying the multiproof. Here's my attempt at how one could do this:
- Initialize an array of
addrs
with same length as leaves - When a leaf is read in via
LEAF
add its partial path to corresponding index ofaddrs
, and add this index to the leaf node being pushed on stack - In
BRANCH
,EXTENSION
orADD
:- if the node popped from stack is a leaf, read its index and prepend a partial path to its
addrs
entry. Also add itsaddrs
index (for the leaf) to the node being pushed on stack - else, read list of indices for all leaves this node is pointing to and prepend their paths with the partial path (e.g. branch idx, or extkey)
- if the node popped from stack is a leaf, read its index and prepend a partial path to its
- After verification is done, all these paths need to be encoded form their nibbles form to get the addresses
Added a prototype of this to the typescript version: https://github.com/ethereumjs/merkle-patricia-tree/pull/101/commits/78810c5711b2e0512079bcfc0bfdb44cca58e664