11package scorex .crypto .authds .avltree .batch
22
33import scorex .crypto .authds .{Balance , _ }
4- import scorex .crypto .encode .Base16
54import scorex .crypto .hash .Digest
6- import scorex .utils .{ ByteArray , ScryptoLogging }
5+ import scorex .utils .ByteArray
76
87import scala .collection .mutable .ArrayBuffer
98import scala .util .{Failure , Success , Try }
@@ -13,7 +12,7 @@ import scala.util.{Failure, Success, Try}
1312 * Code common to the prover and verifier of https://eprint.iacr.org/2016/994
1413 * (see Appendix B, "Our Algorithms")
1514 */
16- trait AuthenticatedTreeOps [D <: Digest ] extends BatchProofConstants with ScryptoLogging {
15+ trait AuthenticatedTreeOps [D <: Digest ] extends BatchProofConstants with ToStringHelper {
1716
1817 type ChangeHappened = Boolean
1918 type HeightIncreased = Boolean
@@ -39,17 +38,17 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
3938 protected def onNodeVisit (n : Node [D ], operation : Operation , isRotate : Boolean = false ): Unit = {
4039 n match {
4140 case p : ProverNodes [D ] if collectChangedNodes && ! n.visited && ! p.isNew =>
42- if (isRotate) {
43- // during rotate operation node may stay in the tree in a different position
44- changedNodesBufferToCheck += p
45- } else if (operation.isInstanceOf [Insert ] || operation.isInstanceOf [Remove ]
46- || operation.isInstanceOf [InsertOrUpdate ]) {
47- // during non-rotate insert and remove operations nodes on the path should not be presented in a new tree
48- changedNodesBuffer += p
49- } else if (! operation.isInstanceOf [Lookup ]) {
50- // during other non-lookup operations we don't know, whether node will stay in thee tree or not
51- changedNodesBufferToCheck += p
52- }
41+ if (isRotate) {
42+ // during rotate operation node may stay in the tree in a different position
43+ changedNodesBufferToCheck += p
44+ } else if (operation.isInstanceOf [Insert ] || operation.isInstanceOf [Remove ]
45+ || operation.isInstanceOf [InsertOrUpdate ]) {
46+ // during non-rotate insert and remove operations nodes on the path should not be presented in a new tree
47+ changedNodesBuffer += p
48+ } else if (! operation.isInstanceOf [Lookup ]) {
49+ // during other non-lookup operations we don't know, whether node will stay in thee tree or not
50+ changedNodesBufferToCheck += p
51+ }
5352 case _ =>
5453 }
5554 n.visited = true
@@ -382,7 +381,7 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
382381 if (rightChild.balance < 0 ) {
383382 // double left rotate
384383 // I know rightChild.left is not a leaf, because rightChild has a higher subtree on the left
385- onNodeVisit(rightChild.left, operation)
384+ onNodeVisit(rightChild.left, operation, isRotate = true )
386385 (doubleLeftRotate(newRoot, newLeft, rightChild), true )
387386 } else {
388387 // single left rotate
@@ -409,7 +408,7 @@ trait AuthenticatedTreeOps[D <: Digest] extends BatchProofConstants with Scrypto
409408 if (leftChild.balance > 0 ) {
410409 // double right rotate
411410 // I know leftChild.right is not a leaf, because leftChild has a higher subtree on the right
412- onNodeVisit(leftChild.right, operation)
411+ onNodeVisit(leftChild.right, operation, isRotate = true )
413412 (doubleRightRotate(r, leftChild, newRight), true )
414413 } else {
415414 // single right rotate
0 commit comments