Improve well-formedness checks and add additional serialization/deserialization tests.

This commit is contained in:
Sean Bowe
2016-04-12 14:58:54 -06:00
parent 6d71658673
commit 01e4ff0f74
2 changed files with 50 additions and 1 deletions

View File

@@ -51,6 +51,16 @@ void IncrementalMerkleTree<Depth, Hash>::wfcheck() const {
if (parents.size() >= Depth) {
throw std::ios_base::failure("tree has too many parents");
}
// The last parent cannot be null.
bool wasnull = false;
BOOST_FOREACH(const boost::optional<Hash>& parent, parents) {
wasnull = !parent;
}
if (wasnull) {
throw std::ios_base::failure("tree has non-canonical representation of parent");
}
}
template<size_t Depth, typename Hash>