diff --git a/README.md b/README.md index 669311b2..c600344a 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,11 @@ Here are code examples for generating proofs and checking them. In this example * First, we create a prover and get an initial digest from it (in a real application, this value is a public constant because anyone, including verifiers, can compute it by using the same two lines of code) ```scala + import com.google.common.primitives.Longs + import scorex.crypto.authds.{ADKey, ADValue} + import scorex.crypto.authds.avltree.batch._ + import scorex.crypto.hash.{Blake2b256, Digest32} + val prover = new BatchAVLProver(keyLength = 1, valueLengthOpt = Some(8)) val initialDigest = prover.digest ``` @@ -106,9 +111,9 @@ Here are code examples for generating proofs and checking them. In this example val key1 = Array(1:Byte) val key2 = Array(2:Byte) val key3 = Array(3:Byte) - val op1 = Insert(key1, Longs.toByteArray(10)) - val op2 = Insert(key2, Longs.toByteArray(20)) - val op3 = Insert(key3, Longs.toByteArray(30)) + val op1 = Insert(ADKey @@ key1, ADValue @@ Longs.toByteArray(10)) + val op2 = Insert(ADKey @@ key2, ADValue @@ Longs.toByteArray(20)) + val op3 = Insert(ADKey @@ key3, ADValue @@ Longs.toByteArray(30)) ``` * The prover applies the three modifications to the empty tree, obtains the first batch proof, and announces the next digest `digest1`. @@ -117,7 +122,7 @@ Here are code examples for generating proofs and checking them. In this example prover.performOneOperation(op1) // Returns Success(None) prover.performOneOperation(op2) // Returns Success(None) prover.performOneOperation(op3) // Returns Success(None) - val proof1 = prover.generateProof + val proof1 = prover.generateProof() val digest1 = prover.digest ``` @@ -126,11 +131,11 @@ Here are code examples for generating proofs and checking them. In this example * Next, the prover attempts to perform five more modifications: changing the first value to 50, subtracting 40 from the second value (which will fail, because our UpDateLongBy operation is designed to fail on negative values), looking up the third value, deleting the key 5 (which will also fail, because key 5 does not exist), and deleting the third value. After the four operations, the prover obtains a second proof, and announces the new digest `digest2` ```scala - val op4 = Update(key1, Longs.toByteArray(50)) - val op5 = UpdateLongBy(key2, -40) - val op6 = Lookup(key3) - val op7 = Remove(Array(5:Byte)) - val op8 = Remove(key3) + val op4 = Update(ADKey @@ key1, ADValue @@ Longs.toByteArray(50)) + val op5 = UpdateLongBy(ADKey @@ key2, -40) + val op6 = Lookup(ADKey @@ key3) + val op7 = Remove(ADKey @@ Array(5:Byte)) + val op8 = Remove(ADKey @@ key3) prover.performOneOperation(op4) // Returns Try(Some(Longs.toByteArray(10))) // Here we can, for example, perform prover.unauthenticatedLookup(key1) to get 50 // without affecting the proof or anything else @@ -138,7 +143,7 @@ Here are code examples for generating proofs and checking them. In this example prover.performOneOperation(op6) // Returns Try(Some(Longs.toByteArray(30))) prover.performOneOperation(op7) // Returns Failure prover.performOneOperation(op8) // Returns Try(Some(Longs.toByteArray(30))) - val proof2 = prover.generateProof // Proof only for op4 and op6 + val proof2 = prover.generateProof() // Proof only for op4 and op6 val digest2 = prover.digest ``` @@ -147,14 +152,14 @@ Here are code examples for generating proofs and checking them. In this example * Once the verifier for a particular batch is constructed, we perform the same operations as the prover, one by one (but not the ones that failed for the prover). If verification fails at any point (at construction time or during an operation), the verifier digest will equal None from that point forward, and no further verifier operations will change the digest. Else, the verifier's new digest is the correct one for the tree as modified by the verifier. Furthermore, if the verifier performed the same modifications as the prover, then the verifier and prover digests will match. ```scala - val verifier1 = new BatchAVLVerifier(initialDigest, proof1, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(2), maxDeletes = Some(0)) - verifier1.performOneOperation(op1) // Returns Success(None) + val verifier1 = new BatchAVLVerifier[Digest32, Blake2b256.type](initialDigest, proof1, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(2), maxDeletes = Some(0)) + verifier1.performOneOperation(op1) // Returns Success(None) verifier1.performOneOperation(op2) // Returns Success(None) verifier1.performOneOperation(op3) // Returns Success(None) verifier1.digest match { case Some(d1) if d1.sameElements(digest1) => //If digest1 from the prover is already trusted, then verification of the second batch can simply start here - val verifier2 = new BatchAVLVerifier(d1, proof2, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(3), maxDeletes = Some(1)) + val verifier2 = new BatchAVLVerifier[Digest32, Blake2b256.type](d1, proof2, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(3), maxDeletes = Some(1)) verifier2.performOneOperation(op4) // Returns Try(Some(Longs.toByteArray(10))) verifier2.performOneOperation(op6) // Returns Try(Some(Longs.toByteArray(30))) verifier2.performOneOperation(op8) // Returns Try(Some(Longs.toByteArray(30))) diff --git a/build.sbt b/build.sbt index f5e0dff4..54217150 100644 --- a/build.sbt +++ b/build.sbt @@ -4,7 +4,7 @@ name := "scrypto" lazy val commonSettings = Seq( organization := "org.scorexfoundation", - version := "2.1.2", + version := "2.1.3-SNAPSHOT", scalaVersion := "2.12.5", licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")), homepage := Some(url("https://github.com/input-output-hk/scrypto")), diff --git a/lock.sbt b/lock.sbt index 80815a40..4477fc27 100644 --- a/lock.sbt +++ b/lock.sbt @@ -8,7 +8,7 @@ dependencyOverrides in ThisBuild ++= Seq( "com.sun.mail" % "javax.mail" % "1.6.0", "com.typesafe.scala-logging" % "scala-logging_2.12" % "3.9.0", "javax.activation" % "activation" % "1.1", - "org.bouncycastle" % "bcprov-jdk15on" % "1.59", + "org.bouncycastle" % "bcprov-jdk15on" % "1.60", "org.rudogma" % "supertagged_2.12" % "1.4", "org.slf4j" % "slf4j-api" % "1.8.0-beta1", "org.whispersystems" % "curve25519-java" % "0.5.0"