aboutsummaryrefslogtreecommitdiffstats
path: root/verify.go
blob: 74c89b6af114052e22d3d027d973b2bdffdc5899 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package main

import "golang.org/x/crypto/sha3"

// Verify the merkle proof for a given node id
func verify(id int64, proof [][]byte) []byte {
	h := sha3.New256()
	buf := proof[0]
	for _, hash := range proof[1:] {
		h.Reset()
		if id&1 == 0 {
			h.Write(hash)
			h.Write(buf)
		} else {
			h.Write(buf)
			h.Write(hash)
		}
		buf = h.Sum(buf[:0])
		id = (id - 1) >> 1
	}
	return buf
}