Skip to content

Commit 8489811

Browse files
authored
Merge pull request #1036 from ergoplatform/v5.0.15
Candidate for 5.0.15 release
2 parents 493cbfb + 91b7fc5 commit 8489811

File tree

11 files changed

+84
-36
lines changed

11 files changed

+84
-36
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ ThisBuild / dynverSeparator := "-"
8282

8383
val bouncycastleBcprov = "org.bouncycastle" % "bcprov-jdk15on" % "1.66"
8484

85-
val scrypto = "org.scorexfoundation" %% "scrypto" % "2.3.0-4-a0bc6176-SNAPSHOT"
85+
val scrypto = "org.scorexfoundation" %% "scrypto" % "3.0.0"
8686
val scryptoDependency =
87-
libraryDependencies += "org.scorexfoundation" %%% "scrypto" % "2.3.0-4-a0bc6176-SNAPSHOT"
87+
libraryDependencies += "org.scorexfoundation" %%% "scrypto" % "3.0.0"
8888

8989
val scorexUtil = "org.scorexfoundation" %% "scorex-util" % "0.2.1"
9090
val scorexUtilDependency =

data/shared/src/main/scala/sigma/ast/SigmaPredef.scala

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,6 @@ object SigmaPredef {
136136
Seq(ArgInfo("condition", "boolean value to embed in SigmaProp value")))
137137
)
138138

139-
val GetVarFunc = PredefinedFunc("getVar",
140-
Lambda(Array(paramT), Array("varId" -> SByte), SOption(tT), None),
141-
PredefFuncInfo(
142-
{ case (Ident(_, SFunc(_, SOption(rtpe), _)), Seq(id: Constant[SNumericType]@unchecked)) =>
143-
mkGetVar(SByte.downcast(id.value.asInstanceOf[AnyVal]), rtpe)
144-
}),
145-
OperationInfo(GetVar,
146-
"Get context variable with given \\lst{varId} and type.",
147-
Seq(ArgInfo("varId", "\\lst{Byte} identifier of context variable")))
148-
)
149-
150139
def PKFunc(networkPrefix: NetworkPrefix) = PredefinedFunc("PK",
151140
Lambda(Array("input" -> SString), SSigmaProp, None),
152141
PredefFuncInfo(
@@ -366,13 +355,23 @@ object SigmaPredef {
366355
ArgInfo("newValues", "new values to be injected into the corresponding positions in ErgoTree.constants array")))
367356
)
368357

358+
val GetVarFunc = PredefinedFunc("getVar",
359+
Lambda(Array(paramT), Array("varId" -> SByte), SOption(tT), None),
360+
PredefFuncInfo(
361+
{ case (Ident(_, SFunc(_, SOption(rtpe), _)), Seq(id: Constant[SNumericType]@unchecked)) =>
362+
mkGetVar(SByte.downcast(id.value.asInstanceOf[AnyVal]), rtpe)
363+
}),
364+
OperationInfo(GetVar,
365+
"Get context variable with given \\lst{varId} and type.",
366+
Seq(ArgInfo("varId", "\\lst{Byte} identifier of context variable")))
367+
)
368+
369369
val ExecuteFromVarFunc = PredefinedFunc("executeFromVar",
370-
Lambda(
371-
Seq(paramT),
372-
Array("id" -> SByte),
373-
tT, None
374-
),
375-
PredefFuncInfo(undefined),
370+
Lambda(Array(paramT), Array("id" -> SByte), tT, None),
371+
PredefFuncInfo(
372+
{ case (Ident(_, SFunc(_, rtpe, _)), Seq(id: Constant[SNumericType]@unchecked)) =>
373+
mkDeserializeContext(SByte.downcast(id.value.asInstanceOf[AnyVal]), rtpe)
374+
}),
376375
OperationInfo(DeserializeContext,
377376
"""Extracts context variable as \lst{Coll[Byte]}, deserializes it to script
378377
| and then executes this script in the current context.

interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ trait Interpreter {
126126
case _ => None
127127
}
128128

129-
/** Extracts proposition for ErgoTree handing soft-fork condition.
129+
/** Extracts proposition for ErgoTree handling soft-fork condition.
130130
* @note soft-fork handler */
131131
protected def propositionFromErgoTree(ergoTree: ErgoTree, context: CTX): SigmaPropValue = {
132132
val validationSettings = context.validationSettings

profile-sbt.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

sc/shared/src/main/scala/sigma/compiler/ir/Base.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package sigma.compiler.ir
22

33
import debox.{cfor, Buffer => DBuffer}
44
import sigma.compiler.ir.core.MutableLazy
5-
import sigma.data.OverloadHack.Overloaded1
5+
import sigma.ast.{DeserializeContext, SType}
66
import sigma.data.{AVHashMap, Nullable, RType}
7+
import sigma.data.OverloadHack.Overloaded1
78
import sigma.reflection.RConstructor
89
import sigma.util.StringUtil
910

@@ -12,7 +13,7 @@ import scala.annotation.unchecked.uncheckedVariance
1213
import scala.annotation.{implicitNotFound, unused}
1314
import scala.collection.compat.immutable.ArraySeq
1415
import scala.collection.mutable
15-
import scala.language.implicitConversions
16+
import scala.language.{existentials, implicitConversions}
1617

1718
/**
1819
* The Base trait houses common AST nodes. It also manages a list of encountered definitions which
@@ -169,7 +170,7 @@ abstract class Base { thisIR: IRContext =>
169170

170171
/** Create a copy of this definition applying the given transformer to all `syms`. */
171172
def transform(t: Transformer): Def[T] =
172-
!!!(s"Cannot transfrom definition using transform($this)", self)
173+
!!!(s"Cannot transform definition using transform($this)", self)
173174

174175
/** Clone this definition transforming all symbols using `t`.
175176
* If new Def[A] is created, it is added to the graph with collapsing and rewriting.
@@ -203,10 +204,11 @@ abstract class Base { thisIR: IRContext =>
203204
}
204205
}
205206

206-
/** Logical AND between two pattern matches of the save value `x`.
207-
* Can be used to construct patterns like `case P1 && P2 => ...` */
208-
object && {
209-
def unapply[T](x: T): Option[(T,T)] = Some((x, x))
207+
/**
208+
* Def done in order to carry on DeserializeContext through stages of compilation intact
209+
*/
210+
case class DeserializeContextDef[V <: SType](d: DeserializeContext[V], e: Elem[V#WrappedType]) extends Def[V#WrappedType] {
211+
override def resultType: Elem[V#WrappedType] = e
210212
}
211213

212214
/** Base class for virtualized instances of type companions.
@@ -383,7 +385,6 @@ abstract class Base { thisIR: IRContext =>
383385
/** Returns the string like `x45: Int = Const(10)` */
384386
def toStringWithDefinition: String
385387
def varNameWithType = varName + ":" + elem.name
386-
387388
}
388389

389390
/** Untyped shortcut sinonim of Ref, which is used as untyped reference to graph nodes (definitions).

sc/shared/src/main/scala/sigma/compiler/ir/GraphBuilding.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ trait GraphBuilding extends Base with DefRewriting { IR: IRContext =>
549549
val e = stypeToElem(optTpe.elemType)
550550
ctx.getVar(id)(e)
551551

552+
case d: DeserializeContext[T] =>
553+
val e = stypeToElem(d.tpe)
554+
DeserializeContextDef(d, e)
555+
552556
case ValUse(valId, _) =>
553557
env.getOrElse(valId, !!!(s"ValUse $valId not found in environment $env"))
554558

sc/shared/src/main/scala/sigma/compiler/ir/TreeBuilding.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ trait TreeBuilding extends Base { IR: IRContext =>
189189
val tpe = elemToSType(s.elem)
190190
mkConstant[tpe.type](wc.constValue.asInstanceOf[tpe.WrappedType], tpe)
191191

192+
case Def(DeserializeContextDef(d, _)) =>
193+
d
194+
192195
case Def(IsContextProperty(v)) => v
193196
case s if s == sigmaDslBuilder => Global
194197

sc/shared/src/main/scala/sigma/compiler/phases/SigmaTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SigmaTyper(val builder: SigmaBuilder,
3737

3838
private def processGlobalMethod(srcCtx: Nullable[SourceContext],
3939
method: SMethod,
40-
args: IndexedSeq[SValue]) = {
40+
args: IndexedSeq[SValue]): SValue = {
4141
val global = Global.withPropagatedSrcCtx(srcCtx)
4242
val node = for {
4343
pf <- method.irInfo.irBuilder if lowerMethodCalls

sc/shared/src/test/scala/sigma/SigmaDslTesting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class SigmaDslTesting extends AnyPropSpec
323323
// Compile script the same way it is performed by applications (i.e. via Ergo Appkit)
324324
val prop = compile(env, code)(IR).asSigmaProp
325325

326-
// Add additional oparations which are not yet implemented in ErgoScript compiler
326+
// Add additional operations which are not yet implemented in ErgoScript compiler
327327
val multisig = AtLeast(
328328
IntConstant(2),
329329
Array(

sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sigmastate.utxo
22

33
import org.ergoplatform.ErgoBox.{AdditionalRegisters, R6, R8}
44
import org.ergoplatform._
5+
import sigma.Colls
56
import sigma.Extensions.ArrayOps
67
import sigma.ast.SCollection.SByteArray
78
import sigma.ast.SType.AnyOps
@@ -19,6 +20,7 @@ import sigmastate.interpreter.Interpreter._
1920
import sigma.ast.Apply
2021
import sigma.eval.EvalSettings
2122
import sigma.exceptions.InvalidType
23+
import sigma.serialization.ValueSerializer
2224
import sigmastate.utils.Helpers._
2325

2426
import java.math.BigInteger
@@ -157,6 +159,50 @@ class BasicOpsSpecification extends CompilerTestingCommons
157159
)
158160
}
159161

162+
property("executeFromVar - SigmaProp") {
163+
val script = GT(Height, IntConstant(-1)).toSigmaProp
164+
val scriptBytes = ValueSerializer.serialize(script)
165+
val customExt = Seq(21.toByte -> ByteArrayConstant(scriptBytes))
166+
test("executeFromVar", env, customExt,
167+
"executeFromVar[SigmaProp](21)",
168+
null,
169+
true
170+
)
171+
}
172+
173+
property("executeFromVar - Int") {
174+
val valueBytes = ValueSerializer.serialize(Plus(IntConstant(2), IntConstant(3)))
175+
val customExt = Seq(21.toByte -> ByteArrayConstant(valueBytes))
176+
test("executeFromVar", env, customExt,
177+
"{ executeFromVar[Int](21) == 5 }",
178+
null,
179+
true
180+
)
181+
}
182+
183+
property("executeFromVar - Coll[Byte]") {
184+
val bytes = Slice(ByteArrayConstant(Colls.fromArray(Array.fill(5)(1.toByte))), IntConstant(1), IntConstant(3))
185+
val valueBytes = ValueSerializer.serialize(bytes)
186+
val customExt = Seq(21.toByte -> ByteArrayConstant(valueBytes))
187+
test("executeFromVar", env, customExt,
188+
"{val ba = executeFromVar[Coll[Byte]](21); ba.size == 2 }",
189+
null,
190+
true
191+
)
192+
}
193+
194+
// test which is showing impossibility of nested Deserialize*
195+
property("executeFromVar - deserialize") {
196+
val script = DeserializeContext(21.toByte, SSigmaProp)
197+
val scriptBytes = ValueSerializer.serialize(script)
198+
val customExt = Seq(21.toByte -> ByteArrayConstant(scriptBytes))
199+
an [Exception] should be thrownBy test("executeFromVar", env, customExt,
200+
"executeFromVar[SigmaProp](21)",
201+
null,
202+
true
203+
)
204+
}
205+
160206
property("Relation operations") {
161207
test("R1", env, ext,
162208
"{ allOf(Coll(getVar[Boolean](trueVar).get, true, true)) }",

0 commit comments

Comments
 (0)