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

merkle tree: investigate divergance between go/rust implementation #498

Closed
liamsi opened this issue Jul 30, 2020 · 0 comments · Fixed by #514
Closed

merkle tree: investigate divergance between go/rust implementation #498

liamsi opened this issue Jul 30, 2020 · 0 comments · Fixed by #514
Labels
bug Something isn't working go Compatibility with Go code

Comments

@liamsi
Copy link
Member

liamsi commented Jul 30, 2020

It seems a completely empty tree is handled differently in Rust (all zeroes output) than in go (returns nil):

func HashFromByteSlices(items [][]byte) []byte {
	switch len(items) {
	case 0:
		return nil

https://github.com/tendermint/tendermint/blob/b5f030892d1f33dfffb7a3d108f63583316befe2/crypto/merkle/tree.go#L9-L21
vs.

0 => [0; HASH_SIZE],


Also notice that this edge-case is treated differently in google's rfc6962 implementation (result of hashing an empty byte slice as the root hash of an empty tree):
https://github.com/google/trillian/blob/7166f485ebc965d24116db667c9e058a8ed9275c/merkle/rfc6962/rfc6962.go#L51

(This is true for both, the go and the rust implementation)

It's probably a good idea to follow the rfc6962 spec (other than we are compatible to that spec):

The hash of an empty list is the hash of an empty string:

MTH({}) = SHA-256().

https://tools.ietf.org/html/rfc6962#section-2.1

ref: tendermint/tendermint#4241 (comment)
ref: #73
ref: tendermint/tendermint#5192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working go Compatibility with Go code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant