Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ language: scala
scala:
- 2.12.10
- 2.11.12
- 2.13.1
jdk:
- oraclejdk8
cache:
Expand Down
20 changes: 12 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ description := "Cryptographic primitives for Scala"

lazy val scala212 = "2.12.10"
lazy val scala211 = "2.11.12"
crossScalaVersions := Seq(scala212, scala211)
scalaVersion := scala212
lazy val scala213 = "2.13.1"

crossScalaVersions := Seq(scala212, scala211, scala213)
scalaVersion := scala213

javacOptions ++=
"-source" :: "1.7" ::
"-target" :: "1.7" ::
"-source" :: "1.8" ::
"-target" :: "1.8" ::
Nil

lazy val commonSettings = Seq(
Expand All @@ -31,17 +33,19 @@ lazy val commonSettings = Seq(
)

libraryDependencies ++= Seq(
"org.rudogma" %% "supertagged" % "1.4",
"org.rudogma" %% "supertagged" % "1.5",
"com.google.guava" % "guava" % "20.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
"org.whispersystems" % "curve25519-java" % "0.5.0",
"org.bouncycastle" % "bcprov-jdk15on" % "1.64",
"org.scorexfoundation" %% "scorex-util" % "0.1.6"
"org.scorexfoundation" %% "scorex-util" % "0.1.7"
)

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.+" % "test",
"org.scalacheck" %% "scalacheck" % "1.13.+" % "test"
"org.scalatest" %% "scalatest" % "3.1.+" % Test,
"org.scalacheck" %% "scalacheck" % "1.14.+" % Test,
// https://mvnrepository.com/artifact/org.scalatestplus/scalatestplus-scalacheck
"org.scalatestplus" %% "scalatestplus-scalacheck" % "3.1.0.0-RC2" % Test
)

publishMavenStyle := true
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sbt.version=1.2.6
sbt.version=1.2.8

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scorex.crypto.authds

import scorex.crypto.authds.avltree.batch.Operation
import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

import scala.util.Try

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scorex.crypto.authds

import scorex.crypto.authds.legacy.treap.Level
import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

trait TwoPartyProofElement extends ScorexEncoding {
val bytes: Array[Byte]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
(implicit val hf: HF = Blake2b256)
extends AuthenticatedTreeOps[D] with ToStringHelper with ScorexLogging {

protected val labelLength = hf.DigestSize
protected val labelLength: Int = hf.DigestSize

private[batch] var topNode: ProverNodes[D] = oldRootAndHeight.map(_._1).getOrElse({
val t = new ProverLeaf(NegativeInfinityKey,
Expand Down Expand Up @@ -230,7 +230,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
}
}

loop(topNode, false)
loop(topNode, keyFound = false)
}

/**
Expand Down Expand Up @@ -267,7 +267,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
* that contains only this info)
* - Condense the sequence of values if they are mostly not randomly distributed
* */
def packTree(rNode: ProverNodes[D]) {
def packTree(rNode: ProverNodes[D]): Unit = {
// Post order traversal to pack up the tree
if (!rNode.visited) {
packagedTree += LabelInPackagedProof
Expand Down Expand Up @@ -357,21 +357,21 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
* @return Random leaf from the tree that is not positive or negative infinity
*/
def randomWalk(rand: Random = new Random): Option[(ADKey, ADValue)] = {
def internalNodeFn(r: InternalProverNode[D], dummy: Unit.type) =
def internalNodeFn(r: InternalProverNode[D], dummy: Unit): (ProverNodes[D], Unit) =
rand.nextBoolean() match {
case true =>
(r.right, Unit)
(r.right, ())
case false =>
(r.left, Unit)
(r.left, ())
}

def leafFn(leaf: ProverLeaf[D], dummy: Unit.type): Option[(ADKey, ADValue)] = {
def leafFn(leaf: ProverLeaf[D], dummy: Unit): Option[(ADKey, ADValue)] = {
if (leaf.key sameElements PositiveInfinityKey) None
else if (leaf.key sameElements NegativeInfinityKey) None
else Some(leaf.key -> leaf.value)
}

treeWalk(internalNodeFn, leafFn, Unit)
treeWalk(internalNodeFn, leafFn, ())
}

/**
Expand Down Expand Up @@ -442,7 +442,7 @@ class BatchAVLProver[D <: Digest, HF <: CryptographicHash[D]](val keyLength: Int
var fail: Boolean = false

def checkTreeHelper(rNode: ProverNodes[D]): (ProverLeaf[D], ProverLeaf[D], Int) = {
def myRequire(t: Boolean, s: String) = {
def myRequire(t: Boolean, s: String): Unit = {
if (!t) {
var x = rNode.key(0).toInt
if (x < 0) x = x + 256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import scorex.crypto.authds._
import scorex.crypto.hash._
import scorex.utils.ByteArray

import scala.collection.mutable
import scala.util.{Failure, Try}

/**
Expand Down Expand Up @@ -33,7 +32,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:

override val collectChangedNodes: Boolean = false

protected val labelLength = hf.DigestSize
protected val labelLength: Int = hf.DigestSize

/**
* Returns Some[the current digest of the authenticated data structure],
Expand Down Expand Up @@ -169,7 +168,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
// Now reconstruct the tree from the proof, which has the post order traversal
// of the tree
var numNodes = 0
val s = new mutable.Stack[VerifierNodes[D]] // Nodes and depths
var s = List.empty[VerifierNodes[D]] // Nodes and depths
var i = 0
var previousLeaf: Option[Leaf[D]] = None
while (proof(i) != EndOfTreeInPackagedProof) {
Expand All @@ -181,7 +180,7 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
case LabelInPackagedProof =>
val label = proof.slice(i, i + labelLength).asInstanceOf[D]
i += labelLength
s.push(new LabelOnlyNode[D](label))
s = new LabelOnlyNode[D](label) +: s
previousLeaf = None
case LeafInPackagedProof =>
val key = if (previousLeaf.nonEmpty) {
Expand All @@ -202,17 +201,21 @@ class BatchAVLVerifier[D <: Digest, HF <: CryptographicHash[D]](startingDigest:
val value = ADValue @@ proof.slice(i, i + valueLength)
i += valueLength
val leaf = new VerifierLeaf[D](key, value, nextLeafKey)
s.push(leaf)
s = leaf +: s

previousLeaf = Some(leaf)
case _ =>
val right = s.pop
val left = s.pop
s.push(new InternalVerifierNode(left, right, Balance @@ n))
val right = s.head
s = s.tail
val left = s.head
s = s.tail
s = new InternalVerifierNode(left, right, Balance @@ n) +: s

}
}

require(s.size == 1)
val root = s.pop
val root = s.head
require(startingDigest startsWith root.label)
directionsIndex = (i + 1) * 8 // Directions start right after the packed tree, which we just finished
Some(root)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scorex.crypto.authds.avltree.batch

import com.google.common.primitives.Longs
import scorex.crypto.authds.{ADKey, ADValue}
import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

import scala.util.{Failure, Success, Try}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scorex.crypto.authds.avltree.batch

import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

trait ToStringHelper extends ScorexEncoding {
//Needed for debug (toString) only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ class AVLTree[HF <: CryptographicHash[_ <: Digest]](keyLength: Int,

val (newTopNode, changeHappened, childHeightIncreased) = modifyHelper(topNode, foundAbove = false)
if (changeHappened) topNode = newTopNode
AVLModifyProof(key, proofStream)
AVLModifyProof(key, proofStream.toSeq) //toSeq required for 2.13
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@ class Treap[HF <: CryptographicHash[_ <: Digest]](rootOpt: Option[Leaf] = None)

val (newTopNode: ProverNodes, changeHappened: Boolean) = modifyHelper(topNode, foundAbove = false)
if (changeHappened) topNode = newTopNode
TreapModifyProof(key, proofStream)
TreapModifyProof(key, proofStream.toSeq) // .toSeq required for 2.13
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scorex.crypto.authds.merkle

import scorex.crypto.authds.{LeafData, Side}
import scorex.crypto.hash.{CryptographicHash, Digest}
import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

/**
* Proof is given leaf data, leaf hash sibling and also siblings for parent nodes. Using this data, it is possible to
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scorex/crypto/authds/merkle/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scorex.crypto.authds.merkle

import scorex.crypto.authds.LeafData
import scorex.crypto.hash._
import scorex.utils.ScorexEncoding
import scorex.util.ScorexEncoding

trait Node[D <: Digest] extends ScorexEncoding {
def hash: D
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scorex.crypto.authds.merkle.sparse

import scorex.crypto.authds.LeafData
import scorex.crypto.encode.Base16
import scorex.util.encode.Base16
import scorex.crypto.hash._

trait Node[D <: Digest] {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala/scorex/crypto/TestingCommons.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scorex.crypto
import java.io.File

import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers

import scala.util.Random

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package scorex.crypto.authds.avltree

import org.scalatest.PropSpec
import org.scalatest.prop.GeneratorDrivenPropertyChecks

import org.scalatest.propspec.AnyPropSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import scorex.crypto.authds.avltree.batch._
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
import scorex.crypto.hash.{Blake2b256, Digest32, Sha256}

class AVLDeleteSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
class AVLDeleteSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {

val KL = 26
val VL = 8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package scorex.crypto.authds.avltree

import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.PropSpec
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.propspec.AnyPropSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import scorex.crypto.authds.avltree.batch.{Insert, InsertOrUpdate, Lookup, Update}
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
import scorex.crypto.hash.Sha256

class AVLTreeSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
class AVLTreeSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {

val KL = 26
val VL = 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ package scorex.crypto.authds.avltree.batch

import com.google.common.primitives.Longs
import org.scalacheck.{Arbitrary, Gen}
import org.scalatest.PropSpec
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import scorex.crypto.authds.avltree.batch.BatchingPlayground.{D, HF, generateProver, time}
import org.scalatest.propspec.AnyPropSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import scorex.crypto.authds.legacy.avltree.AVLTree
import scorex.crypto.authds._
import scorex.crypto.encode.{Base16, Base58}
import scorex.crypto.hash.{Blake2b256, _}
import scorex.util.encode.{Base16, Base58}
import scorex.crypto.hash._
import scorex.utils.{ByteArray, Random}

import scala.util.Random.{nextInt => randomInt}
import scala.util.{Failure, Try}

class AVLBatchSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests
class AVLBatchSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests
with BatchTestingHelpers {

property("return removed leafs and internal nodes for small tree") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package scorex.crypto.authds.avltree.batch
import com.google.common.primitives.Longs
import org.scalacheck.commands.Commands
import org.scalacheck.{Gen, Prop}
import org.scalatest.PropSpec
import org.scalatest.propspec.AnyPropSpec
import scorex.crypto.authds._
import scorex.crypto.hash.{Blake2b256, Digest32}
import scorex.utils.{Random => RandomBytes}

import scala.util.{Failure, Random, Success, Try}

class AVLBatchStatefulSpecification extends PropSpec {
class AVLBatchStatefulSpecification extends AnyPropSpec {

property("BatchAVLProver: prove and verify") {
AVLCommands.property().check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LegacyProver(tree: AVLTree[_]) {
case Failure(e) => throw BatchFailure(e, m)
}
}
BatchSuccessSimple(aggregatedProofs)
BatchSuccessSimple(aggregatedProofs.toSeq)
} match {
case Success(p) => p
case Failure(e: BatchFailure) => e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package scorex.crypto.authds.avltree.batch

import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers
import scorex.crypto.authds.{ADKey, ADValue}
import scorex.crypto.hash.{Blake2b256, Digest32}
import scorex.utils.Random
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package scorex.crypto.authds.avltree.batch

import com.google.common.primitives.Longs
import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers
import scorex.crypto.authds.legacy.avltree.{AVLModifyProof, AVLTree}
import scorex.crypto.authds.{ADDigest, ADKey, ADValue}
import scorex.crypto.hash.{Blake2b256, Digest32, Sha256}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package scorex.crypto.authds.avltree.batch.serialization

import org.scalacheck.{Gen, Shrink}
import org.scalatest.PropSpec
import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.propspec.AnyPropSpec
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
import scorex.crypto.authds.avltree.batch._
import scorex.crypto.authds.{ADKey, ADValue, TwoPartyTests}
import scorex.crypto.hash.{Blake2b256, _}
import scorex.utils.Random

class AVLBatchSerializationSpecification extends PropSpec with GeneratorDrivenPropertyChecks with TwoPartyTests {
class AVLBatchSerializationSpecification extends AnyPropSpec with ScalaCheckDrivenPropertyChecks with TwoPartyTests {

val InitialTreeSize = 1000
val KL = 26
Expand Down
Loading