From be32e2752204dc4069703533a57ff9b2fea41da8 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Sat, 19 Aug 2023 18:46:23 +0200 Subject: [PATCH 1/8] todo-v5.x: removing Char, Float, Double type descriptors --- .../src/main/scala/scalan/TypeDesc.scala | 7 ------ .../src/test/scala/special/TypesTests.scala | 4 ++-- .../special/collections/CollsTests.scala | 24 +++---------------- .../shared/src/main/scala/scalan/Base.scala | 17 ++++++------- .../src/main/scala/scalan/TypeDescs.scala | 3 --- .../scala/sigmastate/eval/Evaluation.scala | 3 --- 6 files changed, 12 insertions(+), 46 deletions(-) diff --git a/common/shared/src/main/scala/scalan/TypeDesc.scala b/common/shared/src/main/scala/scalan/TypeDesc.scala index c7578a2ea8..98ecb1ec4c 100644 --- a/common/shared/src/main/scala/scalan/TypeDesc.scala +++ b/common/shared/src/main/scala/scalan/TypeDesc.scala @@ -35,9 +35,6 @@ object RType { case ClassTag.Short => ShortType case ClassTag.Int => IntType case ClassTag.Long => LongType - case ClassTag.Char => CharType - case ClassTag.Float => FloatType - case ClassTag.Double => DoubleType case ClassTag.Unit => UnitType case _ => GeneralType[A](ctA) }).asInstanceOf[RType[A]] @@ -72,10 +69,6 @@ object RType { implicit val ShortType : RType[Short] = PrimitiveType[Short] (ClassTag.Short, Array.emptyShortArray) implicit val IntType : RType[Int] = PrimitiveType[Int] (ClassTag.Int, Array.emptyIntArray) implicit val LongType : RType[Long] = PrimitiveType[Long] (ClassTag.Long, Array.emptyLongArray) - // TODO v5.x: optimize: remove Char, Float, Double types, they are not supported and will never be - implicit val CharType : RType[Char] = PrimitiveType[Char] (ClassTag.Char, Array.emptyCharArray) - implicit val FloatType : RType[Float] = PrimitiveType[Float] (ClassTag.Float, Array.emptyFloatArray) - implicit val DoubleType : RType[Double] = PrimitiveType[Double] (ClassTag.Double, Array.emptyDoubleArray) implicit val UnitType : RType[Unit] = PrimitiveType[Unit] (ClassTag.Unit, Array[Unit]()(ClassTag.Unit)) implicit case object StringType extends RType[String] { diff --git a/core-lib/shared/src/test/scala/special/TypesTests.scala b/core-lib/shared/src/test/scala/special/TypesTests.scala index 13b562d84c..b0c6ce5808 100644 --- a/core-lib/shared/src/test/scala/special/TypesTests.scala +++ b/core-lib/shared/src/test/scala/special/TypesTests.scala @@ -10,8 +10,8 @@ class TypesTests extends BaseTests { def test[A](t: RType[A], n: String) = { t.name shouldBe n } - test(tupleRType(Array(IntType, LongType, RType[(String, Double)], RType[Option[Boolean]])), - "(Int, Long, (String, Double), Option[Boolean])") + test(tupleRType(Array(IntType, LongType, RType[(Byte, special.sigma.BigInt)], RType[Option[Boolean]])), + "(Int, Long, (Byte, BigInt), Option[Boolean])") } test("RType implements equality") { diff --git a/core-lib/shared/src/test/scala/special/collections/CollsTests.scala b/core-lib/shared/src/test/scala/special/collections/CollsTests.scala index 6e2271fd9e..f1fe708a7f 100644 --- a/core-lib/shared/src/test/scala/special/collections/CollsTests.scala +++ b/core-lib/shared/src/test/scala/special/collections/CollsTests.scala @@ -433,24 +433,6 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers checkColls(repl, coll) } - forAll(charGen, indexGen, minSuccess) { (x, n) => - val repl = builder.replicate(n, x) - val coll = builder.fromArray(Array.fill(n)(x)) - - checkColls(repl, coll) - } - forAll(floatGen, indexGen, minSuccess) { (x, n) => - val repl = builder.replicate(n, x) - val coll = builder.fromArray(Array.fill(n)(x)) - - checkColls(repl, coll) - } - forAll (doubleGen, indexGen, minSuccess) { (x, n) => - val repl = builder.replicate(n, x) - val coll = builder.fromArray(Array.fill(n)(x)) - - checkColls(repl, coll) - } forAll (indexGen, minSuccess) { (n) => val replTrue = builder.replicate(n, true) val collTrue = builder.fromArray(Array.fill(n)(true)) @@ -479,13 +461,13 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers checkColls(repl, coll) } - forAll (byteGen, doubleGen, intGen, indexGen, minSuccess) { (b, d, i, n) => + forAll (byteGen, longGen, intGen, indexGen, minSuccess) { (b, d, i, n) => val repl = builder.replicate(n, (b, (i, (d, b)))) - val coll = builder.fromArray(Array.fill[(Byte, (Int, (Double, Byte)))](n)((b, (i, (d, b))))) + val coll = builder.fromArray(Array.fill[(Byte, (Int, (Long, Byte)))](n)((b, (i, (d, b))))) checkColls(repl, coll) } - forAll (byteGen, doubleGen, intGen, indexGen, indexGen, minSuccess) { (b, d, i, n, m) => + forAll (byteGen, longGen, intGen, indexGen, indexGen, minSuccess) { (b, d, i, n, m) => val repl = builder.replicate(n, (b, ((i, (("string", builder.replicate(m, n)), Array(1, 2, 3, 4))), (d, b)))) val coll = builder.fromArray(Array.fill(n)((b, ((i, (("string", builder.fromArray(Array.fill(m)(n))), Array(1, 2, 3, 4))), (d, b))))) diff --git a/graph-ir/shared/src/main/scala/scalan/Base.scala b/graph-ir/shared/src/main/scala/scalan/Base.scala index b105665f14..22e01da17f 100644 --- a/graph-ir/shared/src/main/scala/scalan/Base.scala +++ b/graph-ir/shared/src/main/scala/scalan/Base.scala @@ -301,16 +301,13 @@ abstract class Base { scalan: Scalan => def lift(srcF: SA => SB): Ref[A => B] = FuncConst[SA,SB,A,B](srcF) } - implicit lazy val BooleanIsLiftable = asLiftable[Boolean,Boolean](BooleanElement.liftable) - implicit lazy val ByteIsLiftable = asLiftable[Byte,Byte](ByteElement.liftable) - implicit lazy val ShortIsLiftable = asLiftable[Short,Short](ShortElement.liftable) - implicit lazy val IntIsLiftable = asLiftable[Int,Int](IntElement.liftable) - implicit lazy val LongIsLiftable = asLiftable[Long,Long](LongElement.liftable) - implicit lazy val StringIsLiftable = asLiftable[String,String](StringElement.liftable) - implicit lazy val FloatIsLiftable = asLiftable[Float,Float](FloatElement.liftable) - implicit lazy val DoubleIsLiftable = asLiftable[Double,Double](DoubleElement.liftable) - implicit lazy val UnitIsLiftable = asLiftable[Unit,Unit](UnitElement.liftable) - implicit lazy val CharIsLiftable = asLiftable[Char,Char](CharElement.liftable) + implicit lazy val BooleanIsLiftable: Liftable[Boolean, Boolean] = asLiftable[Boolean,Boolean](BooleanElement.liftable) + implicit lazy val ByteIsLiftable: Liftable[Byte, Byte] = asLiftable[Byte,Byte](ByteElement.liftable) + implicit lazy val ShortIsLiftable: Liftable[Short, Short] = asLiftable[Short,Short](ShortElement.liftable) + implicit lazy val IntIsLiftable: Liftable[Int, Int] = asLiftable[Int,Int](IntElement.liftable) + implicit lazy val LongIsLiftable: Liftable[Long, Long] = asLiftable[Long,Long](LongElement.liftable) + implicit lazy val StringIsLiftable: Liftable[String, String] = asLiftable[String,String](StringElement.liftable) + implicit lazy val UnitIsLiftable: Liftable[Unit, Unit] = asLiftable[Unit,Unit](UnitElement.liftable) implicit def PairIsLiftable[SA,SB,A,B] (implicit lA: Liftable[SA, A], lB: Liftable[SB, B]): Liftable[(SA, SB), (A, B)] = diff --git a/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala b/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala index 48cb0a0dc9..57fc2a1a52 100644 --- a/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala +++ b/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala @@ -367,11 +367,8 @@ abstract class TypeDescs extends Base { self: Scalan => implicit val ShortElement: Elem[Short] = new BaseElemLiftable(0.toShort, ShortType) implicit val IntElement: Elem[Int] = new BaseElemLiftable(0, IntType) implicit val LongElement: Elem[Long] = new BaseElemLiftable(0L, LongType) - implicit val FloatElement: Elem[Float] = new BaseElemLiftable(0.0F, FloatType) - implicit val DoubleElement: Elem[Double] = new BaseElemLiftable(0.0, DoubleType) implicit val UnitElement: Elem[Unit] = new BaseElemLiftable((), UnitType) implicit val StringElement: Elem[String] = new BaseElemLiftable("", StringType) - implicit val CharElement: Elem[Char] = new BaseElemLiftable('\u0000', CharType) /** Implicitly defines element type for pairs. */ implicit final def pairElement[A, B](implicit ea: Elem[A], eb: Elem[B]): Elem[(A, B)] = diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala index 818e604dd2..fa8b50a6c9 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala @@ -141,9 +141,6 @@ object Evaluation { case _: Short => ShortType case _: Int => IntType case _: Long => LongType - case _: Char => CharType - case _: Float => FloatType - case _: Double => DoubleType case _: String => StringType case _: Unit => UnitType From 18c4d1aa055059f58d1819c30512287989895335 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Sat, 19 Aug 2023 18:55:17 +0200 Subject: [PATCH 2/8] todo-v5.x: renamed CosterException --- .../scala/sigmastate/exceptions/CompilerExceptions.scala | 3 +-- .../src/main/scala/sigmastate/eval/GraphBuilding.scala | 7 +++---- .../test/scala/sigmastate/lang/SigmaCompilerTest.scala | 8 ++++---- .../scala/sigmastate/utxo/ThresholdSpecification.scala | 6 +++--- .../test/scala/special/sigma/SigmaDslSpecification.scala | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/interpreter/shared/src/main/scala/sigmastate/exceptions/CompilerExceptions.scala b/interpreter/shared/src/main/scala/sigmastate/exceptions/CompilerExceptions.scala index b652a4091d..8c331766af 100644 --- a/interpreter/shared/src/main/scala/sigmastate/exceptions/CompilerExceptions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/exceptions/CompilerExceptions.scala @@ -42,8 +42,7 @@ class TyperException(message: String, source: Option[SourceContext] = None) class BuilderException(message: String, source: Option[SourceContext] = None) extends CompilerException(message, source) -// TODO v5.x: remove this exception -class CosterException(message: String, source: Option[SourceContext], cause: Option[Throwable] = None) +class GraphBuildingException(message: String, source: Option[SourceContext], cause: Option[Throwable] = None) extends CompilerException(message, source, cause) diff --git a/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala b/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala index 085ad468f9..a992dbf0d7 100644 --- a/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala +++ b/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala @@ -1,7 +1,6 @@ package sigmastate.eval import org.ergoplatform._ -import org.ergoplatform.validation.ValidationRules.CheckTupleType import scalan.ExactIntegral.{ByteIsExactIntegral, IntIsExactIntegral, LongIsExactIntegral, ShortIsExactIntegral} import scalan.ExactOrdering.{ByteIsExactOrdering, IntIsExactOrdering, LongIsExactOrdering, ShortIsExactOrdering} import scalan.util.Extensions.ByteOps @@ -15,7 +14,7 @@ import sigmastate.serialization.OpCodes import sigmastate.utxo._ import sigmastate._ import sigmastate.basics.CryptoConstants.EcPointType -import sigmastate.exceptions.{SigmaException, CosterException} +import sigmastate.exceptions.{SigmaException, GraphBuildingException} import scala.collection.mutable.ArrayBuffer /** Perform translation of typed expression given by [[Value]] to a graph in IRContext. @@ -396,8 +395,8 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext => protected implicit def groupElementToECPoint(g: special.sigma.GroupElement): EcPointType = CostingSigmaDslBuilder.toECPoint(g).asInstanceOf[EcPointType] - def error(msg: String) = throw new CosterException(msg, None) - def error(msg: String, srcCtx: Option[SourceContext]) = throw new CosterException(msg, srcCtx) + def error(msg: String) = throw new GraphBuildingException(msg, None) + def error(msg: String, srcCtx: Option[SourceContext]) = throw new GraphBuildingException(msg, srcCtx) /** Translates the given typed expression to IR graph representing a function from * Context to some type T. diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala index 96a430a51d..73a424c456 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala @@ -8,7 +8,7 @@ import sigmastate._ import sigmastate.helpers.CompilerTestingCommons import sigmastate.interpreter.Interpreter.ScriptEnv import sigmastate.lang.Terms.{Apply, Ident, Lambda, MethodCall, ZKProofBlock} -import sigmastate.exceptions.{CosterException, InvalidArguments, TyperException} +import sigmastate.exceptions.{GraphBuildingException, InvalidArguments, TyperException} import sigmastate.serialization.ValueSerializer import sigmastate.serialization.generators.ObjectGenerators import sigmastate.utxo.{ByIndex, ExtractAmount, GetVar, SelectField} @@ -23,15 +23,15 @@ class SigmaCompilerTest extends CompilerTestingCommons with LangTests with Objec private def comp(x: String): Value[SType] = compile(env, x) private def testMissingCosting(script: String, expected: SValue): Unit = { - an [CosterException] should be thrownBy comp(env, script) + an [GraphBuildingException] should be thrownBy comp(env, script) } private def testMissingCostingWOSerialization(script: String, expected: SValue): Unit = { - an [CosterException] should be thrownBy comp(env, script) + an [GraphBuildingException] should be thrownBy comp(env, script) } private def costerFail(env: ScriptEnv, x: String, expectedLine: Int, expectedCol: Int): Unit = { - val exception = the[CosterException] thrownBy comp(env, x) + val exception = the[GraphBuildingException] thrownBy comp(env, x) withClue(s"Exception: $exception, is missing source context:") { exception.source shouldBe defined } val sourceContext = exception.source.get sourceContext.line shouldBe expectedLine diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala index f2f797a832..ce442ecb50 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala @@ -4,7 +4,7 @@ import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} import sigmastate.Values.{ConcreteCollection, FalseLeaf, IntConstant, SigmaPropConstant, SigmaPropValue, TrueLeaf} import sigmastate._ import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTransactionTesting, CompilerTestingCommons} -import sigmastate.exceptions.CosterException +import sigmastate.exceptions.GraphBuildingException class ThresholdSpecification extends CompilerTestingCommons with CompilerCrossVersionProps { @@ -407,8 +407,8 @@ class ThresholdSpecification extends CompilerTestingCommons val keyName = "pubkeyA" val env = Map(keyName -> pubkeyA) val pubKeysStrExceeding = Array.fill[String](AtLeast.MaxChildrenCount + 1)(keyName).mkString(",") - an[CosterException] should be thrownBy compile(env, s"""atLeast(2, Coll($pubKeysStrExceeding))""") - an[CosterException] should be thrownBy + an[GraphBuildingException] should be thrownBy compile(env, s"""atLeast(2, Coll($pubKeysStrExceeding))""") + an[GraphBuildingException] should be thrownBy compile(env, s"""{ val arr = Coll($pubKeysStrExceeding); atLeast(2, arr) }""") // max children should work fine diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala b/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala index 07984e81f4..977578b43e 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala +++ b/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala @@ -39,7 +39,7 @@ import sigmastate.basics.ProveDHTuple import sigmastate.interpreter._ import org.scalactic.source.Position import sigmastate.helpers.SigmaPPrint -import sigmastate.exceptions.CosterException +import sigmastate.exceptions.GraphBuildingException import scala.collection.compat.immutable.ArraySeq /** This suite tests every method of every SigmaDsl type to be equivalent to From 586104a230ff959b4b7082b9df4b0730ac4644f1 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Sat, 19 Aug 2023 22:29:39 +0200 Subject: [PATCH 3/8] todo-v5.x: assign an issue for each TODO v6.0 --- .../scala/sigmastate/crypto/Platform.scala | 2 +- .../src/main/scala/sigmastate/Values.scala | 2 +- .../sigmastate/eval/CostingDataContext.scala | 2 +- .../sigmastate/interpreter/Interpreter.scala | 2 +- .../serialization/ModQArithOpSerializer.scala | 2 +- .../serialization/ModQSerializer.scala | 2 +- .../serialization/ValueSerializer.scala | 2 +- .../src/main/scala/sigmastate/trees.scala | 6 ++-- .../src/main/scala/sigmastate/types.scala | 6 ++-- .../scala/sigmastate/utxo/transformers.scala | 3 +- .../sigmastate/lang/SigmaBuilderTest.scala | 18 +++++----- .../special/sigma/SigmaTestingData.scala | 2 +- .../ErgoLikeTransactionSpec.scala | 1 + .../sigmastate/lang/SigmaBinderTest.scala | 2 +- .../special/sigma/SigmaDslSpecification.scala | 34 ++++++++----------- .../scala/special/sigma/SigmaDslTesting.scala | 2 +- 16 files changed, 40 insertions(+), 48 deletions(-) diff --git a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala index dcd5deabde..3b74ba4714 100644 --- a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala +++ b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala @@ -187,7 +187,7 @@ object Platform { case _: Int => tpe == SInt case _: Long => tpe == SLong case _: BigInt => tpe == SBigInt - case _: String => tpe == SString // TODO v6.0: remove this case + case _: String => tpe == SString // TODO v6.0: remove this case (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) case _: GroupElement => tpe.isGroupElement case _: SigmaProp => tpe.isSigmaProp case _: AvlTree => tpe.isAvlTree diff --git a/interpreter/shared/src/main/scala/sigmastate/Values.scala b/interpreter/shared/src/main/scala/sigmastate/Values.scala index 1e9114a782..016177f760 100644 --- a/interpreter/shared/src/main/scala/sigmastate/Values.scala +++ b/interpreter/shared/src/main/scala/sigmastate/Values.scala @@ -881,7 +881,7 @@ object Values { trait OptionValue[T <: SType] extends Value[SOption[T]] { } - // TODO v6.0 (4h): SomeValue and NoneValue are not used in ErgoTree and can be + // TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be // either removed or implemented in v6.0 case class SomeValue[T <: SType](x: Value[T]) extends OptionValue[T] { override def companion = SomeValue diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala b/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala index f7679573d6..72cd34b725 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala @@ -129,7 +129,7 @@ case class CSigmaProp(sigmaTree: SigmaBoolean) extends SigmaProp with WrapperOf[ override def propBytes: Coll[Byte] = { // in order to have comparisons like `box.propositionBytes == pk.propBytes` we need to make sure // the same serialization method is used in both cases - // TODO v6.0: add `pk.propBytes(version)` + // TODO v6.0: add `pk.propBytes(version)` (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/903) val root = sigmaTree.toSigmaProp val ergoTree = new ErgoTree(ErgoTree.DefaultHeader, EmptyConstants, Right(root), 0, null, None) val bytes = DefaultSerializer.serializeErgoTree(ergoTree) diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala index d30a862f98..e606e72525 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala @@ -282,7 +282,7 @@ trait Interpreter { * @throws InterpreterException when cannot proceed and no activation yet. */ protected def checkSoftForkCondition(ergoTree: ErgoTree, context: CTX): Option[VerificationResult] = { - // TODO v6.0: the condition below should be revised if necessary + // TODO v6.0: the condition below should be revised if necessary (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/904) // The following conditions define behavior which depend on the version of ergoTree // This works in addition to more fine-grained soft-forkability mechanism implemented // using ValidationRules (see trySoftForkable method call here and in reduceToCrypto). diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ModQArithOpSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ModQArithOpSerializer.scala index b8d8d07093..765aaeb7b4 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ModQArithOpSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ModQArithOpSerializer.scala @@ -6,7 +6,7 @@ import sigmastate.utils.SigmaByteWriter.DataInfo import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.{ModQArithOpCompanion, SType, ModQArithOp} -// TODO v6.0 (2h): make sure it is covered with tests +// TODO v6.0: make sure it is covered with tests (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/327) case class ModQArithOpSerializer(override val opDesc: ModQArithOpCompanion, cons: (BigIntValue, BigIntValue) => BigIntValue) extends ValueSerializer[ModQArithOp] { val leftInfo: DataInfo[SValue] = opDesc.argInfos(0) diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ModQSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ModQSerializer.scala index f48a6e6388..335c12c1af 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ModQSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ModQSerializer.scala @@ -5,7 +5,7 @@ import sigmastate.lang.Terms._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.{ModQ, SType} -// TODO v6.0 (2h): make sure it is covered with tests +// TODO v6.0: make sure it is covered with tests (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/327) object ModQSerializer extends ValueSerializer[ModQ] { override def opDesc = ModQ diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala index abb0cbe964..2ef308f928 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala @@ -144,7 +144,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { SigmaTransformerSerializer(SigmaOr, mkSigmaOr), BoolToSigmaPropSerializer(mkBoolToSigmaProp), - // TODO hard-fork: this ModQ serializers should be removed only as part of hard-fork + // NOTE: these ModQ serializers can be removed only as part of hard-fork // because their removal may break deserialization of transaction, when for example // ModQ operation happen to be in one of the outputs (i.e. script is not executed // during validation, however deserializer is still used) diff --git a/interpreter/shared/src/main/scala/sigmastate/trees.scala b/interpreter/shared/src/main/scala/sigmastate/trees.scala index adc53ce754..254aa7c317 100644 --- a/interpreter/shared/src/main/scala/sigmastate/trees.scala +++ b/interpreter/shared/src/main/scala/sigmastate/trees.scala @@ -204,7 +204,7 @@ object CreateProveDlog extends FixedCostValueCompanion { val OpType = SFunc(SGroupElement, SSigmaProp) } -// TODO v6.0: implement `eval` method and add support in GraphBuilding +// TODO v6.0: implement `eval` method and add support in GraphBuilding (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/907) /** Construct a new authenticated dictionary with given parameters and tree root digest.*/ case class CreateAvlTree(operationFlags: ByteValue, digest: Value[SByteArray], @@ -1092,7 +1092,7 @@ object BitOp { } } -// TODO v6.0 (24h): implement modular operations +// TODO v6.0: implement modular operations (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/327) case class ModQ(input: Value[SBigInt.type]) extends NotReadyValue[SBigInt.type] { override def companion = ModQ @@ -1122,12 +1122,10 @@ trait OpGroup[C <: ValueCompanion] { object ModQArithOp extends OpGroup[ModQArithOpCompanion] { import OpCodes._ object PlusModQ extends ModQArithOpCompanion(PlusModQCode, "PlusModQ") { - // TODO soft-fork: // override def argInfos: Seq[ArgInfo] = PlusModQInfo.argInfos override def argInfos: Seq[ArgInfo] = Seq(ArgInfo("this", ""), ArgInfo("other", "")) } object MinusModQ extends ModQArithOpCompanion(MinusModQCode, "MinusModQ") { - // TODO soft-fork: // override def argInfos: Seq[ArgInfo] = MinusModQInfo.argInfos override def argInfos: Seq[ArgInfo] = Seq(ArgInfo("this", ""), ArgInfo("other", "")) } diff --git a/interpreter/shared/src/main/scala/sigmastate/types.scala b/interpreter/shared/src/main/scala/sigmastate/types.scala index fe7630eb3e..e4fd826304 100644 --- a/interpreter/shared/src/main/scala/sigmastate/types.scala +++ b/interpreter/shared/src/main/scala/sigmastate/types.scala @@ -188,7 +188,7 @@ object SType { * should be changed and SGlobal.typeId should be preserved. The regression tests in * `property("MethodCall Codes")` should pass. */ - // TODO v6.0 (h4): should contain all numeric types (including also SNumericType) + // TODO v6.0: should contain all numeric types (including also SNumericType) // to support method calls like 10.toByte which encoded as MethodCall with typeId = 4, methodId = 1 // see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/667 lazy val types: Map[Byte, STypeCompanion] = Seq( @@ -793,7 +793,7 @@ object SNumericType extends STypeCompanion { /** Array of all numeric types ordered by number of bytes in the representation. */ final val allNumericTypes = Array(SByte, SShort, SInt, SLong, SBigInt) - // TODO v6.0 (4h): this typeId is now shadowed by SGlobal.typeId + // TODO v6.0: this typeId is now shadowed by SGlobal.typeId // see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/667 override def typeId: TypeCode = 106: Byte @@ -2326,7 +2326,7 @@ case object SAvlTree extends SProduct with SPredefType with SMonoType { val insert = Insert(ADKey @@ key.toArray, ADValue @@ value.toArray) val insertRes = bv.performOneOperation(insert) // TODO v6.0: throwing exception is not consistent with update semantics - // however it preserves v4.0 semantics + // however it preserves v4.0 semantics (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908) if (insertRes.isFailure) { Interpreter.error(s"Incorrect insert for $tree (key: $key, value: $value, digest: ${tree.digest}): ${insertRes.failed.get}}") } diff --git a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala index f78552197e..2fc36c753c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala @@ -412,7 +412,6 @@ object ExtractScriptBytes extends SimpleTransformerCompanion with FixedCostValue val OpType = SFunc(SBox, SByteArray) override def opCode: OpCode = OpCodes.ExtractScriptBytesCode - // TODO v5.x: ensure the following is true /** The cost is fixed and doesn't include serialization of ErgoTree because * the ErgoTree is expected to be constructed with non-null propositionBytes. * This is (and must be) guaranteed by ErgoTree deserializer. @@ -618,7 +617,7 @@ case class OptionGetOrElse[V <: SType](input: Value[SOption[V]], default: Value[ override def tpe: V = input.tpe.elemType protected final override def eval(env: DataEnv)(implicit E: ErgoTreeEvaluator): Any = { val inputV = input.evalTo[Option[V#WrappedType]](env) - val dV = default.evalTo[V#WrappedType](env) // TODO v6.0: execute lazily + val dV = default.evalTo[V#WrappedType](env) // TODO v6.0: execute lazily (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/906) Value.checkType(default, dV) // necessary because cast to V#WrappedType is erased addCost(OptionGetOrElse.costKind) inputV.getOrElse(dV) diff --git a/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala index 7015587e34..8fa3ad0304 100644 --- a/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala @@ -135,7 +135,7 @@ 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 + testArray[SBoolean.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testColl[SBoolean.type](v, c) } @@ -144,7 +144,7 @@ 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 + testArray[SByte.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testColl[SByte.type](v, c) } @@ -153,7 +153,7 @@ 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 + testArray[SShort.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testColl[SShort.type](v, c) } @@ -161,7 +161,7 @@ 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 + testArray[SInt.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testColl[SInt.type](v, c) } @@ -169,7 +169,7 @@ 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 + testArray[SLong.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testColl[SLong.type](v, c) } @@ -177,14 +177,14 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma 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) + 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) } 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 + 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)) } @@ -208,7 +208,7 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma property("liftToConstant ErgoBox") { val v = TestData.b2.asInstanceOf[CostingBox].wrappedValue val c = BoxConstant(TestData.b2) - testSuccess(v, c) // TODO v6.0: ErgoBox should not be liftable directly + testSuccess(v, c) // TODO v6.0: ErgoBox should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testFailure(Array.fill(10)(v)) } @@ -235,7 +235,7 @@ 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 + testSuccess(v, c) // TODO v6.0: AvlTreeData should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905) testFailure(Array.fill(10)(v)) } diff --git a/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala b/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala index db2f8501c5..d2b2fa819e 100644 --- a/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala +++ b/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala @@ -132,7 +132,7 @@ trait SigmaTestingData extends TestingCommons with ObjectGenerators { def createBigIntMaxValue(): BigInt = BigIntMaxValue_instances.getNext - // TODO v6.0: this values have bitCount == 255 (see to256BitValueExact) + // TODO v6.0: this values have bitCount == 255 (see to256BitValueExact) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554) val BigIntMinValue = CBigInt(new BigInteger("-7F" + "ff" * 31, 16)) val BigIntMaxValue = createBigIntMaxValue() diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala index c0c926c9a2..25c01af43d 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala @@ -100,6 +100,7 @@ class ErgoLikeTransactionSpec extends SigmaDslTesting { ).map(identity).toConstant // TODO v6.0 (16h): fix collections equality and remove map(identity) // (PairOfColl should be equal CollOverArray but now it is not) + // see (https://github.com/ScorexFoundation/sigmastate-interpreter/issues/909) res shouldBe exp } diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala index b8aefc1041..a14aaf1c17 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala @@ -143,7 +143,7 @@ class SigmaBinderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Mat If(EQ(IntConstant(10), IntConstant(11)), IntConstant(2), IntConstant(3))) } - // TODO v6.0 (4h): SomeValue and NoneValue are not used in ErgoTree and can be + // TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be // either removed or implemented in v4.x property("Option constructors") { bind(env, "None") shouldBe NoneValue(NoType) diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala b/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala index 977578b43e..ead1af1873 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala +++ b/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala @@ -2202,7 +2202,7 @@ class SigmaDslSpecification extends SigmaDslTesting (BigIntMaxValue, BigIntMinValue) -> expect(false), (BigIntMaxValue, -47.toBigInt) -> expect(false), (BigIntMaxValue, BigIntMaxValue) -> expect(false), - (BigIntMaxValue, BigIntOverlimit) -> expect(true), // TODO v6.0: reject this overlimit cases + (BigIntMaxValue, BigIntOverlimit) -> expect(true), // TODO v6.0: reject this overlimit cases (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554) (BigIntOverlimit, BigIntOverlimit) -> expect(false) ) @@ -2219,7 +2219,7 @@ class SigmaDslSpecification extends SigmaDslTesting property("BigInt LE, GE") { val o = NumericOps.BigIntIsExactOrdering - // TODO v6.0: this values have bitCount == 255 (see to256BitValueExact) + // TODO v6.0: this values have bitCount == 255 (see to256BitValueExact) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554) val BigIntMinValue = CBigInt(new BigInteger("-7F" + "ff" * 31, 16)) val BigIntMaxValue = CBigInt(new BigInteger("7F" + "ff" * 31, 16)) val BigIntOverlimit = CBigInt(new BigInteger("7F" + "ff" * 33, 16)) @@ -2262,7 +2262,7 @@ class SigmaDslSpecification extends SigmaDslTesting (BigIntMaxValue, BigIntMinValue) -> expect(false), (BigIntMaxValue, -47.toBigInt) -> expect(false), (BigIntMaxValue, BigIntMaxValue) -> expect(true), - (BigIntMaxValue, BigIntOverlimit) -> expect(true), // TODO v6.0: reject this overlimit cases + (BigIntMaxValue, BigIntOverlimit) -> expect(true), // TODO v6.0: reject this overlimit cases (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/554) (BigIntOverlimit, BigIntOverlimit) -> expect(true) ) @@ -2274,7 +2274,7 @@ class SigmaDslSpecification extends SigmaDslTesting } property("BigInt methods equivalence (new features)") { - // TODO v6.0 (2h): the behavior of `upcast` for BigInt is different from all other Numeric types + // TODO v6.0: the behavior of `upcast` for BigInt is different from all other Numeric types (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877) // The `Upcast(bigInt, SBigInt)` node is never produced by ErgoScript compiler, but is still valid ErgoTree. // It makes sense to fix this inconsistency as part of upcoming forks assertExceptionThrown( @@ -2282,7 +2282,7 @@ class SigmaDslSpecification extends SigmaDslTesting _.getMessage.contains("Cannot upcast value") ) - // TODO v6.0 (2h): the behavior of `downcast` for BigInt is different from all other Numeric types + // TODO v6.0: the behavior of `downcast` for BigInt is different from all other Numeric types (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/877) // The `Downcast(bigInt, SBigInt)` node is never produced by ErgoScript compiler, but is still valid ErgoTree. // It makes sense to fix this inconsistency as part of HF assertExceptionThrown( @@ -2919,12 +2919,6 @@ class SigmaDslSpecification extends SigmaDslTesting )) } - // TODO v6.0 (3h): related to https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479 - // property("GroupElement.isIdentity equivalence") { - // // val isIdentity = existingFeature({ (x: GroupElement) => x.isIdentity }, - // // "{ (x: GroupElement) => x.isIdentity }") - // } - property("AvlTree properties equivalence") { def expectedExprFor(propName: String) = { FuncValue( @@ -3555,7 +3549,7 @@ class SigmaDslSpecification extends SigmaDslTesting val invalidKvs = Colls.fromItems((invalidKey -> value)) // NOTE, insertProof is based on `key` val input = (tree, (invalidKvs, insertProof)) val (res, _) = insert.checkEquality(input).getOrThrow - res.isDefined shouldBe true // TODO v6.0: should it really be true? (looks like a bug) + res.isDefined shouldBe true // TODO v6.0: should it really be true? (looks like a bug) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908) insert.checkExpected(input, Expected(Success(res), 1796, costDetails2, 1796)) } @@ -3717,7 +3711,7 @@ class SigmaDslSpecification extends SigmaDslTesting val invalidKvs = Colls.fromItems((key -> invalidValue)) val input = (tree, (invalidKvs, updateProof)) val (res, _) = update.checkEquality(input).getOrThrow - res.isDefined shouldBe true // TODO v6.0: should it really be true? (looks like a bug) + res.isDefined shouldBe true // TODO v6.0: should it really be true? (looks like a bug) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908) update.checkExpected(input, Expected(Success(res), 1805, costDetails2, 1805)) } @@ -4044,7 +4038,7 @@ class SigmaDslSpecification extends SigmaDslTesting "{ (x: Box) => x.creationInfo }", FuncValue(Vector((1, SBox)), ExtractCreationInfo(ValUse(1, SBox))))) - // TODO v6.0 (2h): fix collections equality and remove map(identity) + // TODO v6.0: fix collections equality and remove map(identity)(see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/909) // (PairOfColl should be equal CollOverArray) verifyCases( Seq( @@ -4068,7 +4062,7 @@ class SigmaDslSpecification extends SigmaDslTesting } property("Box properties equivalence (new features)") { - // TODO v6.0 (4h): related to https://github.com/ScorexFoundation/sigmastate-interpreter/issues/416 + // TODO v6.0: related to https://github.com/ScorexFoundation/sigmastate-interpreter/issues/416 val getReg = newFeature((x: Box) => x.getReg[Int](1).get, "{ (x: Box) => x.getReg[Int](1).get }") @@ -4344,7 +4338,7 @@ class SigmaDslSpecification extends SigmaDslTesting val box3 = SigmaDsl.Box(testBox(20, TrueTree, 0, Seq(), Map( ErgoBox.R4 -> Constant((10, 20L).asInstanceOf[SType#WrappedType], STuple(SInt, SLong)) - // TODO v6.0 (1h): uncomment after DataSerializer support of Option type + // TODO v6.0: uncomment after DataSerializer support of Option type (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659) // ErgoBox.R5 -> Constant((10, Some(20L)).asInstanceOf[SType#WrappedType], STuple(SInt, SOption(SLong))) // ErgoBox.R6 -> Constant[SOption[SInt.type]](Option(10), SOption(SInt)), ))) @@ -4448,7 +4442,7 @@ class SigmaDslSpecification extends SigmaDslTesting ))) - // TODO v6.0 (1h): uncomment after DataSerializer support of Option type + // TODO v6.0: uncomment after DataSerializer support of Option type (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659) // verifyCases( // Seq( // (box3, Expected(Success(10), cost = 36468))//, expCostDetails, 1790)) @@ -5164,7 +5158,7 @@ class SigmaDslSpecification extends SigmaDslTesting existingPropTest("minerPubKey", { (x: Context) => x.minerPubKey }), preGeneratedSamples = Some(samples)) -// TODO v6.0 (2h): implement support of Option[T] in DataSerializer +// TODO v6.0: implement support of Option[T] in DataSerializer (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/659) // this will allow passing optional values in registers and also in constants // testCases2( // Seq( @@ -9095,7 +9089,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) )) } - // TODO v6.0 (3h): implement Option.fold + // TODO v6.0: implement Option.fold (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/479) property("Option new methods") { val n = ExactNumeric.LongIsExactNumeric val fold = newFeature({ (x: Option[Long]) => x.fold(5.toLong)( (v: Long) => n.plus(v, 1) ) }, @@ -10032,7 +10026,7 @@ class SigmaDslSpecification extends SigmaDslTesting |""".stripMargin ) - // TODO v6.0: Add support of SFunc in TypeSerializer + // TODO v6.0: Add support of SFunc in TypeSerializer (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/847) assertExceptionThrown( f.verifyCase(Coll[Int](), Expected(Success(Coll[Int]()), 0)), exceptionLike[MatchError]("(SInt$) => SInt$ (of class sigmastate.SFunc)") diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala index 884e257ab4..371036fa0d 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala +++ b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala @@ -844,7 +844,7 @@ class SigmaDslTesting extends AnyPropSpec /** in v5.x the old and the new interpreters are the same */ val oldImpl = () => funcJit[A, B](script) - val newImpl = oldImpl // funcJit[A, B](script) // TODO v6.0 (16h): use actual new implementation here + val newImpl = oldImpl // funcJit[A, B](script) // TODO v6.0: use actual new implementation here (https://github.com/ScorexFoundation/sigmastate-interpreter/issues/910) /** In v5.x this method just checks the old implementations fails on the new feature. */ override def checkEquality(input: A, logInputOutput: Boolean = false): Try[(B, CostDetails)] = { From 99a40814eeed93fac09aa027c18a958587b92edf Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Sun, 20 Aug 2023 01:06:26 +0200 Subject: [PATCH 4/8] todo-v5.x: removed SomeValue, NoneValue --- .../src/main/scala/sigmastate/Values.scala | 25 ------------------- .../scala/sigmastate/lang/SigmaBuilder.scala | 8 ------ .../scala/sigmastate/lang/SigmaBinder.scala | 7 ------ .../scala/sigmastate/lang/SigmaTyper.scala | 3 --- .../sigmastate/lang/SigmaBinderTest.scala | 17 ------------- .../sigmastate/lang/SigmaCompilerTest.scala | 5 ---- .../sigmastate/lang/SigmaTyperTest.scala | 7 ------ 7 files changed, 72 deletions(-) diff --git a/interpreter/shared/src/main/scala/sigmastate/Values.scala b/interpreter/shared/src/main/scala/sigmastate/Values.scala index 016177f760..d5326db2b1 100644 --- a/interpreter/shared/src/main/scala/sigmastate/Values.scala +++ b/interpreter/shared/src/main/scala/sigmastate/Values.scala @@ -878,31 +878,6 @@ object Values { def apply(items: Value[SType]*): Tuple = Tuple(items.toIndexedSeq) } - trait OptionValue[T <: SType] extends Value[SOption[T]] { - } - - // TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be - // either removed or implemented in v6.0 - case class SomeValue[T <: SType](x: Value[T]) extends OptionValue[T] { - override def companion = SomeValue - val tpe = SOption(x.tpe) - def opType = SFunc(x.tpe, tpe) - } - object SomeValue extends ValueCompanion { - override val opCode = SomeValueCode - override def costKind: CostKind = Constant.costKind - } - - case class NoneValue[T <: SType](elemType: T) extends OptionValue[T] { - override def companion = NoneValue - val tpe = SOption(elemType) - def opType = SFunc(elemType, tpe) - } - object NoneValue extends ValueCompanion { - override val opCode = NoneValueCode - override def costKind: CostKind = Constant.costKind - } - /** ErgoTree node which converts a collection of expressions into a collection of data * values. Each data value of the resulting collection is obtained by evaluating the * corresponding expression in `items`. All items must have the same type. diff --git a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala index 813664931d..55d1575ff9 100644 --- a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala +++ b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala @@ -158,9 +158,6 @@ abstract class SigmaBuilder { def mkTaggedVariable[T <: SType](varId: Byte, tpe: T): TaggedVariable[T] - def mkSomeValue[T <: SType](x: Value[T]): Value[SOption[T]] - def mkNoneValue[T <: SType](elemType: T): Value[SOption[T]] - def mkBlock(bindings: Seq[Val], result: Value[SType]): Value[SType] def mkBlockValue(items: IndexedSeq[BlockItem], result: Value[SType]): Value[SType] def mkValUse(valId: Int, tpe: SType): Value[SType] @@ -527,11 +524,6 @@ class StdSigmaBuilder extends SigmaBuilder { override def mkTaggedVariable[T <: SType](varId: Byte, tpe: T): TaggedVariable[T] = TaggedVariableNode(varId, tpe).withSrcCtx(currentSrcCtx.value).asInstanceOf[TaggedVariable[T]] - override def mkSomeValue[T <: SType](x: Value[T]): Value[SOption[T]] = - SomeValue(x).withSrcCtx(currentSrcCtx.value) - override def mkNoneValue[T <: SType](elemType: T): Value[SOption[T]] = - NoneValue(elemType).withSrcCtx(currentSrcCtx.value) - override def mkBlock(bindings: Seq[Val], result: Value[SType]): Value[SType] = Block(bindings, result).withSrcCtx(currentSrcCtx.value) diff --git a/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala b/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala index 07616af0c4..f30b25b44c 100644 --- a/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala +++ b/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala @@ -48,7 +48,6 @@ class SigmaBinder(env: ScriptEnv, builder: SigmaBuilder, case "SELF" => Some(Self) case "CONTEXT" => Some(Context) case "Global" => Some(Global) - case "None" => Some(mkNoneValue(NoType)) case _ => None } } @@ -62,12 +61,6 @@ class SigmaBinder(env: ScriptEnv, builder: SigmaBuilder, val tpe = if (args.isEmpty) NoType else args(0).tpe Some(mkConcreteCollection(args, tpe)) - // Rule: Some(x) --> - case Apply(i @ Ident("Some", _), args) => args match { - case Seq(arg) => Some(mkSomeValue(arg)) - case _ => error(s"Invalid arguments of Some: expected one argument but found $args", i.sourceContext) - } - // Rule: min(x, y) --> case Apply(i @ Ident("min", _), args) => args match { case Seq(l: SValue, r: SValue) => diff --git a/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala b/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala index ad4dddcf51..ccc0784abe 100644 --- a/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala +++ b/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala @@ -497,9 +497,6 @@ class SigmaTyper(val builder: SigmaBuilder, case Negation(i) => unmap[SNumericType](env, "-", i.asNumValue)(mkNegation)(tT) case BitInversion(i) => unmap[SNumericType](env, "~", i.asNumValue)(mkBitInversion)(tT) - case SomeValue(x) => SomeValue(assignType(env, x)) - case v: NoneValue[_] => v - case Global => Global case Context => Context case Height => Height diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala index a14aaf1c17..397c5c5e5d 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaBinderTest.scala @@ -143,19 +143,6 @@ class SigmaBinderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Mat If(EQ(IntConstant(10), IntConstant(11)), IntConstant(2), IntConstant(3))) } - // TODO v5.x (4h): SomeValue and NoneValue are not used in ErgoTree and can be - // either removed or implemented in v4.x - property("Option constructors") { - bind(env, "None") shouldBe NoneValue(NoType) - bind(env, "Some(None)") shouldBe SomeValue(NoneValue(NoType)) - bind(env, "Some(10)") shouldBe SomeValue(IntConstant(10)) - bind(env, "Some(X)") shouldBe SomeValue(Ident("X")) - bind(env, "Some(Some(X - 1))") shouldBe - SomeValue(SomeValue(mkMinus(Ident("X").asValue[SInt.type], IntConstant(1)))) - bind(env, "Some(Some(X + 1))") shouldBe - SomeValue(SomeValue(plus(Ident("X").asValue[SInt.type], IntConstant(1)))) - } - property("lambdas") { bind(env, "{ (a: Int) => a - 1 }") shouldBe Lambda(IndexedSeq("a" -> SInt), NoType, mkMinus(IntIdent("a"), 1)) @@ -214,8 +201,4 @@ class SigmaBinderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Mat e.source shouldBe Some(SourceContext(2, 5, "val x = 10")) } - property("fail Some (invalid arguments)") { - fail(env, "Some(1, 2)", 1, 1) - fail(env, "Some()", 1, 1) - } } diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala index 73a424c456..f6266cf285 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala @@ -320,11 +320,6 @@ class SigmaCompilerTest extends CompilerTestingCommons with LangTests with Objec ) } - property("failed option constructors (not supported)") { - costerFail("None", 1, 1) - costerFail("Some(10)", 1, 1) - } - property("byteArrayToLong") { comp("byteArrayToLong(longToByteArray(1L))") shouldBe ByteArrayToLong(LongToByteArray(LongConstant(1))) } diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala index 22c2a1fd7a..85476c3c6d 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala @@ -214,13 +214,6 @@ class SigmaTyperTest extends AnyPropSpec typefail(env, "Coll(1, false)", 1, 1) } - property("Option constructors") { - typecheck(env, "Some(10)") shouldBe SOption(SInt) - typecheck(env, "Some(x)") shouldBe SOption(SInt) - typecheck(env, "Some(x + 1)") shouldBe SOption(SInt) - typecheck(env, "Some(Some(10))") shouldBe SOption(SOption(SInt)) - } - property("methods returning Option") { typecheck(env, "getVar[Int](10)") shouldBe SOption(SInt) typecheck(env, "{ val v = getVar[Int](1); v.get }") shouldBe SInt From 511957eb43a89872c3765f11fcc6a8e9c1dbfb7c Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 28 Aug 2023 12:26:43 +0200 Subject: [PATCH 5/8] todo-v5.x: removed maxTreeDepth todos --- .../validation/SigmaValidationSettingsSerializer.scala | 1 - interpreter/shared/src/main/scala/sigmastate/Values.scala | 1 - .../src/main/scala/sigmastate/serialization/DataSerializer.scala | 1 - .../main/scala/sigmastate/serialization/ValueSerializer.scala | 1 - 4 files changed, 4 deletions(-) diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala b/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala index 1b53b7dbf1..667d8f4989 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala @@ -5,7 +5,6 @@ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import scalan.util.Extensions.{IntOps, LongOps} import sigmastate.exceptions.SerializerException -// TODO v5.x: remove unused class and related json encoders /** The rules are serialized ordered by ruleId. * This serializer preserves roundtrip identity `deserialize(serialize(_)) = identity` * however it may not preserve `serialize(deserialize(_)) = identity` */ diff --git a/interpreter/shared/src/main/scala/sigmastate/Values.scala b/interpreter/shared/src/main/scala/sigmastate/Values.scala index d5326db2b1..840df3ab56 100644 --- a/interpreter/shared/src/main/scala/sigmastate/Values.scala +++ b/interpreter/shared/src/main/scala/sigmastate/Values.scala @@ -755,7 +755,6 @@ object Values { val dhtSerializer = ProveDHTupleSerializer(ProveDHTuple.apply) val dlogSerializer = ProveDlogSerializer(ProveDlog.apply) - // TODO v5.x: control maxTreeDepth same as in deserialize override def serialize(data: SigmaBoolean, w: SigmaByteWriter): Unit = { w.put(data.opCode) data match { diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala index d659dbf81b..f38fd97309 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala @@ -19,7 +19,6 @@ import scala.collection.mutable /** This works in tandem with ConstantSerializer, if you change one make sure to check the other.*/ object DataSerializer { - // TODO v5.x: control maxTreeDepth same as in deserialize /** Use type descriptor `tpe` to deconstruct type structure and recursively serialize subcomponents. * Primitive types are leaves of the type tree, and they are served as basis of recursion. * The data value `v` is expected to conform to the type described by `tpe`. diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala index 2ef308f928..411d8d660e 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala @@ -357,7 +357,6 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { } } - // TODO v5.x: control maxTreeDepth same as in deserialize (see Reader.level property and SigmaSerializer.MaxTreeDepth) override def serialize(v: Value[SType], w: SigmaByteWriter): Unit = serializable(v) match { case c: Constant[SType] => w.constantExtractionStore match { From 80b7f7372799fb139b6534a50de0165d664cfd9b Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 28 Aug 2023 13:44:41 +0200 Subject: [PATCH 6/8] todo-v5.x: ensure each remaining TODO v5.x has an issue url --- sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala index 20aabb1b00..7bffa895f8 100644 --- a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala @@ -256,7 +256,7 @@ class ErgoTreeSpecification extends SigmaDslTesting with ContractsTestkit { { import SSigmaProp._ (SSigmaProp.typeId, Seq( MInfo(1, PropBytesMethod), - MInfo(2, IsProvenMethod) // TODO v5.x (3h): this method must be removed + MInfo(2, IsProvenMethod) // TODO v5.x (3h): this method must be removed (see https://github.com/ScorexFoundation/sigmastate-interpreter/pull/800) ), true) }, { import SBox._ From 3ec06e66218ca26ce1146b3c785ebe78f27e6b29 Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 28 Aug 2023 13:55:13 +0200 Subject: [PATCH 7/8] todo-v5.x: implemented #911: supply ErgoBox.bytes in deserializer --- .../main/scala/org/ergoplatform/ErgoBox.scala | 39 +++++++++++++++---- .../scala/sigmastate/utxo/transformers.scala | 2 +- .../validation/RuleStatusSerializerSpec.scala | 2 +- ...igmaValidationSettingsSerializerSpec.scala | 2 +- .../helpers/CompilerTestingCommons.scala | 12 ++++-- .../utxo/SerializationRoundTripSpec.scala | 10 ++++- .../scala/special/sigma/SigmaDslTesting.scala | 5 ++- 7 files changed, 54 insertions(+), 18 deletions(-) diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala index 9d373fb36a..dadd0d5c7a 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala @@ -35,6 +35,8 @@ import special.collection._ * A transaction is unsealing a box. As a box can not be open twice, any further valid transaction can not be linked * to the same box. * + * Note, private constructor can only be used from within the ErgoBox companion object, e.g. by deserializer. + * * @param value - amount of money associated with the box * @param ergoTree - guarding script, which should be evaluated to true in order to open this box * @param additionalTokens - secondary tokens the box contains @@ -44,17 +46,28 @@ import special.collection._ * @param creationHeight - height when a transaction containing the box was created. * This height is declared by user and should not exceed height of the block, * containing the transaction with this box. + * @param _bytes - serialized bytes of the box when not `null` * HOTSPOT: don't beautify the code of this class */ -class ErgoBox( +class ErgoBox private ( override val value: Long, override val ergoTree: ErgoTree, - override val additionalTokens: Coll[Token] = Colls.emptyColl[Token], - override val additionalRegisters: AdditionalRegisters = Map.empty, + override val additionalTokens: Coll[Token], + override val additionalRegisters: AdditionalRegisters, val transactionId: ModifierId, val index: Short, - override val creationHeight: Int + override val creationHeight: Int, + _bytes: Array[Byte] ) extends ErgoBoxCandidate(value, ergoTree, creationHeight, additionalTokens, additionalRegisters) { + /** This is public constructor has the same parameters as the private primary constructor, except bytes. */ + def this(value: Long, + ergoTree: ErgoTree, + additionalTokens: Coll[Token] = Colls.emptyColl[Token], + additionalRegisters: AdditionalRegisters = Map.empty, + transactionId: ModifierId, + index: Short, + creationHeight: Int) = + this(value, ergoTree, additionalTokens, additionalRegisters, transactionId, index, creationHeight, null) import ErgoBox._ @@ -70,11 +83,15 @@ class ErgoBox( } } - // TODO optimize: avoid serialization by implementing lazy box deserialization /** Serialized content of this box. * @see [[ErgoBox.sigmaSerializer]] */ - lazy val bytes: Array[Byte] = ErgoBox.sigmaSerializer.toBytes(this) + lazy val bytes: Array[Byte] = { + if (_bytes != null) + _bytes // bytes provided by deserializer + else + ErgoBox.sigmaSerializer.toBytes(this) + } override def equals(arg: Any): Boolean = arg match { case x: ErgoBox => java.util.Arrays.equals(id, x.id) @@ -197,10 +214,16 @@ object ErgoBox { } override def parse(r: SigmaByteReader): ErgoBox = { - val ergoBoxCandidate = ErgoBoxCandidate.serializer.parse(r) + val start = r.position + val c = ErgoBoxCandidate.serializer.parse(r) val transactionId = r.getBytes(ErgoLikeTransaction.TransactionIdBytesSize).toModifierId val index = r.getUShort() - ergoBoxCandidate.toBox(transactionId, index.toShort) + val end = r.position + val len = end - start + r.position = start + val boxBytes = r.getBytes(len) // also moves position back to end + new ErgoBox(c.value, c.ergoTree, c.additionalTokens, c.additionalRegisters, + transactionId, index.toShort, c.creationHeight, boxBytes) } } } diff --git a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala index 2fc36c753c..8a434afc2b 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala @@ -436,7 +436,7 @@ object ExtractBytes extends SimpleTransformerCompanion { override def opCode: OpCode = OpCodes.ExtractBytesCode /** The cost is fixed and doesn't include serialization of ErgoBox because * the ErgoBox is expected to be constructed with non-null `bytes`. - * TODO v5.x: This is not currently, but must be guaranteed by lazy ErgoBox deserializer. */ + */ override val costKind = FixedCost(JitCost(12)) override def argInfos: Seq[ArgInfo] = ExtractBytesInfo.argInfos } diff --git a/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala index 711827fe1e..b26a0e4f4c 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala @@ -6,7 +6,7 @@ import sigmastate.serialization.{SigmaSerializer, SerializationSpecification} class RuleStatusSerializerSpec extends SerializationSpecification with CompilerTestingCommons { - private def roundtrip(status: RuleStatus): Assertion = { + private def roundtrip(status: RuleStatus) = { implicit val ser = RuleStatusSerializer roundTripTest(status) roundTripTestWithPos(status) diff --git a/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala index ee4ec75c3c..16fdd8ffee 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala @@ -7,7 +7,7 @@ import sigmastate.serialization.SerializationSpecification class SigmaValidationSettingsSerializerSpec extends SerializationSpecification with CompilerTestingCommons { - private def roundtrip(settings: SigmaValidationSettings): Assertion = { + private def roundtrip(settings: SigmaValidationSettings) = { implicit val set = SigmaValidationSettingsSerializer roundTripTest(settings) roundTripTestWithPos(settings) diff --git a/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala b/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala index b2b497e423..588dfe4f96 100644 --- a/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala +++ b/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala @@ -174,22 +174,26 @@ trait CompilerTestingCommons extends TestingCommons funcJitFromExpr(funcScript, compiledTree, bindings:_*) } - protected def roundTripTest[T](v: T)(implicit serializer: SigmaSerializer[T, T]): Assertion = { + protected def roundTripTest[T](v: T)(implicit serializer: SigmaSerializer[T, T]): T = { // using default sigma reader/writer val bytes = serializer.toBytes(v) bytes.nonEmpty shouldBe true val r = SigmaSerializer.startReader(bytes) val positionLimitBefore = r.positionLimit - serializer.parse(r) shouldBe v + val parsed = serializer.parse(r) + parsed shouldBe v r.positionLimit shouldBe positionLimitBefore + parsed } - protected def roundTripTestWithPos[T](v: T)(implicit serializer: SigmaSerializer[T, T]): Assertion = { + protected def roundTripTestWithPos[T](v: T)(implicit serializer: SigmaSerializer[T, T]): T = { val randomBytesCount = Gen.chooseNum(1, 20).sample.get val randomBytes = Gen.listOfN(randomBytesCount, arbByte.arbitrary).sample.get.toArray val bytes = serializer.toBytes(v) - serializer.parse(SigmaSerializer.startReader(bytes)) shouldBe v + val parsed = serializer.parse(SigmaSerializer.startReader(bytes)) + parsed shouldBe v serializer.parse(SigmaSerializer.startReader(randomBytes ++ bytes, randomBytesCount)) shouldBe v + parsed } def testReduce(I: Interpreter)(ctx: I.CTX, prop: SigmaPropValue): SigmaBoolean = { diff --git a/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala b/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala index 54ee4f4857..bfba524baf 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala @@ -55,8 +55,14 @@ class SerializationRoundTripSpec extends AnyPropSpec } property("ErgoBox: Serializer round trip") { - forAll { t: ErgoBox => roundTripTest(t)(ErgoBox.sigmaSerializer) } - forAll { t: ErgoBox => roundTripTestWithPos(t)(ErgoBox.sigmaSerializer) } + forAll { t: ErgoBox => + val parsed = roundTripTest(t)(ErgoBox.sigmaSerializer) + parsed.bytes shouldBe t.bytes + } + forAll { t: ErgoBox => + val parsed = roundTripTestWithPos(t)(ErgoBox.sigmaSerializer) + parsed.bytes shouldBe t.bytes + } } property("ContextExtension: Serializer round trip") { diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala index 371036fa0d..1630e7f8a9 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala +++ b/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala @@ -373,7 +373,10 @@ class SigmaDslTesting extends AnyPropSpec val box = createBox(0, compiledTree, additionalRegisters = newRegisters) // make sure we are doing tests with the box with is actually serializable - try roundTripTest(box)(ErgoBox.sigmaSerializer) + try { + val parsed = roundTripTest(box)(ErgoBox.sigmaSerializer) + parsed.bytes shouldBe box.bytes + } catch { case ValidationException(_, r: CheckSerializableTypeCode.type, Seq(SOption.OptionTypeCode), _) => // ignore the problem with Option serialization, but test all the other cases From 49104aab627d0025331e031bcc01f29c5a61174e Mon Sep 17 00:00:00 2001 From: Alexander Slesarenko Date: Mon, 28 Aug 2023 14:11:22 +0200 Subject: [PATCH 8/8] todo-v5.x: cleanups --- .../serialization/ValueSerializer.scala | 25 ++++++++++--------- .../validation/RuleStatusSerializerSpec.scala | 3 +-- ...igmaValidationSettingsSerializerSpec.scala | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala index 411d8d660e..ca5a60926c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala @@ -21,7 +21,7 @@ import scala.collection.mutable.{HashMap, Map} abstract class ValueSerializer[V <: Value[SType]] extends SigmaSerializer[Value[SType], V] { import scala.language.implicitConversions - val companion = ValueSerializer + private val companion = ValueSerializer def getComplexity: Int = OpCodeComplexity.getOrElse(opCode, MinimalComplexity) lazy val complexity: Int = getComplexity @@ -49,7 +49,8 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { private val constantSerializer = ConstantSerializer(builder) private val constantPlaceholderSerializer = ConstantPlaceholderSerializer(mkConstantPlaceholder) - val serializers = SparseArrayContainer.buildForSerializers(Seq[ValueSerializer[_ <: Value[SType]]]( + val serializers: SparseArrayContainer[ValueSerializer[_ <: Value[SType]]] = + SparseArrayContainer.buildForSerializers(Seq[ValueSerializer[_ <: Value[SType]]]( constantSerializer, constantPlaceholderSerializer, TupleSerializer(mkTuple), @@ -161,7 +162,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { )) private def serializable(v: Value[SType]): Value[SType] = v match { - case upcast: Upcast[SType, _]@unchecked => + case upcast: Upcast[SNumericType, _]@unchecked => upcast.input case _ => v } @@ -171,10 +172,10 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { CheckValidOpCode(serializer, opCode) serializer } - def addSerializer(opCode: OpCode, ser: ValueSerializer[_ <: Value[SType]]) = { + def addSerializer(opCode: OpCode, ser: ValueSerializer[_ <: Value[SType]]): Unit = { serializers.add(opCode, ser) } - def removeSerializer(opCode: OpCode) = { + def removeSerializer(opCode: OpCode): Unit = { serializers.remove(opCode) } @@ -184,13 +185,13 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { def parent: Scope def children: ChildrenMap def get(name: String): Option[Scope] = children.find(_._1 == name).map(_._2) - def add(name: String, s: Scope) = { + def add(name: String, s: Scope): ChildrenMap = { assert(get(name).isEmpty, s"Error while adding scope $s: name $name already exists in $this") children += (name -> s) } def showInScope(v: String): String - def provideScope(n: String, createNewScope: => Scope) = { + def provideScope(n: String, createNewScope: => Scope): Scope = { val scope = get(n) match { case Some(saved) => saved case None => @@ -203,7 +204,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { } case class SerScope(opCode: OpCode, children: ChildrenMap) extends Scope { - def serializer = getSerializer(opCode) + private def serializer = getSerializer(opCode) def name = s"Serializer of ${serializer.opDesc}" override def parent: Scope = null override def showInScope(v: String): String = name + "/" + v @@ -211,8 +212,8 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { } case class DataScope(parent: Scope, data: DataInfo[_]) extends Scope { - def name = data.info.name - override def children = mutable.ArrayBuffer.empty + override def name: String = data.info.name + override def children: ChildrenMap = mutable.ArrayBuffer.empty override def showInScope(v: String): String = parent.showInScope(s"DataInfo($data)") override def toString = s"DataScope($data)" } @@ -250,7 +251,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { } val collectSerInfo: Boolean = false - val serializerInfo: Map[OpCode, SerScope] = HashMap.empty + val serializerInfo: mutable.Map[OpCode, SerScope] = mutable.HashMap.empty private var scopeStack: List[Scope] = Nil def printSerInfo(): String = { @@ -347,7 +348,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] { scope.get(prop.info.name) match { case None => scope.add(prop.info.name, DataScope(scope, prop)) - println(s"Added $prop to ${scope}") + println(s"Added $prop to $scope") case Some(saved) => saved match { case DataScope(_, data) => assert(data == prop, s"Saved property $data is different from being added $prop: scope $scope") diff --git a/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala index b26a0e4f4c..9909f485b5 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/validation/RuleStatusSerializerSpec.scala @@ -1,13 +1,12 @@ package org.ergoplatform.validation -import org.scalatest.Assertion import sigmastate.helpers.CompilerTestingCommons import sigmastate.serialization.{SigmaSerializer, SerializationSpecification} class RuleStatusSerializerSpec extends SerializationSpecification with CompilerTestingCommons { private def roundtrip(status: RuleStatus) = { - implicit val ser = RuleStatusSerializer + implicit val ser: RuleStatusSerializer.type = RuleStatusSerializer roundTripTest(status) roundTripTestWithPos(status) } diff --git a/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala index 16fdd8ffee..c4162103c6 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializerSpec.scala @@ -8,7 +8,7 @@ import sigmastate.serialization.SerializationSpecification class SigmaValidationSettingsSerializerSpec extends SerializationSpecification with CompilerTestingCommons { private def roundtrip(settings: SigmaValidationSettings) = { - implicit val set = SigmaValidationSettingsSerializer + implicit val set: SigmaValidationSettingsSerializer.type = SigmaValidationSettingsSerializer roundTripTest(settings) roundTripTestWithPos(settings) }