mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-05 21:14:53 +00:00
Fixes #5192. @liamsi Can you verify that the test vectors match the Rust implementation? I updated `ProofsFromByteSlices()` as well, anything else that should be updated?
27 lines
555 B
Go
27 lines
555 B
Go
package merkle
|
|
|
|
import (
|
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
)
|
|
|
|
// TODO: make these have a large predefined capacity
|
|
var (
|
|
leafPrefix = []byte{0}
|
|
innerPrefix = []byte{1}
|
|
)
|
|
|
|
// returns tmhash(<empty>)
|
|
func emptyHash() []byte {
|
|
return tmhash.Sum([]byte{})
|
|
}
|
|
|
|
// returns tmhash(0x00 || leaf)
|
|
func leafHash(leaf []byte) []byte {
|
|
return tmhash.Sum(append(leafPrefix, leaf...))
|
|
}
|
|
|
|
// returns tmhash(0x01 || left || right)
|
|
func innerHash(left []byte, right []byte) []byte {
|
|
return tmhash.Sum(append(innerPrefix, append(left, right...)...))
|
|
}
|