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

Unify transaction and witness merkle roots #806

Open
scravy opened this issue Mar 19, 2019 · 1 comment
Open

Unify transaction and witness merkle roots #806

scravy opened this issue Mar 19, 2019 · 1 comment
Labels
brainstorming Needs input, ideas are welcome needs design Needs a design (possibly in a UIP) before it can be implemented
Milestone

Comments

@scravy
Copy link
Member

scravy commented Mar 19, 2019

Copied from PR#798 discussion

Also partially related to this PR. We are working on also introducing a merkle root for finalizer commits.
We will change their signatures so they will also have a witness program. If we proceed with the current approach, we will add +2 roots to the headers, one for finalizer commits and one for their witness.

@Gnappuraz had an idea that what if we don't introduce the new merkle root for finalizer commits but combine with existing one. Example:

    root
   /    \
txs      commits

So, in the header, we can still use one record, but in a p2p commits message we send besides commits also the hash of txs so we will be able to match with the root.

Then, if we pick this approach, a similar pattern can be applied to the witness root.

        witness root
       /            \
witness              commits witness

One edge-case is that we not always have commits. The idea is to duplicate then what you have on the left leaf to the right.

Now my question :)

If we proceed with that proposal (we don't find an issue with that). What if we instead of grouping witnesses and txs, we will group entities, e.g.:

    root
   /    \
txs      txs witnesses
        commits root
       /            \
commits              commits witnesses

With the second approach we have 2 possible advantages:

  1. we don't need to duplicate left leaf in case commits are missing so the hash will always be of one particular entity, commits and not commits or txs
  2. by looking at the header we can see if we have any finalizer commits in the block (because we have a separate root for them). With the first approach, you can't answer this question by looking at the header only.
@scravy scravy added needs design Needs a design (possibly in a UIP) before it can be implemented brainstorming Needs input, ideas are welcome labels Mar 19, 2019
@scravy scravy changed the title Some issue which was piggy backed on some other PR Unify transaction and witness merkle roots Mar 19, 2019
@scravy
Copy link
Member Author

scravy commented Mar 20, 2019

I guess the proposed version has some merits:

              tx merkel                          commit merkel
              tree hash                            tree hash
             /        \                           /         \
            /          \                         /           \
    txid merkel      wtxid merkel   commits txid merkel   commits wtxid merkel
     tree hash        tree hash          tree hash              tree hash

But I think we need to evaluate which repercussions this has e.g. on light clients. Related to merkle trees are fast merkle trees which are (a) faster (b) more secure, which I would also like to see tackled for 1.0 (#18).

I could imagine, if we wanted to return to the size of 80 bytes in the header, to go even further:

                     hash of combines merkle treed
                      /                          \
                     /                            \
              tx merkel                          commit merkel
              tree hash                            tree hash
             /        \                           /         \
            /          \                         /           \
    txid merkel      wtxid merkel   commits txid merkel   commits wtxid merkel
     tree hash        tree hash          tree hash              tree hash

But also here I am wondering what this means for SPV/light clients.

@thothd thothd added this to the 1.0 milestone Mar 20, 2019
kostyantyn added a commit that referenced this issue Mar 26, 2019
This PR adds merkle root of finalizer commits to the block header.
Having this merkle root in a header will allow us to verify
the consistency of headers+commits P2P messages.

Notice, original "hashMerkleRoot" also takes finalizer commits into account.
The reason is that it's needed for Bloom Filter. We can review
the possibility of not including finalizer commits into hashMerkleRoot
and refactor Bloom Filters/SPV clients in a separate issue or PR.

We also have an issue of how to optimize our merkle roots #806
and this will be discussed/tackled in a separate PR.

Signed-off-by: Kostiantyn Stepaniuk <kostia@thirdhash.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
brainstorming Needs input, ideas are welcome needs design Needs a design (possibly in a UIP) before it can be implemented
Projects
None yet
Development

No branches or pull requests

2 participants