fix: merkle store panics on bounds

Prior to this commit, the MerkleStore panicked under certain bounds. It
will prevent such panics by using checked operations.

ilog2, for instance, will panic when the operand is zero. However, there
is a documentation rule enforcing the merkle tree to be size at least 2.
If this rule is checked, then the panic is impossible.
This commit is contained in:
Victor Lopez
2023-03-16 19:50:59 +01:00
parent 33d37d82e2
commit 867b772d9a
4 changed files with 127 additions and 68 deletions

View File

@@ -35,7 +35,7 @@ pub use store::MerkleStore;
// ERRORS
// ================================================================================================
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MerkleError {
ConflictingRoots(Vec<Word>),
DepthTooSmall(u8),