Add more well-formedness checks/tests to tree.

This commit is contained in:
Sean Bowe
2016-04-21 11:44:16 -06:00
parent 01e4ff0f74
commit d0c4b0e850
2 changed files with 50 additions and 0 deletions

View File

@@ -61,6 +61,16 @@ void IncrementalMerkleTree<Depth, Hash>::wfcheck() const {
if (wasnull) {
throw std::ios_base::failure("tree has non-canonical representation of parent");
}
// Left cannot be empty when right exists.
if (!left && right) {
throw std::ios_base::failure("tree has non-canonical representation of tree");
}
// Left cannot be empty when parents is nonempty.
if (!left && parents.size() > 0) {
throw std::ios_base::failure("tree has non-canonical representation of tree");
}
}
template<size_t Depth, typename Hash>