multiproof-rs icon indicating copy to clipboard operation
multiproof-rs copied to clipboard

Re-constructing paths of leaves during verification

Open s1na opened this issue 5 years ago • 1 comments

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 of addrs, and add this index to the leaf node being pushed on stack
  • In BRANCH, EXTENSION or ADD:
    • if the node popped from stack is a leaf, read its index and prepend a partial path to its addrs entry. Also add its addrs 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)
  • After verification is done, all these paths need to be encoded form their nibbles form to get the addresses

s1na avatar Sep 10 '19 10:09 s1na

Added a prototype of this to the typescript version: https://github.com/ethereumjs/merkle-patricia-tree/pull/101/commits/78810c5711b2e0512079bcfc0bfdb44cca58e664

s1na avatar Sep 16 '19 09:09 s1na