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

MT: Caphash optimization #41

Open
ValarDragon opened this issue Apr 9, 2021 · 0 comments
Open

MT: Caphash optimization #41

ValarDragon opened this issue Apr 9, 2021 · 0 comments

Comments

@ValarDragon
Copy link
Member

When you have many randomly queries to a single merkle tree, you can compute on you're own most nodes at the top. (e.g. with two queries, one on the left half, one on the right half, you don't need to provide any internal nodes on the 'first' layer of the MT proof)

At the moment we already prune such nodes, to save on proof size. However we can further save on computation by having only a single higher arity hash be executed at the top of the tree. So we want to support a 'cap hash', that computes a single hash of 2^k inputs for the top layers of the tree.

Standard merkle tree:

                       root
                       / \
                     /     \
                   /         \
                 /             \
                *               *
               / \             / \
              /   \           /   \
             /     \         /     \
            *       *       *      *
           / \     / \     / \    / \
         0   1  2  3  4 5   6 7

A cap_hash_size =2^2, tree:

                       root
                      / /  \  \
                 /    /      \   \
             /       /        \     \
            *       *       *      *
           / \     / \     / \     / \
          0 1  2  3  4  5  6   7

This should be done by add a new type called "cap hash" to hashing.hpp, which has a single template parameter for input & output type. (hash_digest_type), and it intakes a vector of hash_digest_type and outputs a single hash_digest_type. The we should update the merkle_tree.hpp file to use this, and update the proof format accordingly. the cap hash size should be a parameter input to the merkle tree, and also be updated in BCS.

For now, I suggest we first add this to the merkle tree standalone and test it, with the BCS transform defaulting to use cap hash size of 1. Then once that works we add this cap hash parameter to the BCS parameters.

This notably helps save on circuit costs when we go to recurse a SNARK (e.g. Fractal)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant