txaty / go-merkletree

Go Merkle Tree. High performance, Supporting parallel run, OpenZeppelin sorting pairs.
https://pkg.go.dev/github.com/txaty/go-merkletree
MIT License
110 stars 17 forks source link

MerkleTree from 1 data node #40

Open Dmdv opened 2 months ago

Dmdv commented 2 months ago

Why merkle tree can't be from 1 node?

https://github.com/txaty/go-merkletree/blob/ccfc3d24289d9c28111edc02f688b8bef9f45fb7/merkle_tree.go#L104

Even if there's just one mode, we still can compute 1 node merkle tree. What is the standard solution?

txaty commented 2 months ago

Hi! Thanks for using the library and providing feedbacks.

From the Bitcoin source code of Merkle Tree and this GitHub issue, seems like the standard solution is to make the solo node the root of the tree.

I thought it was meaningless and lack of use cases to construct a Merkle Tree with only one leaf so I enforced the number of leaves to be at least 2.