Skip to content

Commit

Permalink
tree: add new method LoadKeyForProof
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Aug 9, 2023
1 parent b2d852d commit 131aace
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,33 @@ func groupKeys(keys keylist, depth byte) []keylist {
return groups
}

func (n *InternalNode) LoadKeyForProof(key []byte, resolver NodeResolverFn) error {
// Each internal node that is part of the proof needs to load all it's
// children since it's needed for proof openings.
childrenKey := make([]byte, n.depth+1)
copy(childrenKey, key[:n.depth])
for i := range n.children {
if _, ok := n.children[i].(HashedNode); ok {
childrenKey[n.depth] = byte(i)
serialized, err := resolver(childrenKey)
if err != nil {
return err
}
c, err := ParseNode(serialized, n.depth+1)
if err != nil {
return err
}
n.children[i] = c
}
if child, ok := n.children[i].(*InternalNode); ok {
if err := child.LoadKeyForProof(childrenKey, resolver); err != nil {
return err
}
}
}
return nil
}

func (n *InternalNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte, error) {
var (
groups = groupKeys(keys, n.depth)
Expand Down Expand Up @@ -1339,8 +1366,8 @@ func (n *LeafNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte
if len(esses) == 0 {
esses = append(esses, extStatusAbsentOther|(n.depth<<3))
poass = append(poass, n.stem)
pe.Vals = append(pe.Vals, nil)
}
pe.Vals = append(pe.Vals, nil) // TODO(PR-temp): workaround proving bug.
continue
}

Expand Down

0 comments on commit 131aace

Please sign in to comment.