From 0b87c84cdd3876375c7bc0d6255332195ff57f45 Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Tue, 28 Apr 2020 01:12:57 +0300 Subject: [PATCH] Merkle tree panics when there's a single leaf - fix --- crypto-primitives/src/merkle_tree/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index 1ea81b2..b76577a 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -268,6 +268,10 @@ fn log2(number: usize) -> usize { /// Returns the height of the tree, given the size of the tree. #[inline] fn tree_height(tree_size: usize) -> usize { + if tree_size == 1 { + return 1; + } + log2(tree_size) }