Remove the Merkle tree hash function's fixed point.

This commit is contained in:
Taylor Hornby
2016-05-04 09:15:14 -06:00
parent 9e387120eb
commit bf2e3122ac
8 changed files with 251 additions and 132 deletions

View File

@@ -31,6 +31,22 @@ public:
: authentication_path(authentication_path), index(index) { }
};
template<size_t Depth, typename Hash>
class EmptyMerkleRoots {
public:
EmptyMerkleRoots() {
empty_roots.at(0) = Hash();
for (size_t d = 1; d <= Depth; d++) {
empty_roots.at(d) = Hash::combine(empty_roots.at(d-1), empty_roots.at(d-1));
}
}
Hash empty_root(size_t depth) {
return empty_roots.at(depth);
}
private:
boost::array<Hash, Depth+1> empty_roots;
};
template<size_t Depth, typename Hash>
class IncrementalWitness;
@@ -64,7 +80,12 @@ public:
wfcheck();
}
static Hash empty_root() {
return emptyroots.empty_root(Depth);
}
private:
static EmptyMerkleRoots<Depth, Hash> emptyroots;
boost::optional<Hash> left;
boost::optional<Hash> right;