1
1
package scorex .crypto .authds .merkle
2
2
3
3
import scorex .crypto .authds .Side
4
+ import scorex .crypto .authds .merkle .MerkleProof .LeftSide
4
5
import scorex .crypto .authds .merkle .MerkleTree .InternalNodePrefix
5
6
import scorex .crypto .hash .{CryptographicHash , Digest }
6
7
import scorex .util .ScorexEncoding
@@ -68,10 +69,10 @@ case class BatchMerkleProof[D <: Digest](indices: Seq[(Int, Digest)], proofs: Se
68
69
} else {
69
70
70
71
// 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)
73
74
} 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)
75
76
}
76
77
77
78
// remove the used value from m
@@ -84,7 +85,7 @@ case class BatchMerkleProof[D <: Digest](indices: Seq[(Int, Digest)], proofs: Se
84
85
a_new = b.distinct.map(_._1 / 2 )
85
86
86
87
// 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 ) {
88
89
e_new = loop(a_new, a_new zip e_new, m_new)
89
90
}
90
91
e_new
0 commit comments