diff --git a/proofs.go b/proofs.go index c7d6146..017e1ed 100644 --- a/proofs.go +++ b/proofs.go @@ -208,7 +208,7 @@ func verifyProofWithUpdates(proof *SparseMerkleProof, root []byte, key []byte, v node := make([]byte, hashSize(spec)) copy(node, proof.SideNodes[i]) - if GetPathBit(path, len(proof.SideNodes)-1-i) == left { + if getPathBit(path, len(proof.SideNodes)-1-i) == left { currentHash, currentData = digestNode(spec, currentHash, node) } else { currentHash, currentData = digestNode(spec, node, currentHash) @@ -276,7 +276,7 @@ func DecompactProof(proof *SparseCompactMerkleProof, spec *TreeSpec) (*SparseMer decompactedSideNodes := make([][]byte, proof.NumSideNodes) position := 0 for i := 0; i < proof.NumSideNodes; i++ { - if GetPathBit(proof.BitMask, i) == 1 { + if getPathBit(proof.BitMask, i) == 1 { decompactedSideNodes[i] = placeholder(spec) } else { decompactedSideNodes[i] = proof.SideNodes[position] diff --git a/smt.go b/smt.go index 010e491..76b6526 100644 --- a/smt.go +++ b/smt.go @@ -114,7 +114,7 @@ func (smt *SMT) Get(key []byte) ([]byte, error) { } } inner := (*node).(*innerNode) - if GetPathBit(path, depth) == left { + if getPathBit(path, depth) == left { node = &inner.leftChild } else { node = &inner.rightChild @@ -172,7 +172,7 @@ func (smt *SMT) update( *last = &ext last = &ext.child } - if GetPathBit(path, prefixlen) == left { + if getPathBit(path, prefixlen) == left { *last = &innerNode{leftChild: newLeaf, rightChild: leaf} } else { *last = &innerNode{leftChild: leaf, rightChild: newLeaf} @@ -195,7 +195,7 @@ func (smt *SMT) update( inner := node.(*innerNode) var child *treeNode - if GetPathBit(path, depth) == left { + if getPathBit(path, depth) == left { child = &inner.leftChild } else { child = &inner.rightChild @@ -266,7 +266,7 @@ func (smt *SMT) delete(node treeNode, depth int, path []byte, orphans *orphanNod inner := node.(*innerNode) var child, sib *treeNode - if GetPathBit(path, depth) == left { + if getPathBit(path, depth) == left { child, sib = &inner.leftChild, &inner.rightChild } else { child, sib = &inner.rightChild, &inner.leftChild @@ -335,7 +335,7 @@ func (smt *SMT) Prove(key []byte) (proof *SparseMerkleProof, err error) { } } inner := node.(*innerNode) - if GetPathBit(path, depth) == left { + if getPathBit(path, depth) == left { node, sib = inner.leftChild, inner.rightChild } else { node, sib = inner.rightChild, inner.leftChild @@ -466,7 +466,7 @@ func (smt *SMT) ProveClosest(path []byte) ( if !ok { // this can only happen for an empty tree break } - if GetPathBit(workingPath, depth) == left { + if getPathBit(workingPath, depth) == left { node, sib = inner.leftChild, inner.rightChild } else { node, sib = inner.rightChild, inner.leftChild @@ -689,7 +689,7 @@ func (ext *extensionNode) match(path []byte, depth int) (int, bool) { panic("depth != path_begin") } for i := ext.pathStart(); i < ext.pathEnd(); i++ { - if GetPathBit(ext.path, i) != GetPathBit(path, i) { + if getPathBit(ext.path, i) != getPathBit(path, i) { return i - ext.pathStart(), false } } @@ -700,7 +700,7 @@ func (ext *extensionNode) match(path []byte, depth int) (int, bool) { func (ext *extensionNode) commonPrefix(path []byte) int { count := 0 for i := ext.pathStart(); i < ext.pathEnd(); i++ { - if GetPathBit(ext.path, i) != GetPathBit(path, i) { + if getPathBit(ext.path, i) != getPathBit(path, i) { break } count++ @@ -719,8 +719,8 @@ func (ext *extensionNode) split(path []byte, depth int) (treeNode, *treeNode, in index := ext.pathStart() var myBit, branchBit int for ; index < ext.pathEnd(); index++ { - myBit = GetPathBit(ext.path, index) - branchBit = GetPathBit(path, index) + myBit = getPathBit(ext.path, index) + branchBit = getPathBit(path, index) if myBit != branchBit { break } @@ -773,7 +773,7 @@ func (ext *extensionNode) expand() treeNode { last := ext.child for i := ext.pathEnd() - 1; i >= ext.pathStart(); i-- { var next innerNode - if GetPathBit(ext.path, i) == left { + if getPathBit(ext.path, i) == left { next.leftChild = last } else { next.rightChild = last diff --git a/utils.go b/utils.go index c42a3be..d7c93ba 100644 --- a/utils.go +++ b/utils.go @@ -11,9 +11,9 @@ func newNilPathHasher(hashSize int) PathHasher { return &nilPathHasher{hashSize: hashSize} } -// GetPathBit gets the bit at an offset from the most significant bit -// TODO: Unexport this method -func GetPathBit(data []byte, position int) int { +// getPathBit gets the bit at an offset (see position) in the data +// provided relative to the most significant bit +func getPathBit(data []byte, position int) int { // get the byte at the position and then left shift one by the offset of the position // from the leftmost bit in the byte. Check if the bitwise AND is the same // Path: []byte{ {0 1 0 1 1 0 1 0}, {0 1 1 0 1 1 0 1}, {1 0 0 1 0 0 1 0} } (length = 24 bits / 3 bytes) @@ -50,7 +50,7 @@ func flipPathBit(data []byte, position int) { func countSetBits(data []byte) int { count := 0 for i := 0; i < len(data)*8; i++ { - if GetPathBit(data, i) == 1 { + if getPathBit(data, i) == 1 { count++ } } @@ -61,7 +61,7 @@ func countSetBits(data []byte) int { func countCommonPrefix(data1, data2 []byte, from int) int { count := 0 for i := from; i < len(data1)*8; i++ { - if GetPathBit(data1, i) == GetPathBit(data2, i) { + if getPathBit(data1, i) == getPathBit(data2, i) { count++ } else { break