11package scorex .crypto .authds .merkle
22
33import scorex .crypto .authds .Side
4+ import scorex .crypto .authds .merkle .MerkleProof .LeftSide
45import scorex .crypto .authds .merkle .MerkleTree .InternalNodePrefix
56import scorex .crypto .hash .{CryptographicHash , Digest }
67import scorex .util .ScorexEncoding
@@ -68,10 +69,10 @@ case class BatchMerkleProof[D <: Digest](indices: Seq[(Int, Digest)], proofs: Se
6869 } else {
6970
7071 // hash the corresponding value inside E with the first hash inside M, taking note of the side
71- if (m_new.head._2 == MerkleProof . LeftSide ) {
72- e_new = e_new :+ hf.prefixedHash(MerkleTree . InternalNodePrefix , m_new.head._1 ++ e.apply(i)._2)
72+ if (m_new.head._2 == LeftSide ) {
73+ e_new = e_new :+ hf.prefixedHash(InternalNodePrefix , m_new.head._1 ++ e.apply(i)._2)
7374 } else {
74- e_new = e_new :+ hf.prefixedHash(MerkleTree . InternalNodePrefix , e.apply(i)._2 ++ m_new.head._1)
75+ e_new = e_new :+ hf.prefixedHash(InternalNodePrefix , e.apply(i)._2 ++ m_new.head._1)
7576 }
7677
7778 // remove the used value from m
@@ -84,7 +85,7 @@ case class BatchMerkleProof[D <: Digest](indices: Seq[(Int, Digest)], proofs: Se
8485 a_new = b.distinct.map(_._1 / 2 )
8586
8687 // Repeat until the root of the tree is reached (M has no more elements)
87- if (m_new.nonEmpty || e_new.size > 1 ) {
88+ if (( m_new.nonEmpty || e_new.size > 1 ) && a_new.nonEmpty ) {
8889 e_new = loop(a_new, a_new zip e_new, m_new)
8990 }
9091 e_new
0 commit comments