Skip to content

Commit

Permalink
tree: simplify GetProofItems for LeafNode (#355)
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign committed May 22, 2023
1 parent ab52d15 commit 16803c2
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,38 +1261,28 @@ func (n *LeafNode) GetProofItems(keys keylist) (*ProofElements, []byte, [][]byte
} else {
scomm = n.c2
}

slotPath := string(key[:n.depth]) + string([]byte{2 + suffix/128})

// Proof of absence: case of a missing value.
//
// Suffix tree is present as a child of the extension,
// but does not contain the requested suffix. This can
// only happen when the leaf has never been written to
// since after deletion the value would be set to zero
// but still contain the leaf marker 2^128.
var leaves [2]Fr
if n.values[suffix] == nil {
pe.Cis = append(pe.Cis, scomm, scomm)
pe.Zis = append(pe.Zis, 2*suffix, 2*suffix+1)
pe.Yis = append(pe.Yis, &FrZero, &FrZero)
pe.Fis = append(pe.Fis, suffPoly[:], suffPoly[:])
if len(esses) == 0 || esses[len(esses)-1] != extStatusPresent|(n.depth<<3) {
esses = append(esses, extStatusPresent|(n.depth<<3))
}
pe.ByPath[slotPath] = scomm
continue
// Proof of absence: case of a missing value.
//
// Suffix tree is present as a child of the extension,
// but does not contain the requested suffix. This can
// only happen when the leaf has never been written to
// since after deletion the value would be set to zero
// but still contain the leaf marker 2^128.
leaves[0], leaves[1] = FrZero, FrZero
} else {
// suffix tree is present and contains the key
leaves[0], leaves[1] = suffPoly[2*suffix], suffPoly[2*suffix+1]
}

// suffix tree is present and contains the key
var leaves [2]Fr
leafToComms(leaves[:], n.values[suffix])
pe.Cis = append(pe.Cis, scomm, scomm)
pe.Zis = append(pe.Zis, 2*suffix, 2*suffix+1)
pe.Yis = append(pe.Yis, &leaves[0], &leaves[1])
pe.Fis = append(pe.Fis, suffPoly[:], suffPoly[:])
if len(esses) == 0 || esses[len(esses)-1] != extStatusPresent|(n.depth<<3) {
esses = append(esses, extStatusPresent|(n.depth<<3))
}
slotPath := string(key[:n.depth]) + string([]byte{2 + suffix/128})
pe.ByPath[slotPath] = scomm
}

Expand Down

0 comments on commit 16803c2

Please sign in to comment.