From fb3e52ea689c234377cffb55642afcb7f3669ee5 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 17 Jul 2024 21:05:56 +0300 Subject: [PATCH 1/9] String fix & test --- data/jvm/src/main/scala/sigma/Platform.scala | 5 ++++- .../src/test/scala/sigma/ast/SigmaBuilderTest.scala | 11 ++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index bd39d75ab9..4878b3fb1b 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -31,7 +31,10 @@ object Platform { case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt)) case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) - case v: String => Nullable(mkConstant[SString.type](v, SString)) + + // todo: check Header and UnsignedBigInt + + case v: String if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SString.type](v, SString)) // The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the // isCorrectType requirement would fail in ConstantNode constructor. diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index acf8e74bd2..a964c7f662 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -175,9 +175,14 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant String") { val v = "abc" val c = StringConstant(v) - test[SString.type](v, c) - testArray[SString.type](v, c) // TODO v6.0: String should be liftable at all (not supported in ErgoTree) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) - testColl[SString.type](v, c) + if (!VersionContext.current.isV6SoftForkActivated) { + // v6.0: String should be liftable at all (not supported in ErgoTree) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + test[SString.type](v, c) + testArray[SString.type](v, c) + testColl[SString.type](v, c) + } else { + testFailure(v) + } } property("liftToConstant BigInteger") { From ec215dfa78093036756dde37e2c022f70c956fe7 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 17 Jul 2024 21:25:19 +0300 Subject: [PATCH 2/9] Array fix & test --- data/jvm/src/main/scala/sigma/Platform.scala | 14 +++--- .../scala/sigma/ast/SigmaBuilderTest.scala | 43 ++++++++++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index 4878b3fb1b..27e99f2be2 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -16,13 +16,13 @@ object Platform { private[sigma] def liftToConstant(obj: Any, builder: SigmaBuilder): Nullable[Constant[SType]] = { import builder._ obj match { - case arr: Array[Boolean] => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean)) - case arr: Array[Byte] => Nullable(mkCollectionConstant[SByte.type](arr, SByte)) - case arr: Array[Short] => Nullable(mkCollectionConstant[SShort.type](arr, SShort)) - case arr: Array[Int] => Nullable(mkCollectionConstant[SInt.type](arr, SInt)) - case arr: Array[Long] => Nullable(mkCollectionConstant[SLong.type](arr, SLong)) - case arr: Array[BigInteger] => Nullable(mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt(_)), SBigInt)) - case arr: Array[String] => Nullable(mkCollectionConstant[SString.type](arr, SString)) + case arr: Array[Boolean] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean)) + case arr: Array[Byte] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SByte.type](arr, SByte)) + case arr: Array[Short] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SShort.type](arr, SShort)) + case arr: Array[Int] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SInt.type](arr, SInt)) + case arr: Array[Long] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SLong.type](arr, SLong)) + case arr: Array[BigInteger] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt(_)), SBigInt)) + case arr: Array[String] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SString.type](arr, SString)) case v: Byte => Nullable(mkConstant[SByte.type](v, SByte)) case v: Short => Nullable(mkConstant[SShort.type](v, SShort)) case v: Int => Nullable(mkConstant[SInt.type](v, SInt)) diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index a964c7f662..c8eb17e0ca 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -122,6 +122,13 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant(arr, c.tpe)) } + def testArrayFailure[T <: SType] + (v: T#WrappedType, c: Constant[T])(implicit t: RType[T#WrappedType]) = { + // for any Byte and Short value `v`, lifting of array should succeed + val arr = Array.fill[T#WrappedType](10)(v)(t.classTag) + testFailure(arr) + } + def testColl[T <: SType] (v: T#WrappedType, c: Constant[T])(implicit t: RType[T#WrappedType]) = { // for any Byte and Short value `v`, lifting of Coll should succeed @@ -134,7 +141,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val v = true val c = BooleanConstant(v) test[SBoolean.type](v, c) - testArray[SBoolean.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testArray[SBoolean.type](v, c) + } else { + testArrayFailure[SBoolean.type](v, c) + } testColl[SBoolean.type](v, c) } @@ -143,7 +154,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val c = ByteConstant(v) testNumeric[SByte.type](v, c) testLiftingOfCAnyValue[SByte.type](v, c) - testArray[SByte.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testArray[SByte.type](v, c) + } else { + testArrayFailure[SByte.type](v, c) + } testColl[SByte.type](v, c) } @@ -152,7 +167,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val c = ShortConstant(v) testNumeric[SShort.type](v, c) testLiftingOfCAnyValue[SShort.type](v, c) - testArray[SShort.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testArray[SShort.type](v, c) + } else { + testArrayFailure[SShort.type](v, c) + } testColl[SShort.type](v, c) } @@ -160,7 +179,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val v = 1 val c = IntConstant(v) test[SInt.type](v, c) - testArray[SInt.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testArray[SInt.type](v, c) + } else { + testArrayFailure[SInt.type](v, c) + } testColl[SInt.type](v, c) } @@ -168,7 +191,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val v = 1L val c = LongConstant(v) test[SLong.type](v, c) - testArray[SLong.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testArray[SLong.type](v, c) + } else { + testArrayFailure[SLong.type](v, c) + } testColl[SLong.type](v, c) } @@ -190,7 +217,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma val c = BigIntConstant(v) testSuccess(v, c) // TODO v6.0: both BigInteger and arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) val arr = Array.fill(10)(v) - testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt), c.tpe)) + if (!VersionContext.current.isV6SoftForkActivated) { + testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt), c.tpe)) + } else { + testFailure(arr) + } } property("liftToConstant BigInt") { From d257b5a0715cb9d37afbc11b3a5c6786df89772c Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 17 Jul 2024 23:58:09 +0300 Subject: [PATCH 3/9] BigInteger and ErgoBox fix and tests --- data/jvm/src/main/scala/sigma/Platform.scala | 4 ++-- .../src/test/scala/sigma/ast/SigmaBuilderTest.scala | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index 27e99f2be2..2b077a77f5 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -27,7 +27,7 @@ object Platform { case v: Short => Nullable(mkConstant[SShort.type](v, SShort)) case v: Int => Nullable(mkConstant[SInt.type](v, SInt)) case v: Long => Nullable(mkConstant[SLong.type](v, SLong)) - case v: BigInteger => Nullable(mkConstant[SBigInt.type](SigmaDsl.BigInt(v), SBigInt)) + case v: BigInteger if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBigInt.type](SigmaDsl.BigInt(v), SBigInt)) case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt)) case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) @@ -41,7 +41,7 @@ object Platform { // This method is used as part of consensus in SubstConstants operation, however // ErgoBox cannot be passed as argument as it is never valid value during evaluation. // Thus we can use activation-based versioning and fix this code when v5.0 is activated. - case b: ErgoBox => + case b: ErgoBox if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBox.type](SigmaDsl.Box(b), SBox)) // fixed in v5.0 // this case is added in v5.0 and it can be useful when the box value comes from a diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index c8eb17e0ca..9e02a6f8f4 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -215,7 +215,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant BigInteger") { val v = BigInteger.valueOf(1L) val c = BigIntConstant(v) - testSuccess(v, c) // TODO v6.0: both BigInteger and arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testSuccess(v, c) + } else { + testFailure(v) + } val arr = Array.fill(10)(v) if (!VersionContext.current.isV6SoftForkActivated) { testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt), c.tpe)) @@ -243,7 +247,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant ErgoBox") { val v = TestData.b2.asInstanceOf[CBox].wrappedValue val c = BoxConstant(TestData.b2) - testSuccess(v, c) // TODO v6.0: ErgoBox should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testSuccess(v, c) + } else { + testFailure(v) + } testFailure(Array.fill(10)(v)) } From 1644380074047da63e195c27ae047bac631e2688 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 18 Jul 2024 13:43:02 +0300 Subject: [PATCH 4/9] AvlTreeData fix & test --- data/jvm/src/main/scala/sigma/Platform.scala | 2 +- .../shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index 2b077a77f5..3d2d14274f 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -51,7 +51,7 @@ object Platform { Nullable(mkConstant[SBox.type](b, SBox)) else Nullable.None // return the same result as in v4.x when there was no this case - case avl: AvlTreeData => Nullable(mkConstant[SAvlTree.type](SigmaDsl.avlTree(avl), SAvlTree)) + case avl: AvlTreeData if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SAvlTree.type](SigmaDsl.avlTree(avl), SAvlTree)) case avl: AvlTree => Nullable(mkConstant[SAvlTree.type](avl, SAvlTree)) case sb: SigmaBoolean => Nullable(mkConstant[SSigmaProp.type](SigmaDsl.SigmaProp(sb), SSigmaProp)) case p: SigmaProp => Nullable(mkConstant[SSigmaProp.type](p, SSigmaProp)) diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index 9e02a6f8f4..b125893438 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -278,7 +278,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant AvlTreeData") { val v = TestData.t1.asInstanceOf[CAvlTree].wrappedValue val c = AvlTreeConstant(SigmaDsl.avlTree(v)) - testSuccess(v, c) // TODO v6.0: AvlTreeData should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) + if (!VersionContext.current.isV6SoftForkActivated) { + testSuccess(v, c) + } else { + testFailure(v) + } testFailure(Array.fill(10)(v)) } From 3901ba25b9052e4c7d68ad9b520dfdf011298ae1 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Mon, 30 Sep 2024 17:04:54 +0300 Subject: [PATCH 5/9] merging w. 6.0.0, Header support --- data/jvm/src/main/scala/sigma/Platform.scala | 3 ++- .../src/test/scala/sigma/ast/SigmaBuilderTest.scala | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index 3d2d14274f..072ed763ad 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -31,8 +31,9 @@ object Platform { case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt)) case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) + case h: Header => Nullable(mkConstant[SHeader.type](h, SHeader)) - // todo: check Header and UnsignedBigInt + // todo: check UnsignedBigInt case v: String if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SString.type](v, SString)) diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index b125893438..4946789411 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -244,6 +244,14 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma testColl[SGroupElement.type](v, c) } + property("liftToConstant Header") { + val h = TestData.h1 + val c = HeaderConstant(h) + test[SHeader.type](h, c) + testFailure(Array.fill(10)(h)) + testColl[SHeader.type](h, c) + } + property("liftToConstant ErgoBox") { val v = TestData.b2.asInstanceOf[CBox].wrappedValue val c = BoxConstant(TestData.b2) From 40fe947f569172da521ec8e1c8b317f882a00b12 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Wed, 2 Oct 2024 16:27:44 +0300 Subject: [PATCH 6/9] versioned header check --- data/jvm/src/main/scala/sigma/Platform.scala | 2 +- .../shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/data/jvm/src/main/scala/sigma/Platform.scala b/data/jvm/src/main/scala/sigma/Platform.scala index 072ed763ad..104ea44d3d 100644 --- a/data/jvm/src/main/scala/sigma/Platform.scala +++ b/data/jvm/src/main/scala/sigma/Platform.scala @@ -31,7 +31,7 @@ object Platform { case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt)) case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) - case h: Header => Nullable(mkConstant[SHeader.type](h, SHeader)) + case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader)) // todo: check UnsignedBigInt diff --git a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala index 4946789411..c1642627ee 100644 --- a/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala @@ -247,7 +247,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant Header") { val h = TestData.h1 val c = HeaderConstant(h) - test[SHeader.type](h, c) + if (VersionContext.current.isV6SoftForkActivated) { + testSuccess(h, c) + } else { + testFailure(h) + } testFailure(Array.fill(10)(h)) testColl[SHeader.type](h, c) } From 19c752da1ff6cb2054846641d097238ccfdd58ee Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 3 Oct 2024 11:44:28 +0300 Subject: [PATCH 7/9] fixing most of tests --- data/js/src/main/scala/sigma/Platform.scala | 1 + .../org/ergoplatform/ErgoScriptPredef.scala | 3 +- .../org/ergoplatform/ErgoTreePredefSpec.scala | 24 +++++------ .../TestingInterpreterSpecification.scala | 16 +++++--- .../utxo/AVLTreeScriptsSpecification.scala | 10 ++--- .../utxo/ContextEnrichingSpecification.scala | 14 +++---- .../ErgoLikeInterpreterSpecification.scala | 41 ++++++++++++------- .../AtomicSwapExampleSpecification.scala | 1 - ...alletAdvContractExampleSpecification.scala | 7 +--- ...ldWalletContractExampleSpecification.scala | 1 - .../DHTupleExampleSpecification.scala | 1 - .../DemurrageExampleSpecification.scala | 1 - .../sigmastate/utxo/examples/IcoExample.scala | 7 ++-- .../utxo/examples/LetsSpecification.scala | 4 +- .../examples/MixExampleSpecification.scala | 5 +-- .../RPSGameExampleSpecification.scala | 7 ++-- .../ReversibleTxExampleSpecification.scala | 11 +++-- .../TimedPaymentExampleSpecification.scala | 1 - .../XorGameExampleSpecification.scala | 7 ++-- 19 files changed, 82 insertions(+), 80 deletions(-) diff --git a/data/js/src/main/scala/sigma/Platform.scala b/data/js/src/main/scala/sigma/Platform.scala index 29c761c3f1..45d74ea2b2 100644 --- a/data/js/src/main/scala/sigma/Platform.scala +++ b/data/js/src/main/scala/sigma/Platform.scala @@ -31,6 +31,7 @@ object Platform { case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) case v: String => Nullable(mkConstant[SString.type](v, SString)) + case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader)) // The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the // isCorrectType requirement would fail in ConstantNode constructor. diff --git a/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala b/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala index 9eec42a4fb..7bcf10d593 100644 --- a/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala +++ b/sc/shared/src/main/scala/org/ergoplatform/ErgoScriptPredef.scala @@ -1,6 +1,7 @@ package org.ergoplatform import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix +import sigma.Colls import sigma.ast.SType import sigma.ast.syntax.SigmaPropValue import sigma.ast.Value @@ -32,7 +33,7 @@ object ErgoScriptPredef { networkPrefix: NetworkPrefix) (implicit IR: IRContext): SigmaPropValue = { val env = emptyEnv + - ("tokenId" -> tokenId, "thresholdAmount" -> thresholdAmount) + ("tokenId" -> Colls.fromArray(tokenId), "thresholdAmount" -> thresholdAmount) val res = compileWithCosting(env, """{ | val sumValues = { (xs: Coll[Long]) => xs.fold(0L, { (acc: Long, amt: Long) => acc + amt }) } diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala index eb086e88c8..40012c2806 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala @@ -58,8 +58,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBox, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "boxCreationHeight_prove"), propTree, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "boxCreationHeight_verify"), propTree, ctx, pr, fakeMessage).get._1 shouldBe true + val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).get + verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).get._1 shouldBe true } property("collect coins from the founders' box") { @@ -118,8 +118,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBoxes.head, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkSpending_prove"), prop, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "checkSpending_verify"), prop, ctx, pr, fakeMessage).get._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).get + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).get._1 shouldBe true } } @@ -148,13 +148,13 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio self = inputBoxes.head, activatedVersionInTests) // should not be able to collect before minerRewardDelay - val prove = prover.prove(emptyEnv + (ScriptNameProp -> "rewardOutputScript_prove"), prop, ctx, fakeMessage).get - verifier.verify(emptyEnv + (ScriptNameProp -> "rewardOutputScript_verify"), prop, prevBlockCtx, prove, fakeMessage) + val prove = prover.prove(emptyEnv, prop, ctx, fakeMessage).get + verifier.verify(emptyEnv, prop, prevBlockCtx, prove, fakeMessage) .getOrThrow should matchPattern { case (false,_) => } // should be able to collect after minerRewardDelay - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true } property("create transaction collecting the emission box") { @@ -232,8 +232,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio self = inputBoxes.head, activatedVersionInTests).withCostLimit(scriptCostLimitInTests * 10) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true } @@ -308,8 +308,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio boxesToSpend = inputBoxes, spendingTransaction, self = inputBoxes.head, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkRewardTx_prove"), prop, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "checkRewardTx_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true spendingTransaction } diff --git a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala index 4ba6b1a9f7..42d424994d 100644 --- a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala @@ -12,7 +12,7 @@ import scorex.util.encode.{Base16, Base58} import sigma.Colls import sigma.VersionContext.V6SoftForkVersion import sigma.VersionContext -import sigma.data.{CAND, CAvlTree, CHeader, ProveDlog, SigmaBoolean, TrivialProp} +import sigma.data.{CAND, CAvlTree, CBox, CHeader, ProveDlog, SigmaBoolean, TrivialProp} import sigma.interpreter.ContextExtension import sigma.util.Extensions.IntOps import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter} @@ -143,12 +143,18 @@ class TestingInterpreterSpecification extends CompilerTestingCommons val env = Map( "dk1" -> dk1, "dk2" -> dk2, - "bytes1" -> Array[Byte](1, 2, 3), - "bytes2" -> Array[Byte](4, 5, 6), - "box1" -> testBox(10, TrueTree, 0, Seq(), Map( + "bytes1" -> Colls.fromArray(Array[Byte](1, 2, 3)), + "bytes2" -> Colls.fromArray(Array[Byte](4, 5, 6)), + "box1" -> (if(VersionContext.current.isJitActivated) { + CBox(testBox(10, TrueTree, 0, Seq(), Map( + reg1 -> IntArrayConstant(Array[Int](1, 2, 3)), + reg2 -> BoolArrayConstant(Array[Boolean](true, false, true)) + )))} else { + testBox(10, TrueTree, 0, Seq(), Map( reg1 -> IntArrayConstant(Array[Int](1, 2, 3)), reg2 -> BoolArrayConstant(Array[Boolean](true, false, true)) - )) + )) + }) ) val prop = mkTestErgoTree(compile(env, code)(IR).asBoolValue.toSigmaProp) val challenge = Array.fill(32)(Random.nextInt(100).toByte) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala index 6b0c0080c9..ca7f9dd7c7 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala @@ -15,14 +15,13 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ -import sigma.Coll +import sigma.{AvlTree, Coll, Colls, Context} import sigma.ast.SAvlTree import sigma.ast.syntax.{GetVarByteArray, OptionValueOps} import sigma.compiler.ir.IRContext import sigma.data.{AvlTreeData, AvlTreeFlags, CSigmaProp, TrivialProp} import sigma.eval.SigmaDsl import sigma.interpreter.ProverResult -import sigma.{AvlTree, Context} import sigmastate.eval.Extensions.AvlTreeOps @@ -39,9 +38,6 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons def genKey(str: String): ADKey = ADKey @@@ Blake2b256("key: " + str) def genValue(str: String): ADValue = ADValue @@@ Blake2b256("val: " + str) - val inKey = genKey("init key") - val inValue = genValue("init value") - property("avl tree - removals") { case class AvlTreeContract[Spec <: ContractSpec] (ops: Coll[Coll[Byte]], proof: Coll[Byte], prover: Spec#ProvingParty) @@ -204,7 +200,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons val treeData = new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None) - val env = Map("key" -> key, "proof" -> proof) + val env = Map("key" -> Colls.fromArray(key), "proof" -> Colls.fromArray(proof)) val prop = compile(env, """SELF.R4[AvlTree].get.contains(key, proof)""").asBoolValue.toSigmaProp val propExp = IR.builder.mkMethodCall( @@ -374,7 +370,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons val treeData = SigmaDsl.avlTree(new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None)) val env = Map("proofId" -> proofId.toLong, - "keys" -> ConcreteCollection.fromItems(genKey("3"), genKey("4"), genKey("5"))) + "keys" -> Colls.fromItems(Colls.fromArray(genKey("3")), Colls.fromArray(genKey("4")), Colls.fromArray(genKey("5")))) val prop = compile(env, """{ | val tree = SELF.R4[AvlTree].get diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala index fe3dac68b3..3b2baa62fe 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala @@ -5,8 +5,8 @@ import scorex.crypto.hash.Blake2b256 import sigma.ast._ import sigma.ast.syntax._ import sigmastate._ -import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} -import sigma.Coll +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} +import sigma.{Coll, Colls} class ContextEnrichingSpecification extends CompilerTestingCommons @@ -19,7 +19,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] val pubkey = prover.dlogSecrets.head.publicImage - val env = Map("blake" -> Blake2b256(preimage.toArray), "pubkey" -> pubkey) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray)), "pubkey" -> pubkey) val prop = compile(env, """{ | pubkey && blake2b256(getVar[Coll[Byte]](1).get) == blake @@ -49,7 +49,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]] val pubkey = prover.dlogSecrets.head.publicImage - val env = Map("blake" -> Blake2b256(preimage1.append(preimage2).toArray), "pubkey" -> pubkey) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage1.append(preimage2).toArray)), "pubkey" -> pubkey) val prop = compile(env, """{ | pubkey && blake2b256(getVar[Coll[Byte]](1).get ++ getVar[Coll[Byte]](2).get) == blake @@ -89,7 +89,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons .withContextExtender(k1, ByteArrayConstant(v1)) .withContextExtender(k2, ByteArrayConstant(v2)) - val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> r) + val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> Colls.fromArray(r)) val prop = compile(env, "{ xor(getVar[Coll[Byte]](k1).get, getVar[Coll[Byte]](k2).get) == r }").asBoolValue.toSigmaProp val propTree = mkTestErgoTree(prop) @@ -119,7 +119,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val prover = new ContextEnrichingTestProvingInterpreter val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] - val env = Map("blake" -> Blake2b256(preimage.toArray)) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray))) val prop = compile(env, """{ | blake2b256(getVar[Coll[Byte]](1).get) == blake @@ -149,7 +149,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons val preimage1 = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]] val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]] - val env = Map("blake" -> Blake2b256(preimage2.append(preimage1).toArray)) + val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage2.append(preimage1).toArray))) val prop = compile(env, """{ | blake2b256(getVar[Coll[Byte]](2).get ++ getVar[Coll[Byte]](1).get) == blake diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala index 615a826649..f7adc194b5 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala @@ -5,11 +5,12 @@ import org.ergoplatform.ErgoBox.R4 import org.ergoplatform._ import org.scalatest.TryValues._ import scorex.crypto.hash.Blake2b256 +import sigma.{Colls, VersionContext} import sigma.ast.SCollection.SByteArray import sigma.ast._ import sigmastate._ import sigma.ast.syntax._ -import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog, TrivialProp} +import sigma.data.{AvlTreeData, CBox, ProveDHTuple, ProveDlog, TrivialProp} import sigma.util.Extensions.EcpOps import sigma.validation.ValidationException import sigmastate.eval._ @@ -51,8 +52,8 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons .withErgoTreeVersion(ergoTreeVersionInTests) val e = compile(Map( - "h1" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes, - "h2" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes), + "h1" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes), + "h2" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes)), "h1 == h1") val exp = TrueLeaf e shouldBe exp @@ -192,7 +193,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val spendingTransaction = createTransaction(newBoxes) def mixingRequestProp(sender: ProveDlog, timeout: Int): ErgoTree = { - val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> properHash) + val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> Colls.fromArray(properHash)) val compiledProp = compile(env, """{ | val notTimePassed = HEIGHT <= timeout @@ -459,9 +460,14 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val pubkey1 = prover.dlogSecrets.head.publicImage val pubkey2 = prover.dlogSecrets(1).publicImage + val tb = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0) + val brother = if(VersionContext.current.isJitActivated) { + CBox(tb) + } else { + tb + } - val brother = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0) - val brotherWithWrongId = testBox(value = 10, + val tbWithWrongId = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0, boxIndex = 120: Short) @@ -482,7 +488,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val propExpected = BinAnd( EQ(SizeOf(Inputs), IntConstant(2)), - EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(brother)))).toSigmaProp + EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(tb)))).toSigmaProp prop shouldBe propExpected // try a version of the script that matches the white paper @@ -496,18 +502,18 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons currentHeight = 50, lastBlockUtxoRoot = AvlTreeData.dummy, minerPubkey = ErgoLikeContextTesting.dummyPubkey, - boxesToSpend = IndexedSeq(brother, s), + boxesToSpend = IndexedSeq(tb, s), spendingTransaction, self = s, activatedVersionInTests) - val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop"), propTree, ctx, fakeMessage).getOrThrow - verifier.verify(emptyEnv + (ScriptNameProp -> "verify_prop"), propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true + val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).getOrThrow + verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true val wrongCtx = ErgoLikeContextTesting( currentHeight = 50, lastBlockUtxoRoot = AvlTreeData.dummy, minerPubkey = ErgoLikeContextTesting.dummyPubkey, - boxesToSpend = IndexedSeq(brotherWithWrongId, s), + boxesToSpend = IndexedSeq(tbWithWrongId, s), spendingTransaction, self = s, activatedVersionInTests) @@ -522,9 +528,9 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons }""".stripMargin).asBoolValue.toSigmaProp val prop2Tree = mkTestErgoTree(prop2) - prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop2"), prop2Tree, ctx, fakeMessage).isFailure shouldBe true + prover.prove(emptyEnv, prop2Tree, ctx, fakeMessage).isFailure shouldBe true verifier - .verify(emptyEnv + (ScriptNameProp -> "verify_prop2"), prop2Tree, ctx, pr, fakeMessage) + .verify(emptyEnv, prop2Tree, ctx, pr, fakeMessage) .getOrThrow._1 shouldBe false } @@ -547,7 +553,12 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val newBoxes = IndexedSeq(newBox) val spendingTransaction = createTransaction(newBoxes) - val env = Map("friend" -> friend) + val friendVar = if(VersionContext.current.isJitActivated){ + CBox(friend) + } else { + friend + } + val env = Map("friend" -> friendVar) val prop = compile(env, """{ | @@ -623,7 +634,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons val helloHash = Blake2b256.hash(preimageHello) - val env = Map("helloHash" -> helloHash) + val env = Map("helloHash" -> Colls.fromArray(helloHash)) val prop = compile(env, """{ | val cond = INPUTS(0).value > 10 diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala index 131aba22d0..7323dc6118 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/AtomicSwapExampleSpecification.scala @@ -39,7 +39,6 @@ class AtomicSwapExampleSpecification extends CompilerTestingCommons with Compile val deadlineB = 500 val env = Map( - ScriptNameProp -> "atomic", "height1" -> height1, "height2" -> height2, "deadlineBob" -> deadlineB, "deadlineAlice" -> deadlineA, "pubkeyA" -> pubkeyA, "pubkeyB" -> pubkeyB, "hx" -> hx) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala index 9bcfd81ecf..ef100a36a5 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletAdvContractExampleSpecification.scala @@ -9,6 +9,7 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ +import sigmastate.interpreter.Interpreter class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons @@ -35,7 +36,6 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons val minSpend = 100 val env = Map( - ScriptNameProp -> "env", "user1" -> alicePubKey, "user2" -> bobPubKey, "user3" -> carolPubKey, @@ -109,12 +109,9 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons ) ) - val dave = new ErgoLikeTestProvingInterpreter // paying to dave, some arbitrary user - val davePubKey = dave.dlogSecrets.head.publicImage - val firstWithdrawHeight = depositHeight + 1 // - val spendEnv = Map(ScriptNameProp -> "spendEnv") + val spendEnv = Interpreter.emptyEnv // One of Alice, Bob or Carol withdraws val firstWithdrawAmount1Key = depositAmount * percent1Key / 100 // less than or equal to percent diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala index 1948bc16d9..bfeb9732a8 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ColdWalletContractExampleSpecification.scala @@ -31,7 +31,6 @@ class ColdWalletContractExampleSpecification extends CompilerTestingCommons val minSpend = 100 val env = Map( - ScriptNameProp -> "env", "alice" -> alicePubKey, "bob" -> bobPubKey, "blocksIn24h" -> IntConstant(blocksIn24h), diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala index 9246cc1c8e..60569d061e 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala @@ -38,7 +38,6 @@ class DHTupleExampleSpecification extends CompilerTestingCommons val g_x = alicePubKey.value // g_x is Alice's public key (g_x = g^x) val env = Map( - ScriptNameProp -> "env", "g" -> g.toGroupElement, "g_x" -> g_x.toGroupElement ) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala index 4ec6922c38..6d4ff117d3 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DemurrageExampleSpecification.scala @@ -49,7 +49,6 @@ class DemurrageExampleSpecification extends CompilerTestingCommons val regScript = userProver.dlogSecrets.head.publicImage val env = Map( - ScriptNameProp -> "Demurrage", "demurragePeriod" -> demurragePeriod, "demurrageCoeff" -> demurrageCoeff, "regScript" -> regScript diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala index 556c56bc03..9c81e4539d 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala @@ -252,8 +252,7 @@ class IcoExample extends CompilerTestingCommons private val feeBytes = feeProp.bytes val env = Map( - ScriptNameProp -> "withdrawalScriptEnv", - "feeBytes" -> feeBytes, + "feeBytes" -> Colls.fromArray(feeBytes), "projectPubKey" -> project.secrets.head.publicImage ) lazy val withdrawalScript: SigmaPropValue = compile(env, @@ -313,7 +312,7 @@ class IcoExample extends CompilerTestingCommons Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(withdrawalTree)) } - def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", wsHash), + def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(wsHash)), """{ | val openTree = SELF.R5[AvlTree].get | @@ -349,7 +348,7 @@ class IcoExample extends CompilerTestingCommons Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(tree)) } - def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", issuanceHash), + def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(issuanceHash)), """{ | | val selfIndexIsZero = INPUTS(0).id == SELF.id diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala index 556fbf9c06..609a127bec 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala @@ -178,7 +178,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion val letsTokenId = Digest32Coll @@ Colls.fromArray(Array.fill(32)(Random.nextInt(100).toByte)) - val env = Map(ScriptNameProp -> "withdrawalScriptEnv", "letsToken" -> ByteArrayConstant(letsTokenId)) + val env = Map("letsToken" -> ByteArrayConstant(letsTokenId)) private val miningRewardsDelay = 720 private val feeProp = ErgoTreePredef.feeProposition(miningRewardsDelay) // create ErgoTree v0 @@ -235,7 +235,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion def userContractHash = Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(exchangeTree)) - def managementScript = compile(env.updated("userContractHash", userContractHash), + def managementScript = compile(env.updated("userContractHash", Colls.fromArray(userContractHash)), """{ | | val selfOut = OUTPUTS(0) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala index fc19a485ee..fdb241a908 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala @@ -3,6 +3,7 @@ package sigmastate.utxo.examples import java.math.BigInteger import org.ergoplatform.ErgoBox.{R4, R5} import scorex.crypto.hash.Blake2b256 +import sigma.Colls import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog} import sigma.util.Extensions.EcpOps import sigmastate.CompilerCrossVersionProps @@ -41,7 +42,6 @@ class MixExampleSpecification extends CompilerTestingCommons // val alicePubKey:ProveDlog = ProveDlog(g_x) val fullMixEnv = Map( - ScriptNameProp -> "fullMixEnv", "g" -> g.toGroupElement, "gX" -> gX.toGroupElement ) @@ -60,10 +60,9 @@ class MixExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfMixEnv = Map( - ScriptNameProp -> "halfMixEnv", "g" -> g.toGroupElement, "gX" -> gX.toGroupElement, - "fullMixScriptHash" -> Blake2b256(fullMixScript.bytes) + "fullMixScriptHash" -> Colls.fromArray(Blake2b256(fullMixScript.bytes)) ) // Note that below script allows Alice to spend the half-mix output anytime before Bob spends it. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala index c695b8e07d..3ca85e892b 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala @@ -4,6 +4,7 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5, R6, R7} import scorex.crypto.hash.Blake2b256 import scorex.utils.Random +import sigma.Colls import sigma.data.{AvlTreeData, ProveDlog} import sigma.ast.{ByteArrayConstant, ByteConstant, ErgoTree, IntConstant, SigmaPropConstant} import sigmastate._ @@ -51,9 +52,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons val h = Blake2b256(s :+ a) // Alice's commitment val fullGameEnv = Map( - ScriptNameProp -> "fullGameScriptEnv", "alice" -> alicePubKey, - "k" -> h + "k" -> Colls.fromArray(h) ) val fullGameScript = mkTestErgoTree(compile(fullGameEnv, @@ -78,9 +78,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfGameEnv = Map( - ScriptNameProp -> "halfGameScript", "alice" -> alicePubKey, - "fullGameScriptHash" -> Blake2b256(fullGameScript.bytes) + "fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes)) ) // Note that below script allows Alice to spend the half-game output anytime before Bob spends it. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala index 4294dc5b4b..fad547460f 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ReversibleTxExampleSpecification.scala @@ -3,13 +3,14 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5} import org.ergoplatform._ import scorex.crypto.hash.Blake2b256 +import sigma.Colls import sigma.data.AvlTreeData import sigma.ast.{ErgoTree, IntConstant, SigmaPropConstant} import sigmastate._ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ -import sigmastate.interpreter.Interpreter.ScriptNameProp import sigma.ast.syntax._ +import sigmastate.interpreter.Interpreter class ReversibleTxExampleSpecification extends CompilerTestingCommons @@ -79,7 +80,6 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons val carolPubKey = carol.dlogSecrets.head.publicImage val withdrawEnv = Map( - ScriptNameProp -> "withdrawEnv", "carol" -> carolPubKey // this pub key can reverse payments ) @@ -94,12 +94,11 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons val blocksIn24h = 500 val feeProposition = ErgoTreePredef.feeProposition() val depositEnv = Map( - ScriptNameProp -> "depositEnv", "alice" -> alicePubKey, "blocksIn24h" -> blocksIn24h, "maxFee" -> 10L, - "feePropositionBytes" -> feeProposition.bytes, - "withdrawScriptHash" -> Blake2b256(withdrawScript.bytes) + "feePropositionBytes" -> Colls.fromArray(feeProposition.bytes), + "withdrawScriptHash" -> Colls.fromArray(Blake2b256(withdrawScript.bytes)) ) val depositScript = mkTestErgoTree(compile(depositEnv, @@ -189,7 +188,7 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons self = reversibleWithdrawOutput, activatedVersionInTests ) - val spendEnv = Map(ScriptNameProp -> "spendEnv") + val spendEnv = Interpreter.emptyEnv val proofBobSpend = bob.prove(spendEnv, withdrawScript, bobSpendContext, fakeMessage).get.proof diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala index 2657a49eb0..fb1c275fb8 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/TimedPaymentExampleSpecification.scala @@ -27,7 +27,6 @@ class TimedPaymentExampleSpecification extends CompilerTestingCommons val bobPubKey = bob.dlogSecrets.head.publicImage val env = Map( - ScriptNameProp -> "env", "alice" -> alicePubKey ) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala index b3d6d4eff8..8821ccb72e 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala @@ -4,6 +4,7 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.{R4, R5, R6} import scorex.crypto.hash.Blake2b256 import scorex.utils.Random +import sigma.Colls import sigma.data.{AvlTreeData, ProveDlog} import sigma.ast.{ByteArrayConstant, ByteConstant, IntConstant, SigmaPropConstant} import sigmastate._ @@ -51,9 +52,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons val h = Blake2b256(s :+ a) // Alice's commitment val fullGameEnv = Map( - ScriptNameProp -> "fullGameScriptEnv", "alice" -> alicePubKey, - "h" -> h + "h" -> Colls.fromArray(h) ) val fullGameScript = mkTestErgoTree(compile(fullGameEnv, @@ -73,9 +73,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons ).asSigmaProp) val halfGameEnv = Map( - ScriptNameProp -> "halfGameScript", "alice" -> alicePubKey, - "fullGameScriptHash" -> Blake2b256(fullGameScript.bytes) + "fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes)) ) // Note that below script allows Alice to spend the half-game output anytime before Bob spends it. From f77be78b0cbf5726f5575611decb2bbcd10be07c Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 3 Oct 2024 12:05:57 +0300 Subject: [PATCH 8/9] fixing JS tests --- data/js/src/main/scala/sigma/Platform.scala | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/data/js/src/main/scala/sigma/Platform.scala b/data/js/src/main/scala/sigma/Platform.scala index 45d74ea2b2..2bc9995cd2 100644 --- a/data/js/src/main/scala/sigma/Platform.scala +++ b/data/js/src/main/scala/sigma/Platform.scala @@ -14,23 +14,23 @@ object Platform { private[sigma] def liftToConstant(obj: Any, builder: SigmaBuilder): Nullable[Constant[SType]] = { import builder._ obj match { - case arr: Array[Boolean] => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean)) - case arr: Array[Byte] => Nullable(mkCollectionConstant[SByte.type](arr, SByte)) - case arr: Array[Short] => Nullable(mkCollectionConstant[SShort.type](arr, SShort)) - case arr: Array[Int] => Nullable(mkCollectionConstant[SInt.type](arr, SInt)) - case arr: Array[Long] => Nullable(mkCollectionConstant[SLong.type](arr, SLong)) - case arr: Array[BigInteger] => Nullable(mkCollectionConstant[SBigInt.type](arr.map[BigInt](n => CBigInt(n)), SBigInt)) - case arr: Array[String] => Nullable(mkCollectionConstant[SString.type](arr, SString)) + case arr: Array[Boolean] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean)) + case arr: Array[Byte] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SByte.type](arr, SByte)) + case arr: Array[Short] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SShort.type](arr, SShort)) + case arr: Array[Int] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SInt.type](arr, SInt)) + case arr: Array[Long] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SLong.type](arr, SLong)) + case arr: Array[BigInteger] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBigInt.type](arr.map[BigInt](n => CBigInt(n)), SBigInt)) + case arr: Array[String] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SString.type](arr, SString)) case v: AnyValue => val tpe = Evaluation.rtypeToSType(v.tVal) Nullable(mkConstant[tpe.type](v.value.asInstanceOf[tpe.WrappedType], tpe)) case v: Int => Nullable(mkConstant[SInt.type](v, SInt)) case v: Long => Nullable(mkConstant[SLong.type](v, SLong)) - case v: BigInteger => Nullable(mkConstant[SBigInt.type](CBigInt(v), SBigInt)) + case v: BigInteger if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBigInt.type](CBigInt(v), SBigInt)) case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt)) case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement)) case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf) - case v: String => Nullable(mkConstant[SString.type](v, SString)) + case v: String if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SString.type](v, SString)) case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader)) // The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the @@ -38,7 +38,7 @@ object Platform { // This method is used as part of consensus in SubstConstants operation, however // ErgoBox cannot be passed as argument as it is never valid value during evaluation. // Thus we can use activation-based versioning and fix this code when v5.0 is activated. - case b: ErgoBox => + case b: ErgoBox if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBox.type](CBox(b), SBox)) // fixed in v5.0 // this case is added in v5.0 and it can be useful when the box value comes from a From 6c1ac1ebd439ea5185a0e124674dea9c7c9fac1b Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Thu, 3 Oct 2024 12:32:26 +0300 Subject: [PATCH 9/9] fix for AVLtreedata lift in JS --- data/js/src/main/scala/sigma/Platform.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/js/src/main/scala/sigma/Platform.scala b/data/js/src/main/scala/sigma/Platform.scala index 2bc9995cd2..64b17085ae 100644 --- a/data/js/src/main/scala/sigma/Platform.scala +++ b/data/js/src/main/scala/sigma/Platform.scala @@ -48,7 +48,7 @@ object Platform { Nullable(mkConstant[SBox.type](b, SBox)) else Nullable.None // return the same result as in v4.x when there was no this case - case avl: AvlTreeData => Nullable(mkConstant[SAvlTree.type](CAvlTree(avl), SAvlTree)) + case avl: AvlTreeData if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SAvlTree.type](CAvlTree(avl), SAvlTree)) case avl: AvlTree => Nullable(mkConstant[SAvlTree.type](avl, SAvlTree)) case sb: SigmaBoolean => Nullable(mkConstant[SSigmaProp.type](CSigmaProp(sb), SSigmaProp)) case p: SigmaProp => Nullable(mkConstant[SSigmaProp.type](p, SSigmaProp))