Browse Source

update hashing of empty inputs, and initial block LastResultsHash (#141)

pull/7804/head
Erik Grinaker 4 years ago
committed by GitHub
parent
commit
89ac8f6e62
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions
  1. +1
    -1
      spec/core/data_structures.md
  2. +6
    -1
      spec/core/encoding.md

+ 1
- 1
spec/core/data_structures.md View File

@ -423,7 +423,7 @@ block.LastResultsHash == MerkleRoot([]ResponseDeliverTx)
`LastResultsHash` is the root hash of a Merkle tree built from `ResponseDeliverTx` responses (`Log`,`Info`, `Codespace` and `Events` fields are ignored). `LastResultsHash` is the root hash of a Merkle tree built from `ResponseDeliverTx` responses (`Log`,`Info`, `Codespace` and `Events` fields are ignored).
The first block has `block.Header.ResultsHash == []byte{}`.
The first block has `block.Header.ResultsHash == MerkleRoot(nil)`, i.e. the hash of an empty input, for RFC-6962 conformance.
## EvidenceHash ## EvidenceHash


+ 6
- 1
spec/core/encoding.md View File

@ -216,6 +216,11 @@ h0 h1 h2 h3 h0 h1 h2 h3 h4 h5
The function `MerkleRoot` is a simple recursive function defined as follows: The function `MerkleRoot` is a simple recursive function defined as follows:
```go ```go
// SHA256([]byte{})
func emptyHash() []byte {
return tmhash.Sum([]byte{})
}
// SHA256(0x00 || leaf) // SHA256(0x00 || leaf)
func leafHash(leaf []byte) []byte { func leafHash(leaf []byte) []byte {
return tmhash.Sum(append(0x00, leaf...)) return tmhash.Sum(append(0x00, leaf...))
@ -232,7 +237,7 @@ func getSplitPoint(k int) { ... }
func MerkleRoot(items [][]byte) []byte{ func MerkleRoot(items [][]byte) []byte{
switch len(items) { switch len(items) {
case 0: case 0:
return nil
return empthHash()
case 1: case 1:
return leafHash(items[0]) return leafHash(items[0])
default: default:


Loading…
Cancel
Save