mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-27 03:31:42 +00:00
Simple merkle rfc compatibility (#2713)
* Begin simple merkle compatibility PR * Fix query_test * Use trillian test vectors * Change the split point per RFC 6962 * update spec * refactor innerhash to match spec * Update changelog * Address @liamsi's comments * Write the comment requested by @liamsi
This commit is contained in:
13
types/tx.go
13
types/tx.go
@ -31,13 +31,14 @@ func (tx Tx) String() string {
|
||||
// Txs is a slice of Tx.
|
||||
type Txs []Tx
|
||||
|
||||
// Hash returns the simple Merkle root hash of the transactions.
|
||||
// Hash returns the Merkle root hash of the transaction hashes.
|
||||
// i.e. the leaves of the tree are the hashes of the txs.
|
||||
func (txs Txs) Hash() []byte {
|
||||
// These allocations will be removed once Txs is switched to [][]byte,
|
||||
// ref #2603. This is because golang does not allow type casting slices without unsafe
|
||||
txBzs := make([][]byte, len(txs))
|
||||
for i := 0; i < len(txs); i++ {
|
||||
txBzs[i] = txs[i]
|
||||
txBzs[i] = txs[i].Hash()
|
||||
}
|
||||
return merkle.SimpleHashFromByteSlices(txBzs)
|
||||
}
|
||||
@ -69,7 +70,7 @@ func (txs Txs) Proof(i int) TxProof {
|
||||
l := len(txs)
|
||||
bzs := make([][]byte, l)
|
||||
for i := 0; i < l; i++ {
|
||||
bzs[i] = txs[i]
|
||||
bzs[i] = txs[i].Hash()
|
||||
}
|
||||
root, proofs := merkle.SimpleProofsFromByteSlices(bzs)
|
||||
|
||||
@ -87,8 +88,8 @@ type TxProof struct {
|
||||
Proof merkle.SimpleProof
|
||||
}
|
||||
|
||||
// LeadHash returns the hash of the this proof refers to.
|
||||
func (tp TxProof) LeafHash() []byte {
|
||||
// Leaf returns the hash(tx), which is the leaf in the merkle tree which this proof refers to.
|
||||
func (tp TxProof) Leaf() []byte {
|
||||
return tp.Data.Hash()
|
||||
}
|
||||
|
||||
@ -104,7 +105,7 @@ func (tp TxProof) Validate(dataHash []byte) error {
|
||||
if tp.Proof.Total <= 0 {
|
||||
return errors.New("Proof total must be positive")
|
||||
}
|
||||
valid := tp.Proof.Verify(tp.RootHash, tp.LeafHash())
|
||||
valid := tp.Proof.Verify(tp.RootHash, tp.Leaf())
|
||||
if valid != nil {
|
||||
return errors.New("Proof is not internally consistent")
|
||||
}
|
||||
|
Reference in New Issue
Block a user