You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.1 KiB

  1. /*
  2. Package merkle computes a deterministic minimal height Merkle tree hash.
  3. If the number of items is not a power of two, some leaves
  4. will be at different levels. Tries to keep both sides of
  5. the tree the same size, but the left may be one greater.
  6. Use this for short deterministic trees, such as the validator list.
  7. For larger datasets, use IAVLTree.
  8. Be aware that the current implementation by itself does not prevent
  9. second pre-image attacks. Hence, use this library with caution.
  10. Otherwise you might run into similar issues as, e.g., in early Bitcoin:
  11. https://bitcointalk.org/?topic=102395
  12. *
  13. / \
  14. / \
  15. / \
  16. / \
  17. * *
  18. / \ / \
  19. / \ / \
  20. / \ / \
  21. * * * h6
  22. / \ / \ / \
  23. h0 h1 h2 h3 h4 h5
  24. TODO(ismail): add 2nd pre-image protection or clarify further on how we use this and why this secure.
  25. */
  26. package merkle