Skip to content

Commit

Permalink
refactoring: more precise types for ProofTreeLeaf + Hint.image
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Jul 30, 2023
1 parent 49d1255 commit 8988532
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion common/shared/src/test/scala/scalan/BaseTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ abstract class BaseShouldTests extends AnyFlatSpec with TestUtils {
}
}

protected implicit def convertToInAndIgnoreMethods2(resultOfStringPassedToVerb: ResultOfStringPassedToVerb) =
protected implicit def convertToInAndIgnoreMethods2(
resultOfStringPassedToVerb: ResultOfStringPassedToVerb): InAndIgnoreMethods2 =
new InAndIgnoreMethods2(resultOfStringPassedToVerb)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@ sealed trait UncheckedSigmaTree extends UncheckedTree {

trait UncheckedConjecture extends UncheckedSigmaTree with ProofTreeConjecture

trait UncheckedLeaf[SP <: SigmaBoolean] extends UncheckedSigmaTree with ProofTreeLeaf {
val proposition: SigmaBoolean
}
trait UncheckedLeaf extends UncheckedSigmaTree with ProofTreeLeaf

case class UncheckedSchnorr(
override val proposition: ProveDlog,
override val commitmentOpt: Option[FirstDLogProverMessage],
override val challenge: Challenge,
secondMessage: SecondDLogProverMessage
) extends UncheckedLeaf[ProveDlog]
) extends UncheckedLeaf

case class UncheckedDiffieHellmanTuple(
override val proposition: ProveDHTuple,
override val commitmentOpt: Option[FirstDHTupleProverMessage],
override val challenge: Challenge,
secondMessage: SecondDHTupleProverMessage
) extends UncheckedLeaf[ProveDHTuple]
) extends UncheckedLeaf

case class CAndUncheckedNode(
override val challenge: Challenge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ConjectureType extends Enumeration {
trait ProofTree extends Product

trait ProofTreeLeaf extends ProofTree {
val proposition: SigmaBoolean
val proposition: SigmaLeaf
val commitmentOpt: Option[FirstProverMessage]
}

Expand Down
27 changes: 12 additions & 15 deletions interpreter/shared/src/main/scala/sigmastate/interpreter/Hint.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package sigmastate.interpreter

import java.math.BigInteger

import sigmastate.{NodePosition, UncheckedTree}
import sigmastate.{NodePosition, SigmaLeaf, UncheckedTree}
import sigmastate.Values.SigmaBoolean
import sigmastate.basics.FirstProverMessage
import sigmastate.basics.VerifierMessage.Challenge
Expand All @@ -13,6 +12,10 @@ import sigmastate.basics.VerifierMessage.Challenge
* prover knows that pk2 is known to another party, the prover may prove the statement (with an empty proof for "pk2").
*/
trait Hint {
/**
* Public image of a secret
*/
def image: SigmaLeaf

/**
* A hint is related to a subtree (or a leaf) of a tree. This field encodes a position in the tree.
Expand All @@ -25,12 +28,6 @@ trait Hint {
* A hint which is indicating that a secret associated with its public image "image" is already proven.
*/
abstract class SecretProven extends Hint {

/**
* Public image of a secret which is proven
*/
def image: SigmaBoolean

/**
* Challenge used for a proof
*/
Expand All @@ -46,16 +43,16 @@ abstract class SecretProven extends Hint {
* A hint which contains a proof-of-knowledge for a secret associated with its public image "image",
* with also the mark that the proof is real.
*/
case class RealSecretProof(image: SigmaBoolean,
case class RealSecretProof(image: SigmaLeaf,
challenge: Challenge,
uncheckedTree: UncheckedTree,
override val position: NodePosition) extends SecretProven

/**
* A hint which contains a proof-of-knowledge for a secret associated with its public image "image",
* with also the mark that the proof is real.
* with also the mark that the proof is simulated (not real).
*/
case class SimulatedSecretProof(image: SigmaBoolean,
case class SimulatedSecretProof(image: SigmaLeaf,
challenge: Challenge,
uncheckedTree: UncheckedTree,
override val position: NodePosition) extends SecretProven
Expand All @@ -66,7 +63,7 @@ case class SimulatedSecretProof(image: SigmaBoolean,
* to randomness ("a" in a sigma protocol).
*/
abstract class CommitmentHint extends Hint {
def image: SigmaBoolean
/** Commitment to randomness (first message in a sigma protocol) */
def commitment: FirstProverMessage
}

Expand All @@ -78,7 +75,7 @@ abstract class CommitmentHint extends Hint {
* @param secretRandomness - randomness
* @param commitment - commitment to randomness used while proving knowledge of the secret
*/
case class OwnCommitment(override val image: SigmaBoolean,
case class OwnCommitment(override val image: SigmaLeaf,
secretRandomness: BigInteger,
commitment: FirstProverMessage,
override val position: NodePosition) extends CommitmentHint
Expand All @@ -89,7 +86,7 @@ case class OwnCommitment(override val image: SigmaBoolean,
* @param image - image of a secret
* @param commitment - commitment to randomness used while proving knowledge of the secret
*/
case class RealCommitment(override val image: SigmaBoolean,
case class RealCommitment(override val image: SigmaLeaf,
commitment: FirstProverMessage,
override val position: NodePosition) extends CommitmentHint

Expand All @@ -99,7 +96,7 @@ case class RealCommitment(override val image: SigmaBoolean,
* @param image - image of a secret
* @param commitment - commitment to randomness used while proving knowledge of the secret
*/
case class SimulatedCommitment(override val image: SigmaBoolean,
case class SimulatedCommitment(override val image: SigmaLeaf,
commitment: FirstProverMessage,
override val position: NodePosition) extends CommitmentHint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ trait ProverUtils extends Interpreter {
inner.children.zipWithIndex.foldLeft(hintsBag) { case (hb, (c, idx)) =>
traverseNode(c, realPropositions, simulatedPropositions, hb, position.child(idx))
}
case leaf: UncheckedLeaf[_] =>
case leaf: UncheckedLeaf =>
val realFound = realPropositions.contains(leaf.proposition)
val simulatedFound = simulatedPropositions.contains(leaf.proposition)
if (realFound || simulatedFound) {
Expand Down

0 comments on commit 8988532

Please sign in to comment.