Esempio n. 1
0
func (tree *MerkleTree) lookup(root *node, indexBytes []byte) (value []byte, trace *proto.TreeProof, err error) {
	trace = &proto.TreeProof{}
	var tracingRoot coname.MerkleNode = makeTracingNode(tree, trace, root)
	value, err = coname.TreeLookup(tracingRoot, indexBytes)
	if err != nil {
		return nil, nil, err
	}
	return
}
Esempio n. 2
0
func verifyProof(s *Snapshot, index, value []byte, proof *proto.TreeProof) {
	reconstructed, err := coname.ReconstructTree(proof, coname.ToBits(coname.IndexBits, index))
	if err != nil {
		panic(err)
	}
	redoneLookup, err := coname.TreeLookup(reconstructed, index)
	if err != nil {
		panic(err)
	}
	if got, want := redoneLookup, value; !bytes.Equal(got, want) {
		log.Panicf("reconstructed lookup got different result: %v rather than %v", got, want)
	}
	recomputedHash, err := coname.RecomputeHash(treeNonce, reconstructed)
	if err != nil {
		panic(err)
	}
	rootHash, err := s.GetRootHash()
	if err != nil {
		panic(err)
	}
	if got, want := recomputedHash, rootHash; !bytes.Equal(got, want) {
		log.Panicf("reconstructed hash differed: %x rather than %x", got, want)
	}
}