From 7526c22846f5159702cb0de9dfa06afddc443390 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Sat, 13 Nov 2021 23:49:36 +0300 Subject: [PATCH 1/2] keys checking --- .../avltree/batch/serialization/BatchAVLProverSerializer.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala index 615d3ec9..040428db 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala @@ -128,6 +128,8 @@ class BatchAVLProverSerializer[D <: Digest, HF <: CryptographicHash[D]](implicit val rightBytes = bytes.slice(keyLength + 6 + leftLength, bytes.length) val left = loop(leftBytes) val right = loop(rightBytes) + val keyAsNum = BigInt(1, key) + require(BigInt(1, left.key) < keyAsNum && keyAsNum <= BigInt(1, right.key), s"key check fail") new InternalProverNode[D](key, left, right, balance) case 2 => val balance = Balance @@ bytes.slice(1, 2).head From b70a098138866c08c266178871525061bd87d6b0 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Mon, 15 Nov 2021 13:05:09 +0300 Subject: [PATCH 2/2] keys comparison fixed --- .../batch/serialization/BatchAVLProverSerializer.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala b/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala index 040428db..d3bc0176 100644 --- a/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala +++ b/src/main/scala/scorex/crypto/authds/avltree/batch/serialization/BatchAVLProverSerializer.scala @@ -4,6 +4,8 @@ import com.google.common.primitives.{Bytes, Ints} import scorex.crypto.authds.avltree.batch.{BatchAVLProver, InternalProverNode, ProverLeaf, ProverNodes} import scorex.crypto.authds.{ADKey, ADValue, Balance} import scorex.crypto.hash.{CryptographicHash, Digest} +import scorex.util.encode.Base16 +import scorex.utils.ByteArray import scala.util.Try @@ -128,8 +130,11 @@ class BatchAVLProverSerializer[D <: Digest, HF <: CryptographicHash[D]](implicit val rightBytes = bytes.slice(keyLength + 6 + leftLength, bytes.length) val left = loop(leftBytes) val right = loop(rightBytes) - val keyAsNum = BigInt(1, key) - require(BigInt(1, left.key) < keyAsNum && keyAsNum <= BigInt(1, right.key), s"key check fail") + + // check that left.key < key <= right.key + val leftComparison = ByteArray.compare(left.key, key) + val rightComparison = ByteArray.compare(key, right.key) + require(leftComparison < 0 && rightComparison <= 0, s"key check fail for key ${Base16.encode(key)}") new InternalProverNode[D](key, left, right, balance) case 2 => val balance = Balance @@ bytes.slice(1, 2).head