Skip to content

Commit a610ce2

Browse files
authored
Merge pull request #55 from input-output-hk/ads-doc
AD-related code is fixed in README
2 parents 43c3eb6 + 3d68bc9 commit a610ce2

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ Here are code examples for generating proofs and checking them. In this example
9595
* 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)
9696

9797
```scala
98+
import com.google.common.primitives.Longs
99+
import scorex.crypto.authds.{ADKey, ADValue}
100+
import scorex.crypto.authds.avltree.batch._
101+
import scorex.crypto.hash.{Blake2b256, Digest32}
102+
98103
val prover = new BatchAVLProver(keyLength = 1, valueLengthOpt = Some(8))
99104
val initialDigest = prover.digest
100105
```
@@ -106,9 +111,9 @@ Here are code examples for generating proofs and checking them. In this example
106111
val key1 = Array(1:Byte)
107112
val key2 = Array(2:Byte)
108113
val key3 = Array(3:Byte)
109-
val op1 = Insert(key1, Longs.toByteArray(10))
110-
val op2 = Insert(key2, Longs.toByteArray(20))
111-
val op3 = Insert(key3, Longs.toByteArray(30))
114+
val op1 = Insert(ADKey @@ key1, ADValue @@ Longs.toByteArray(10))
115+
val op2 = Insert(ADKey @@ key2, ADValue @@ Longs.toByteArray(20))
116+
val op3 = Insert(ADKey @@ key3, ADValue @@ Longs.toByteArray(30))
112117
```
113118

114119
* 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
117122
prover.performOneOperation(op1) // Returns Success(None)
118123
prover.performOneOperation(op2) // Returns Success(None)
119124
prover.performOneOperation(op3) // Returns Success(None)
120-
val proof1 = prover.generateProof
125+
val proof1 = prover.generateProof()
121126
val digest1 = prover.digest
122127
```
123128
@@ -126,19 +131,19 @@ Here are code examples for generating proofs and checking them. In this example
126131
* 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`
127132

128133
```scala
129-
val op4 = Update(key1, Longs.toByteArray(50))
130-
val op5 = UpdateLongBy(key2, -40)
131-
val op6 = Lookup(key3)
132-
val op7 = Remove(Array(5:Byte))
133-
val op8 = Remove(key3)
134+
val op4 = Update(ADKey @@ key1, ADValue @@ Longs.toByteArray(50))
135+
val op5 = UpdateLongBy(ADKey @@ key2, -40)
136+
val op6 = Lookup(ADKey @@ key3)
137+
val op7 = Remove(ADKey @@ Array(5:Byte))
138+
val op8 = Remove(ADKey @@ key3)
134139
prover.performOneOperation(op4) // Returns Try(Some(Longs.toByteArray(10)))
135140
// Here we can, for example, perform prover.unauthenticatedLookup(key1) to get 50
136141
// without affecting the proof or anything else
137142
prover.performOneOperation(op5) // Returns Failure
138143
prover.performOneOperation(op6) // Returns Try(Some(Longs.toByteArray(30)))
139144
prover.performOneOperation(op7) // Returns Failure
140145
prover.performOneOperation(op8) // Returns Try(Some(Longs.toByteArray(30)))
141-
val proof2 = prover.generateProof // Proof only for op4 and op6
146+
val proof2 = prover.generateProof() // Proof only for op4 and op6
142147
val digest2 = prover.digest
143148
```
144149

@@ -147,14 +152,14 @@ Here are code examples for generating proofs and checking them. In this example
147152
* 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.
148153

149154
```scala
150-
val verifier1 = new BatchAVLVerifier(initialDigest, proof1, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(2), maxDeletes = Some(0))
151-
verifier1.performOneOperation(op1) // Returns Success(None)
155+
val verifier1 = new BatchAVLVerifier[Digest32, Blake2b256.type](initialDigest, proof1, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(2), maxDeletes = Some(0))
156+
verifier1.performOneOperation(op1) // Returns Success(None)
152157
verifier1.performOneOperation(op2) // Returns Success(None)
153158
verifier1.performOneOperation(op3) // Returns Success(None)
154159
verifier1.digest match {
155160
case Some(d1) if d1.sameElements(digest1) =>
156161
//If digest1 from the prover is already trusted, then verification of the second batch can simply start here
157-
val verifier2 = new BatchAVLVerifier(d1, proof2, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(3), maxDeletes = Some(1))
162+
val verifier2 = new BatchAVLVerifier[Digest32, Blake2b256.type](d1, proof2, keyLength = 1, valueLengthOpt = Some(8), maxNumOperations = Some(3), maxDeletes = Some(1))
158163
verifier2.performOneOperation(op4) // Returns Try(Some(Longs.toByteArray(10)))
159164
verifier2.performOneOperation(op6) // Returns Try(Some(Longs.toByteArray(30)))
160165
verifier2.performOneOperation(op8) // Returns Try(Some(Longs.toByteArray(30)))

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name := "scrypto"
44

55
lazy val commonSettings = Seq(
66
organization := "org.scorexfoundation",
7-
version := "2.1.2",
7+
version := "2.1.3-SNAPSHOT",
88
scalaVersion := "2.12.5",
99
licenses := Seq("CC0" -> url("https://creativecommons.org/publicdomain/zero/1.0/legalcode")),
1010
homepage := Some(url("https://github.com/input-output-hk/scrypto")),

lock.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencyOverrides in ThisBuild ++= Seq(
88
"com.sun.mail" % "javax.mail" % "1.6.0",
99
"com.typesafe.scala-logging" % "scala-logging_2.12" % "3.9.0",
1010
"javax.activation" % "activation" % "1.1",
11-
"org.bouncycastle" % "bcprov-jdk15on" % "1.59",
11+
"org.bouncycastle" % "bcprov-jdk15on" % "1.60",
1212
"org.rudogma" % "supertagged_2.12" % "1.4",
1313
"org.slf4j" % "slf4j-api" % "1.8.0-beta1",
1414
"org.whispersystems" % "curve25519-java" % "0.5.0"

0 commit comments

Comments
 (0)