Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

registers, collections, collection operations draft #1

Merged
merged 31 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
adfeec5
registers
kushti Nov 11, 2017
d2dcc7e
ByteLeaf
kushti Nov 11, 2017
44cc678
operations derived from TwoArgumentsOperation
kushti Nov 11, 2017
947b1f1
typo fix
kushti Nov 11, 2017
9cd627b
BoxLeaf, Extract, Self
kushti Nov 11, 2017
ca7c636
BoxField.Bytes
kushti Nov 11, 2017
5cd6812
Transformer
kushti Nov 11, 2017
2105ebd
poster files
kushti Nov 13, 2017
6c109e4
explicitly naming BoxLeaf's value parameter in Self
kushti Nov 13, 2017
63cc62b
removing docs/ for simpler merging
kushti Nov 13, 2017
963b84d
Merge remote-tracking branch 'remotes/origin/master' into register
kushti Nov 13, 2017
acfedd7
Self init fix, fake message externalized
kushti Nov 14, 2017
ee5e9d2
fakeMessage
kushti Nov 14, 2017
ca924e2
BoxLeaf made trait
kushti Nov 14, 2017
f4402a0
Extract family, RunExtract
kushti Nov 14, 2017
4383b4c
MapCollection / Exists, Utxocontext rework
kushti Nov 14, 2017
3d3e5dd
new hierarchy playground example
kushti Nov 18, 2017
c51afeb
new Value hierarchy
kushti Nov 18, 2017
1d03741
CollectionLeaf / Inputs / Outputs
kushti Nov 18, 2017
6699dad
MapCollection
kushti Nov 18, 2017
942c00a
Extract family rework, BoxLeaf rework
kushti Nov 18, 2017
fb99ef8
Fold & Sum
kushti Nov 18, 2017
6714b85
map + sum example
kushti Nov 18, 2017
96501e6
Exists stub
kushti Nov 18, 2017
6e87a39
cats.scala & Proof.scala are removed
kushti Nov 18, 2017
544baef
Triple/Relation typing
kushti Nov 21, 2017
2015fe0
OutputAmount, OutputScript, TxHasOutput, TxOut removed
kushti Nov 21, 2017
fbdfe54
exists test passed
kushti Nov 21, 2017
92a4e54
EQ/NEQ fix
kushti Nov 21, 2017
cbe96f7
transformationReady
kushti Nov 21, 2017
2d16755
ignoring demurrage example
kushti Nov 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ val testingDependencies = Seq(
)

libraryDependencies ++= Seq(
"org.bouncycastle" % "bcprov-jdk15on" % "1.58",
"com.typesafe.akka" %% "akka-actor" % "2.4.+",
"org.scorexfoundation" %% "scorex-core" % "2.+",
"org.bitbucket.inkytonik.kiama" %% "kiama" % "2.1.0"
Expand Down
21 changes: 0 additions & 21 deletions src/main/scala/sigmastate/Proof.scala

This file was deleted.

36 changes: 20 additions & 16 deletions src/main/scala/sigmastate/interpreter/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import scapi.sigma.rework.FirstProverMessage
import sigmastate.utxo.CostTable




trait Interpreter {
type CTX <: Context[CTX]
type StateT <: StateTree
type SigmaT <: SigmaTree

type ProofT = UncheckedTree //todo: ProofT <: UncheckedTree ?

val dlogGroup: DlogGroup = new BcDlogECFp()
lazy val dlogGroup: DlogGroup = new BcDlogECFp()

/**
* Max cost of a script interpreter can accept
Expand All @@ -55,24 +53,30 @@ trait Interpreter {
}

protected val relations: Strategy = everywherebu(rule[SigmaStateTree] {
case EQ(l: Value, r: Value) => BooleanLeaf.fromBoolean(l == r)
case NEQ(l: Value, r: Value) => BooleanLeaf.fromBoolean(l != r)
case GT(l: IntLeaf, r: IntLeaf) => BooleanLeaf.fromBoolean(l.value > r.value)
case GE(l: IntLeaf, r: IntLeaf) => BooleanLeaf.fromBoolean(l.value >= r.value)
case LT(l: IntLeaf, r: IntLeaf) => BooleanLeaf.fromBoolean(l.value < r.value)
case LE(l: IntLeaf, r: IntLeaf) => BooleanLeaf.fromBoolean(l.value <= r.value)
case EQ(l: Value, r: Value) if l.evaluated && r.evaluated =>
BooleanLeafConstant.fromBoolean(l == r)
case NEQ(l: Value, r: Value) if l.evaluated && r.evaluated =>
BooleanLeafConstant.fromBoolean(l != r)
case GT(l: IntLeafConstant, r: IntLeafConstant) =>
BooleanLeafConstant.fromBoolean(l.value > r.value)
case GE(l: IntLeafConstant, r: IntLeafConstant) =>
BooleanLeafConstant.fromBoolean(l.value >= r.value)
case LT(l: IntLeafConstant, r: IntLeafConstant) =>
BooleanLeafConstant.fromBoolean(l.value < r.value)
case LE(l: IntLeafConstant, r: IntLeafConstant) =>
BooleanLeafConstant.fromBoolean(l.value <= r.value)
})

protected val operations: Strategy = everywherebu(rule[SigmaStateTree] {
case Plus(l: IntLeaf, r: IntLeaf) => IntLeaf(l.value + r.value)
case Minus(l: IntLeaf, r: IntLeaf) => IntLeaf(l.value - r.value)
case Xor(l: ByteArrayLeaf, r: ByteArrayLeaf) =>
case Plus(l: IntLeafConstant, r: IntLeafConstant) => IntLeafConstant(l.value + r.value)
case Minus(l: IntLeafConstant, r: IntLeafConstant) => IntLeafConstant(l.value - r.value)
case Xor(l: ByteArrayLeafConstant, r: ByteArrayLeafConstant) =>
assert(l.value.length == r.value.length)
ByteArrayLeaf(Helpers.xor(l.value, r.value))
case Append(l: ByteArrayLeaf, r: ByteArrayLeaf) =>
ByteArrayLeafConstant(Helpers.xor(l.value, r.value))
case Append(l: ByteArrayLeafConstant, r: ByteArrayLeafConstant) =>
require(l.value.length + r.value.length < 10000) //todo: externalize this maximum intermediate value length limit
ByteArrayLeaf(l.value ++ r.value)
case CalcBlake2b256(l: ByteArrayLeaf) => ByteArrayLeaf(Blake2b256(l.value))
ByteArrayLeafConstant(l.value ++ r.value)
case c@CalcBlake2b256Inst(l: ByteArrayLeafConstant) if l.evaluated => c.function(l)
})

protected val conjs: Strategy = everywherebu(rule[SigmaStateTree] {
Expand Down
8 changes: 5 additions & 3 deletions src/main/scala/sigmastate/interpreter/ProverInterpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ trait ProverInterpreter extends Interpreter with AttributionCore {

val secrets: Seq[SigmaProtocolPrivateInput[_]]

val contextExtenders: Map[Int, ByteArrayLeaf]
val contextExtenders: Map[Int, ByteArrayLeafConstant]

def enrichContext(tree: SigmaStateTree): ContextExtension = {
val targetName = CustomByteArray.getClass.getSimpleName.replace("$", "")
Expand Down Expand Up @@ -106,14 +106,16 @@ trait ProverInterpreter extends Interpreter with AttributionCore {
def prove(exp: SigmaStateTree, context: CTX, message: Array[Byte]): Try[ProverResult[ProofT]] = Try {
val candidateProp = reduceToCrypto(exp, context).get

println(candidateProp)

val (cProp, ext) = (candidateProp.isInstanceOf[SigmaT] match {
case true => (candidateProp, ContextExtension(Map()))
case false =>
val extension = enrichContext(candidateProp)
//todo: no need for full reduction here probably
(reduceToCrypto(candidateProp, context.withExtension(extension)).get, extension)
}).ensuring { res =>
res._1.isInstanceOf[BooleanLeaf] ||
res._1.isInstanceOf[BooleanLeafConstant] ||
res._1.isInstanceOf[CAND] ||
res._1.isInstanceOf[COR] ||
res._1.isInstanceOf[DLogNode] ||
Expand All @@ -122,7 +124,7 @@ trait ProverInterpreter extends Interpreter with AttributionCore {


ProverResult(cProp match {
case tree: BooleanLeaf =>
case tree: BooleanLeafConstant =>
tree match {
case TrueLeaf => NoProof
case FalseLeaf => ???
Expand Down
Loading