22 uncovered a bug whereby deleteWithSideNodes tries to Get side nodes, but those nodes may not exist in the tree. The case where these nodes don't exist in the tree is when a branch is added with AddBranch (which only includes the side nodes hashes, but not their values).
This is mostly an issue with the DSMST, where it is constructed by adding branches rather than updating.
Specifically, here. This Get only happens during the first iteration of the loop, i.e. it only applies to the sibling of the leaf node to delete. This node can either be another leaf node or an internal node, but cannot be a placeholder.
This can be resolved by adding an optional (i.e. nullable) field to SparseMerkleProof for the sibling nodes value. If this is non-nil on an Add, it is added to the tree's hashmap.
22 uncovered a bug whereby
deleteWithSideNodes
tries toGet
side nodes, but those nodes may not exist in the tree. The case where these nodes don't exist in the tree is when a branch is added withAddBranch
(which only includes the side nodes hashes, but not their values).This is mostly an issue with the DSMST, where it is constructed by adding branches rather than updating.
Specifically, here. This
Get
only happens during the first iteration of the loop, i.e. it only applies to the sibling of the leaf node to delete. This node can either be another leaf node or an internal node, but cannot be a placeholder.