Skip to content

Commit ffcdb03

Browse files
authored
Merge pull request #91 from input-output-hk/keys-check
Checking keys during internal nodes deserialization
2 parents 5ff5d04 + b70a098 commit ffcdb03

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.google.common.primitives.{Bytes, Ints}
44
import scorex.crypto.authds.avltree.batch.{BatchAVLProver, InternalProverNode, ProverLeaf, ProverNodes}
55
import scorex.crypto.authds.{ADKey, ADValue, Balance}
66
import scorex.crypto.hash.{CryptographicHash, Digest}
7+
import scorex.util.encode.Base16
8+
import scorex.utils.ByteArray
79

810
import scala.util.Try
911

@@ -128,6 +130,11 @@ class BatchAVLProverSerializer[D <: Digest, HF <: CryptographicHash[D]](implicit
128130
val rightBytes = bytes.slice(keyLength + 6 + leftLength, bytes.length)
129131
val left = loop(leftBytes)
130132
val right = loop(rightBytes)
133+
134+
// check that left.key < key <= right.key
135+
val leftComparison = ByteArray.compare(left.key, key)
136+
val rightComparison = ByteArray.compare(key, right.key)
137+
require(leftComparison < 0 && rightComparison <= 0, s"key check fail for key ${Base16.encode(key)}")
131138
new InternalProverNode[D](key, left, right, balance)
132139
case 2 =>
133140
val balance = Balance @@ bytes.slice(1, 2).head

0 commit comments

Comments
 (0)