-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/refactoring' into multisig
# Conflicts: # sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala
- Loading branch information
Showing
24 changed files
with
241 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 26 additions & 93 deletions
119
interpreter/shared/src/main/scala/sigmastate/UncheckedTree.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,58 @@ | ||
package sigmastate | ||
|
||
import java.util.Arrays | ||
import sigmastate.basics.DLogProtocol.{FirstDLogProverMessage, ProveDlog, SecondDLogProverMessage} | ||
import sigmastate.basics.VerifierMessage.Challenge | ||
import sigmastate.Values.SigmaBoolean | ||
import sigmastate.basics.{FirstDiffieHellmanTupleProverMessage, ProveDHTuple, SecondDiffieHellmanTupleProverMessage} | ||
import sigmastate.basics.{FirstDHTupleProverMessage, ProveDHTuple, SecondDHTupleProverMessage} | ||
import sigmastate.crypto.GF2_192_Poly | ||
|
||
sealed trait UncheckedTree extends ProofTree | ||
|
||
case object NoProof extends UncheckedTree | ||
|
||
sealed trait UncheckedSigmaTree extends UncheckedTree { | ||
val challenge: Array[Byte] | ||
val challenge: Challenge | ||
} | ||
|
||
trait UncheckedConjecture extends UncheckedSigmaTree with ProofTreeConjecture { | ||
|
||
override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { | ||
case x: UncheckedConjecture => | ||
Arrays.equals(challenge, x.challenge) && children == x.children | ||
case _ => false | ||
}) | ||
|
||
override def hashCode(): Int = | ||
31 * Arrays.hashCode(challenge) + children.hashCode() | ||
} | ||
trait UncheckedConjecture extends UncheckedSigmaTree with ProofTreeConjecture | ||
|
||
trait UncheckedLeaf[SP <: SigmaBoolean] extends UncheckedSigmaTree with ProofTreeLeaf { | ||
val proposition: SigmaBoolean | ||
} | ||
|
||
case class UncheckedSchnorr(override val proposition: ProveDlog, | ||
override val commitmentOpt: Option[FirstDLogProverMessage], | ||
override val challenge: Challenge, | ||
secondMessage: SecondDLogProverMessage) | ||
extends UncheckedLeaf[ProveDlog] { | ||
case class UncheckedSchnorr( | ||
override val proposition: ProveDlog, | ||
override val commitmentOpt: Option[FirstDLogProverMessage], | ||
override val challenge: Challenge, | ||
secondMessage: SecondDLogProverMessage | ||
) extends UncheckedLeaf[ProveDlog] | ||
|
||
override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { | ||
case x: UncheckedSchnorr => | ||
// NOTE, proposition is not compared because it is included into challenge | ||
// like `challenge = hash(prop ++ msg)` | ||
commitmentOpt == x.commitmentOpt && | ||
Arrays.equals(challenge, x.challenge) && | ||
secondMessage == x.secondMessage | ||
case _ => false | ||
}) | ||
|
||
override def hashCode(): Int = { | ||
var h = commitmentOpt.hashCode() | ||
h = 31 * h + Arrays.hashCode(challenge) | ||
h = 31 * h + secondMessage.hashCode() | ||
h | ||
} | ||
} | ||
|
||
|
||
case class UncheckedDiffieHellmanTuple(override val proposition: ProveDHTuple, | ||
override val commitmentOpt: Option[FirstDiffieHellmanTupleProverMessage], | ||
override val challenge: Challenge, | ||
secondMessage: SecondDiffieHellmanTupleProverMessage) | ||
extends UncheckedLeaf[ProveDHTuple] { | ||
|
||
override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { | ||
case x: UncheckedDiffieHellmanTuple => | ||
// NOTE, proposition is not compared because it is included into challenge | ||
// like `challenge = hash(prop ++ msg)` | ||
commitmentOpt == x.commitmentOpt && | ||
Arrays.equals(challenge, x.challenge) && | ||
secondMessage == x.secondMessage | ||
case _ => false | ||
}) | ||
|
||
override def hashCode(): Int = { | ||
var h = commitmentOpt.hashCode() | ||
h = 31 * h + Arrays.hashCode(challenge) | ||
h = 31 * h + secondMessage.hashCode() | ||
h | ||
} | ||
} | ||
|
||
case class CAndUncheckedNode(override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree]) | ||
extends UncheckedConjecture { | ||
case class UncheckedDiffieHellmanTuple( | ||
override val proposition: ProveDHTuple, | ||
override val commitmentOpt: Option[FirstDHTupleProverMessage], | ||
override val challenge: Challenge, | ||
secondMessage: SecondDHTupleProverMessage | ||
) extends UncheckedLeaf[ProveDHTuple] | ||
|
||
case class CAndUncheckedNode( | ||
override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree]) extends UncheckedConjecture { | ||
override val conjectureType = ConjectureType.AndConjecture | ||
} | ||
|
||
|
||
case class COrUncheckedNode(override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree]) extends UncheckedConjecture { | ||
|
||
case class COrUncheckedNode( | ||
override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree]) extends UncheckedConjecture { | ||
override val conjectureType = ConjectureType.OrConjecture | ||
|
||
} | ||
|
||
case class CThresholdUncheckedNode(override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree], | ||
k: Integer, | ||
polynomialOpt: Option[GF2_192_Poly]) extends UncheckedConjecture { | ||
case class CThresholdUncheckedNode( | ||
override val challenge: Challenge, | ||
override val children: Seq[UncheckedSigmaTree], | ||
k: Integer, | ||
polynomialOpt: Option[GF2_192_Poly]) extends UncheckedConjecture { | ||
require(children.length <= 255) // Our polynomial arithmetic can take only byte inputs | ||
require(k >= 0 && k <= children.length) | ||
|
||
override val conjectureType = ConjectureType.ThresholdConjecture | ||
|
||
override def canEqual(other: Any) = other.isInstanceOf[CThresholdUncheckedNode] | ||
|
||
override def equals(other: Any) = (this eq other.asInstanceOf[AnyRef]) || (other match { | ||
case other: CThresholdUncheckedNode => | ||
Arrays.equals(challenge, other.challenge) && | ||
children == other.children && | ||
k == other.k && | ||
polynomialOpt == other.polynomialOpt | ||
case _ => false | ||
}) | ||
|
||
override def hashCode(): Int = { | ||
var h = Arrays.hashCode(challenge) | ||
h = 31 * h + children.hashCode | ||
h = 31 * h + k.hashCode() | ||
h = 31 * h + polynomialOpt.hashCode() | ||
h | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.