diff --git a/proofs.go b/proofs.go index 3a2b690..0b8f11d 100644 --- a/proofs.go +++ b/proofs.go @@ -193,17 +193,6 @@ func (proof *SparseMerkleClosestProof) Unmarshal(bz []byte) error { return dec.Decode(proof) } -// GetValueHash returns the value hash of the closest proof. -func (proof *SparseMerkleClosestProof) GetValueHash(spec *TrieSpec) []byte { - if proof.ClosestValueHash == nil { - return nil - } - if spec.sumTrie { - return proof.ClosestValueHash[:len(proof.ClosestValueHash)-sumSize] - } - return proof.ClosestValueHash -} - func (proof *SparseMerkleClosestProof) validateBasic(spec *TrieSpec) error { // ensure the depth of the leaf node being proven is within the path size if proof.Depth < 0 || proof.Depth > spec.ph.PathSize()*8 { diff --git a/smt.go b/smt.go index 558db63..f55a3f8 100644 --- a/smt.go +++ b/smt.go @@ -178,19 +178,36 @@ func (smt *SMT) update( } // We insert an "extension" representing multiple single-branch inner nodes last := &node + var newInner *innerNode + if getPathBit(path, prefixlen) == left { + newInner = &innerNode{ + leftChild: newLeaf, + rightChild: leaf, + } + } else { + newInner = &innerNode{ + leftChild: leaf, + rightChild: newLeaf, + } + } + // Determine if we need to insert an extension or a branch if depth < prefixlen { // note: this keeps path slice alive - GC inefficiency? if depth > 0xff { panic("invalid depth") } - ext := extensionNode{path: path, pathBounds: [2]byte{byte(depth), byte(prefixlen)}} + ext := extensionNode{ + child: newInner, + path: path, + pathBounds: [2]byte{ + byte(depth), byte(prefixlen), + }, + } + // Dereference the last node to replace it with the extension node *last = &ext - last = &ext.child - } - if getPathBit(path, prefixlen) == left { - *last = &innerNode{leftChild: newLeaf, rightChild: leaf} } else { - *last = &innerNode{leftChild: leaf, rightChild: newLeaf} + // Dereference the last node to replace it with the new inner node + *last = newInner } return node, nil }