dmfxyz / murky

Merkle Proof Generator and Validator in Solidity
MIT License
368 stars 35 forks source link

Murky does not match OpenZeppelin/merkle-tree or merkletreejs implementations #11

Open 0xTimepunk opened 7 months ago

0xTimepunk commented 7 months ago

The issue reported in https://ethereum.stackexchange.com/questions/129249/merkle-tree-not-matching-between-solidity-and-etherjs

Cannot be fixed by adding one element by making it even - this only seems to work if the number of leaves is small (3 in the case of the example above, making it 4)

But for a tree of say 9 elements, adding a zero node does not solve the issue

Why does murky not follow the bitcoin tree implementation?

dmfxyz commented 6 months ago

Thanks for the issue. That is how Bitcoin implements its merkle trees, but is not the only way. When murky was originally written, zero padding for odd number of leafs best matched off chain implementations I was writing.

A tree of 9 elements should definitely be coercible to match. But, either way, I will consider adding a Bitcoin style implementation. And would absolutely welcome a PR that does so.