Skip to content

Commit

Permalink
draft of merkle tree
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed Aug 7, 2024
1 parent 6aa388b commit 2854670
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/merkle_tree.cairo
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use super::utils::double_sha256;

pub fn merkle_root(ref txids: Array<u256>) -> u256 {
if txids.len() % 2 == 1 {
txids.append(*txids.at(txids.len() - 1));
let len = txids.len();
if len % 2 == 1 {
txids.append(*txids.at(len - 1));
} else {
// CVE-2012-2459 bug fix
assert!(
txids.at(len - 1) != txids.at(len - 2), "unexpected node duplication in merkle tree"
);
}

let mut next_txids = ArrayTrait::new();
let mut i = 0;
let len = txids.len();
while i < len {
next_txids.append(double_sha256(*txids.at(i), *txids.at(i + 1)));
i += 2;
Expand Down

0 comments on commit 2854670

Please sign in to comment.