Skip to content

Commit

Permalink
Merge pull request #7 from GarrickOllivander/fix_merkle_tree_malleabi…
Browse files Browse the repository at this point in the history
…lity

Fix Merkle tree malleability.
  • Loading branch information
ignopeverell authored Oct 31, 2016
2 parents a23308d + 4e11aab commit 2efa8ce
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ impl Hashed for HPair {
}
}
/// An iterator over hashes in a vector that pairs them to build a row in a
/// Merkle tree. If the vector has an odd number of hashes, duplicates the last.
/// Merkle tree. If the vector has an odd number of hashes, it appends a zero hash
/// See https://bitcointalk.org/index.php?topic=102395.0 CVE-2012-2459 (block merkle calculation exploit)
/// for the argument against duplication of last hash
struct HPairIter(Vec<Hash>);
impl Iterator for HPairIter {
type Item = HPair;

fn next(&mut self) -> Option<HPair> {
self.0.pop().map(|first| HPair(first, self.0.pop().unwrap_or(first)))
self.0.pop().map(|first| HPair(first, self.0.pop().unwrap_or(ZERO_HASH)))
}
}
/// A row in a Merkle tree. Can be built from a vector of hashes. Calculates
Expand Down

0 comments on commit 2efa8ce

Please sign in to comment.