diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db3427969c..fa239b73f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -103,7 +103,7 @@ jobs: key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} - name: Runs tests and collect coverage - run: sbt -jvm-opts ci/ci.jvmopts ++${{ matrix.scala }} commonJS/test corelibJS/test interpreterJS/test graphirJS/test sdkJS/test scJS/test + run: sbt -jvm-opts ci/ci.jvmopts ++${{ matrix.scala }} coreJS/test interpreterJS/test parsersJS/test sdkJS/test scJS/test - name: Publish a JVM snapshot ${{ github.ref }} if: env.HAS_SECRETS == 'true' diff --git a/build.sbt b/build.sbt index 31d769e1e2..a76c73d885 100644 --- a/build.sbt +++ b/build.sbt @@ -188,11 +188,12 @@ lazy val commonDependenies2 = libraryDependencies ++= Seq( val sigmajsCryptoFacadeVersion = "0.0.7" -lazy val common = crossProject(JVMPlatform, JSPlatform) - .in(file("common")) +lazy val core = crossProject(JVMPlatform, JSPlatform) + .in(file("core")) .settings(commonSettings ++ testSettings2, commonDependenies2, testingDependencies2, + scorexUtilDependency, publish / skip := true ) .jvmSettings( crossScalaSettings ) @@ -209,59 +210,17 @@ lazy val common = crossProject(JVMPlatform, JSPlatform) ), useYarn := true ) -lazy val commonJS = common.js - .enablePlugins(ScalaJSBundlerPlugin) - -lazy val corelib = crossProject(JVMPlatform, JSPlatform) - .in(file("core-lib")) - .dependsOn(common % allConfigDependency) - .settings(commonSettings ++ testSettings2, - commonDependenies2, - testingDependencies2, - crossScalaSettings, - scryptoDependency, - publish / skip := true - ) - .jvmSettings( - crossScalaSettings - ) - .jsSettings( - crossScalaSettingsJS, - libraryDependencies ++= Seq( - "org.scala-js" %%% "scala-js-macrotask-executor" % "1.0.0" - ), - useYarn := true - ) -lazy val corelibJS = corelib.js - .enablePlugins(ScalaJSBundlerPlugin) - -lazy val graphir = crossProject(JVMPlatform, JSPlatform) - .in(file("graph-ir")) - .dependsOn(common % allConfigDependency, corelib % allConfigDependency) - .settings( - commonDependenies2, - scryptoDependency, - publish / skip := true - ) - .jvmSettings( - crossScalaSettings, - libraryDependencies ++= Seq(scalameter) - ) - .jsSettings( - crossScalaSettingsJS, - useYarn := true - ) -lazy val graphirJS = graphir.js +lazy val coreJS = core.js .enablePlugins(ScalaJSBundlerPlugin) lazy val interpreter = crossProject(JVMPlatform, JSPlatform) .in(file("interpreter")) - .dependsOn(corelib % allConfigDependency) + .dependsOn(core % allConfigDependency) .settings( commonSettings ++ testSettings2, commonDependenies2, testingDependencies2, - scorexUtilDependency, fastparseDependency, circeDependency, + scorexUtilDependency, fastparseDependency, circeDependency, scryptoDependency, publish / skip := true ) .jvmSettings( crossScalaSettings ) @@ -319,7 +278,7 @@ lazy val parsersJS = parsers.js lazy val sdk = crossProject(JVMPlatform, JSPlatform) .in(file("sdk")) - .dependsOn(corelib % allConfigDependency, interpreter % allConfigDependency, parsers % allConfigDependency) + .dependsOn(core % allConfigDependency, interpreter % allConfigDependency, parsers % allConfigDependency) .settings(commonSettings ++ testSettings2, commonDependenies2, testingDependencies2, @@ -351,7 +310,6 @@ lazy val sdkJS = sdk.js lazy val sc = crossProject(JVMPlatform, JSPlatform) .in(file("sc")) .dependsOn( - graphir % allConfigDependency, interpreter % allConfigDependency, parsers % allConfigDependency, sdk % allConfigDependency @@ -361,6 +319,7 @@ lazy val sc = crossProject(JVMPlatform, JSPlatform) commonDependenies2, testingDependencies2, scorexUtilDependency, fastparseDependency, circeDependency, + scryptoDependency, Test / parallelExecution := false ) .settings(publish / skip := true) @@ -396,13 +355,13 @@ lazy val scJS = sc.js lazy val sigma = (project in file(".")) - .aggregate(common.jvm, corelib.jvm, graphir.jvm, interpreter.jvm, parsers.jvm, sc.jvm, sdk.jvm) + .aggregate(core.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm) .settings(libraryDefSettings, rootSettings) .settings(publish / aggregate := false) .settings(publishLocal / aggregate := false) lazy val aggregateCompile = ScopeFilter( - inProjects(common.jvm, corelib.jvm, graphir.jvm, interpreter.jvm, parsers.jvm, sc.jvm, sdk.jvm), + inProjects(core.jvm, interpreter.jvm, parsers.jvm, sdk.jvm, sc.jvm), inConfigurations(Compile)) lazy val rootSettings = Seq( diff --git a/common/shared/src/main/scala/scalan/TypeDesc.scala b/common/shared/src/main/scala/scalan/TypeDesc.scala deleted file mode 100644 index 98ecb1ec4c..0000000000 --- a/common/shared/src/main/scala/scalan/TypeDesc.scala +++ /dev/null @@ -1,140 +0,0 @@ -package scalan - -import scala.reflect.ClassTag -import scala.annotation.{implicitNotFound, unused} -import scala.language.implicitConversions - -/** Base type for all runtime type descriptors. Sigma uses type descriptors to - * represent structure of the data values. Data values of registers and context - * variables come equipped with type descriptors in order to check the actual type - * is the same as the type expected by the script. - * @see [[getReg]], [[getVar]] - */ -@implicitNotFound(msg = "No RType available for ${A}.") -abstract class RType[A] { - /** Class tag suitable for construct instances of Array[A]. */ - def classTag: ClassTag[A] - - /** Syntactically correct type name (type expression as String) */ - def name: String = this.toString - - /** Creates empty immutable array of this type. */ - def emptyArray: Array[A] = Array.empty[A](classTag) -} - -object RType { - /** Helper to request RType instances from an implicit scope.*/ - def apply[A](implicit t: RType[A]): RType[A] = t - - /** Helper cast from untyped descriptor to the typed one. */ - @inline def asType[T](t: RType[_]): RType[T] = t.asInstanceOf[RType[T]] - - def fromClassTag[A](ctA: ClassTag[A]): RType[A] = (ctA match { - case ClassTag.Boolean => BooleanType - case ClassTag.Byte => ByteType - case ClassTag.Short => ShortType - case ClassTag.Int => IntType - case ClassTag.Long => LongType - case ClassTag.Unit => UnitType - case _ => GeneralType[A](ctA) - }).asInstanceOf[RType[A]] - - type SomeType = RType[_] - - /** Type descriptor for types with limited type information like Any, AnyRef, Nothing. - * It also used to wrap class tags which are GenericClassTag instances - * (also with limited information about type structure). - * To describe structure of the type more precisely use concrete classes - * in the hierarchy of RType. - */ - case class GeneralType[A](classTag: ClassTag[A]) extends RType[A] { - override def name: String = classTag match { - case ClassTag.Any => "Any" - case ClassTag.AnyRef => "AnyRef" - case ClassTag.Nothing => "Nothing" - case ct => ct.runtimeClass.getSimpleName() - } - } - - /** Descriptor used to represent primitive types. */ - case class PrimitiveType[A](classTag: ClassTag[A], - override val emptyArray: Array[A]) extends RType[A] { - override def name: String = classTag.toString() - } - - val AnyType : RType[Any] = GeneralType[Any] (ClassTag.Any) - - implicit val BooleanType : RType[Boolean] = PrimitiveType[Boolean] (ClassTag.Boolean, Array.emptyBooleanArray) - implicit val ByteType : RType[Byte] = PrimitiveType[Byte] (ClassTag.Byte, Array.emptyByteArray) - 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) - implicit val UnitType : RType[Unit] = PrimitiveType[Unit] (ClassTag.Unit, Array[Unit]()(ClassTag.Unit)) - - implicit case object StringType extends RType[String] { - override def classTag: ClassTag[String] = ClassTag[String](classOf[String]) - override def name: String = "String" - } - - /** Descriptor of descriptor to represent type of RType[_] instances. - * This describes any possible descriptor, disregarding its underlying type. - * Thus the underlying type is assumed to be Any. */ - case object RTypeType extends RType[RType[_]] { - val classTag: ClassTag[RType[_]] = ClassTag[RType[_]](classOf[RType[_]]) - override def name: String = s"RType[Any]" - } - /** Implicitly obtain the single RTypeType descriptor casted to the given type A. */ - implicit def rtypeRType[A]: RType[RType[A]] = asType[RType[A]](RTypeType) - - implicit def pairRType[A,B](implicit tA: RType[A], tB: RType[B]): RType[(A,B)] = PairType(tA, tB) - - case class PairType[A,B](tFst: RType[A], tSnd: RType[B]) extends RType[(A,B)] { - val classTag: ClassTag[(A, B)] = scala.reflect.classTag[(A,B)] - override def name: String = s"(${tFst.name}, ${tSnd.name})" - } - implicit def extendPairType[A,B](pt: RType[(A,B)]): PairType[A,B] = pt.asInstanceOf[PairType[A,B]] - - implicit def funcRType[A,B](implicit tDom: RType[A], tRange: RType[B]): RType[A => B] = FuncType(tDom, tRange) - - case class FuncType[A,B](tDom: RType[A], tRange: RType[B]) extends RType[A => B] { - val classTag: ClassTag[A => B] = scala.reflect.classTag[A => B] - override def name: String = s"${tDom.name} => ${tRange.name}" - } - - implicit def arrayRType[A](implicit tA: RType[A]): RType[Array[A]] = ArrayType(tA) - - case class ArrayType[A](tA: RType[A]) extends RType[Array[A]] { - val classTag: ClassTag[Array[A]] = { - @unused // avoid warning about unused ctA - implicit val ctA: ClassTag[A] = tA.classTag - scala.reflect.classTag[Array[A]] - } - override def name: String = s"Array[${tA.name}]" - } - - implicit def optionRType[A](implicit tA: RType[A]): RType[Option[A]] = OptionType(tA) - - case class OptionType[A](tA: RType[A]) extends RType[Option[A]] { - val classTag: ClassTag[Option[A]] = { - @unused // avoid warning about unused ctA - implicit val ctA: ClassTag[A] = tA.classTag - scala.reflect.classTag[Option[A]] - } - override def name: String = s"Option[${tA.name}]" - } - - /** Underlying type of Thunk[A] values (or by-name values of type A). */ - type ThunkData[A] = () => A - - implicit def thunkRType[A](implicit tA: RType[A]): RType[ThunkData[A]] = ThunkType(tA) - - case class ThunkType[A](tA: RType[A]) extends RType[ThunkData[A]] { - val classTag: ClassTag[ThunkData[A]] = { - @unused // avoid warning about unused ctA - implicit val ctA: ClassTag[A] = tA.classTag - scala.reflect.classTag[ThunkData[A]] - } - override def name: String = s"Thunk[${tA.name}]" - } - -} diff --git a/common/shared/src/main/scala/scalan/package.scala b/common/shared/src/main/scala/scalan/package.scala deleted file mode 100644 index 1a25931fd6..0000000000 --- a/common/shared/src/main/scala/scalan/package.scala +++ /dev/null @@ -1,26 +0,0 @@ - -import scala.reflect.ClassTag - -package object scalan { - - /** Allows implicit resolution to find appropriate instance of ClassTag in - * the scope where RType is implicitly available. */ - implicit def rtypeToClassTag[A](implicit t: RType[A]): ClassTag[A] = t.classTag - - /** Immutable empty array of integers, should be used instead of allocating new empty arrays. */ - val EmptyArrayOfInt = Array.empty[Int] - - /** Immutable empty Seq[Int] backed by empty array. - * You should prefer using it instead of `Seq[Int]()` or `Seq.empty[Int]` - */ - val EmptySeqOfInt: Seq[Int] = EmptyArrayOfInt - - /** Create a new empty buffer around pre-allocated empty array. - * This method is preferred, rather that creating empty debox.Buffer directly - * because it allows to avoid allocation of the empty array. - * Note, this method allocates a new Buffer, but the underlying empty array is shared. - * This is safe because empty arrays are immutable. - */ - def emptyDBufferOfInt: debox.Buffer[Int] = debox.Buffer.unsafe(EmptyArrayOfInt) - -} diff --git a/common/shared/src/main/scala/scalan/reflection/CommonReflection.scala b/common/shared/src/main/scala/scalan/reflection/CommonReflection.scala deleted file mode 100644 index b839d668be..0000000000 --- a/common/shared/src/main/scala/scalan/reflection/CommonReflection.scala +++ /dev/null @@ -1,74 +0,0 @@ -package scalan.reflection - -import scala.collection.compat.immutable.ArraySeq -import scala.collection.mutable -import scala.collection.immutable - -/** Reflection metadata and global dictionaries to access it. - * For each class of this module that needs reflection metadata, - * we register a class entry with the necessary information. - * Only information that is needed at runtime is registered. - */ -object CommonReflection { - /** Descriptors of classes. */ - val classes = mutable.HashMap.empty[Class[_], SRClass[_]] - - /** Registers a class entry in the map of classes. - * - * @tparam T the type of the class to be registered - * @param clazz the class to be registered - * @param constructors the constructors of the class - * @param fields the fields of the class - * @param methods the methods of the class (represented as a map of method names and argument types to the corresponding RMethod instances) - */ - def registerClassEntry[T](clazz: Class[T], - constructors: Seq[SRConstructor[_]] = ArraySeq.empty, - fields: Map[String, SRField] = Map.empty, - methods: Map[(String, Seq[Class[_]]), RMethod] = Map.empty): Unit = classes.synchronized { - classes.put(clazz, new SRClass(clazz, constructors, fields, methods)) - } - - registerClassEntry(classOf[Boolean]) - - registerClassEntry(classOf[Byte]) - - registerClassEntry(classOf[Short]) - - registerClassEntry(classOf[Int]) - - registerClassEntry(classOf[Long]) - - registerClassEntry(classOf[Product2[_, _]]) - - registerClassEntry(classOf[immutable.$colon$colon[_]], - constructors = Array( - mkConstructor(Array(classOf[java.lang.Object], classOf[immutable.List[_]])) { args => - new immutable.$colon$colon(args(0).asInstanceOf[java.lang.Object], args(1).asInstanceOf[immutable.List[_]]) - } - ) - ) - - { val clazz = classOf[scala.Option[_]] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "filter", Array(classOf[scala.Function1[_,_]])) { (obj, args) => - obj.asInstanceOf[Option[Any]].filter(args(0).asInstanceOf[Any => Boolean]) - }, - mkMethod(clazz, "map", Array(classOf[scala.Function1[_,_]])) { (obj, args) => - obj.asInstanceOf[Option[Any]].map(args(0).asInstanceOf[Any => Any]) - } - ) - ) - } - - { val clazz = classOf[scala.Some[_]] - registerClassEntry(clazz, - constructors = Array( - mkConstructor(Array(classOf[java.lang.Object])) { args => - new scala.Some(args(0).asInstanceOf[java.lang.Object]) - } - ) - ) - } - -} diff --git a/core-lib/shared/src/main/scala/special/Types.scala b/core-lib/shared/src/main/scala/special/Types.scala deleted file mode 100644 index 5b37d57d4e..0000000000 --- a/core-lib/shared/src/main/scala/special/Types.scala +++ /dev/null @@ -1,34 +0,0 @@ -package special - -import scalan.util.CollectionUtil -import scalan.RType -import scala.reflect.ClassTag -import special.collection.Coll -import scalan.RType.SomeType - -object Types { - /** Generic representation of tuples values. */ - type TupleData = Coll[Any] - - /** Returns an RType object representing a tuple type with the given SomeType array types. - * @param types An array of SomeType representing the types of each item in the tuple. - * @return An RType object for the tuple type. - */ - def tupleRType(types: Array[SomeType]): RType[TupleData] = TupleType(types) - - /** Descriptor (in RType family) of tuple types. - * @param items types of tuple items - */ - case class TupleType(items: Array[SomeType]) extends RType[TupleData] { - override val classTag: ClassTag[TupleData] = scala.reflect.classTag[TupleData] - - override def name: String = items.map(_.name).mkString("(", ", ", ")") - - override def hashCode(): Int = CollectionUtil.deepHashCode(items) - - override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { - case that: TupleType => java.util.Arrays.equals(items.asInstanceOf[Array[AnyRef]], that.items.asInstanceOf[Array[AnyRef]]) - case _ => false - }) - } -} diff --git a/core-lib/shared/src/main/scala/special/collection/Helpers.scala b/core-lib/shared/src/main/scala/special/collection/Helpers.scala deleted file mode 100644 index 732603b7e4..0000000000 --- a/core-lib/shared/src/main/scala/special/collection/Helpers.scala +++ /dev/null @@ -1,11 +0,0 @@ -package special.collection - -object Helpers { - private def sameLengthErrorMsg[A,B](xs: Coll[A], ys: Coll[B]) = - s"Collections should have same length but was ${xs.length} and ${ys.length}:\n xs=$xs;\n ys=$ys" - - def requireSameLength[A,B](xs: Coll[A], ys: Coll[B]) = { - require(xs.length == ys.length, sameLengthErrorMsg(xs, ys)) - } - -} diff --git a/core-lib/shared/src/main/scala/special/collection/package.scala b/core-lib/shared/src/main/scala/special/collection/package.scala deleted file mode 100644 index b8be71be23..0000000000 --- a/core-lib/shared/src/main/scala/special/collection/package.scala +++ /dev/null @@ -1,33 +0,0 @@ -package special - -import scala.language.implicitConversions -import scalan.RType - -import scala.reflect.{classTag, ClassTag} - -package collection { - /** Type descriptor for `Coll[A]` type. */ - case class CollType[A](tItem: RType[A]) extends RType[Coll[A]] { - override val classTag: ClassTag[Coll[A]] = ClassTag[Coll[A]](classOf[Coll[A]]) - override def name: String = s"Coll[${tItem.name}]" - } -} - -package object collection { - /** Forces reflection data initialization */ - val reflection = CoreLibReflection - - /** Implicit resolution of `Coll[A]` type descriptor, given a descriptor of `A`. */ - implicit def collRType[A](implicit tA: RType[A]): RType[Coll[A]] = CollType[A](tA) - - /** Conversion to underlying descriptor class. - * Allows syntax like - * - * ```val tColl: RType[Coll[A]] = ...; tColl.tItem``` - * - * where `tItem` is a method of `CollType`, but is not defined on `RType`. - */ - implicit def downcastCollType[A](ct: RType[Coll[A]]): CollType[A] = ct.asInstanceOf[CollType[A]] - - implicit val collBuilderRType: RType[CollBuilder] = RType.fromClassTag(classTag[CollBuilder]) -} diff --git a/core-lib/shared/src/main/scala/special/sigma/package.scala b/core-lib/shared/src/main/scala/special/sigma/package.scala deleted file mode 100644 index a81b27a45b..0000000000 --- a/core-lib/shared/src/main/scala/special/sigma/package.scala +++ /dev/null @@ -1,34 +0,0 @@ -package special - -import java.math.BigInteger -import scalan.RType -import scalan.RType.GeneralType - -import scala.reflect.classTag - -/** The following implicit values are used as type descriptors of all the predefined Sigma types. - * @see [[RType]] class - */ -package object sigma { - /** Forces reflection data initialization */ - val reflection = CoreLibReflection - - implicit val BigIntRType: RType[BigInt] = GeneralType(classTag[BigInt]) - implicit val GroupElementRType: RType[GroupElement] = GeneralType(classTag[GroupElement]) - implicit val SigmaPropRType: RType[SigmaProp] = GeneralType(classTag[SigmaProp]) - implicit val AvlTreeRType: RType[AvlTree] = GeneralType(classTag[AvlTree]) - - implicit val BoxRType: RType[Box] = GeneralType(classTag[Box]) - implicit val ContextRType: RType[Context] = GeneralType(classTag[Context]) - - implicit val HeaderRType: RType[Header] = GeneralType(classTag[Header]) - implicit val PreHeaderRType: RType[PreHeader] = GeneralType(classTag[PreHeader]) - - implicit val AnyValueRType: RType[AnyValue] = RType.fromClassTag(classTag[AnyValue]) - - implicit val SigmaContractRType: RType[SigmaContract] = RType.fromClassTag(classTag[SigmaContract]) - implicit val SigmaDslBuilderRType: RType[SigmaDslBuilder] = RType.fromClassTag(classTag[SigmaDslBuilder]) - - implicit val BigIntegerRType: RType[BigInteger] = GeneralType(classTag[BigInteger]) - -} \ No newline at end of file diff --git a/common/js/src/main/scala/scalan/reflection/Platform.scala b/core/js/src/main/scala/sigma/reflection/Platform.scala similarity index 94% rename from common/js/src/main/scala/scalan/reflection/Platform.scala rename to core/js/src/main/scala/sigma/reflection/Platform.scala index 7b4c2d74e6..199729fc7a 100644 --- a/common/js/src/main/scala/scalan/reflection/Platform.scala +++ b/core/js/src/main/scala/sigma/reflection/Platform.scala @@ -1,7 +1,6 @@ -package scalan.reflection - -import sigmastate.RuntimePlatform +package sigma.reflection +import sigma.RuntimePlatform import scala.collection.mutable /** JS Platform dependent implementation of reflection methods. */ @@ -15,7 +14,7 @@ object Platform { * found. */ def resolveClass[T](clazz: Class[T]): RClass[T] = { - val res = CommonReflection.classes.get(clazz) match { + val res = ReflectionData.classes.get(clazz) match { case Some(c) => assert(c.clazz == clazz) c diff --git a/common/jvm/src/main/scala/scalan/reflection/JavaImpl.scala b/core/jvm/src/main/scala/sigma/reflection/JavaImpl.scala similarity index 96% rename from common/jvm/src/main/scala/scalan/reflection/JavaImpl.scala rename to core/jvm/src/main/scala/sigma/reflection/JavaImpl.scala index fba9fcd29c..fcebc8f928 100644 --- a/common/jvm/src/main/scala/scalan/reflection/JavaImpl.scala +++ b/core/jvm/src/main/scala/sigma/reflection/JavaImpl.scala @@ -1,4 +1,4 @@ -package scalan.reflection +package sigma.reflection import debox.cfor @@ -134,9 +134,6 @@ object JRConstructor { */ class JRMethod private (val value: Method) extends RMethod { override def invoke(obj: Any, args: AnyRef*): AnyRef = { -// val name = value.getName -// val parameterTypes: Seq[Class[_]] = value.getParameterTypes -// memoize(declaringClass.methods)((name, parameterTypes), this) value.invoke(obj, args:_*) } diff --git a/common/jvm/src/main/scala/scalan/reflection/Platform.scala b/core/jvm/src/main/scala/sigma/reflection/Platform.scala similarity index 98% rename from common/jvm/src/main/scala/scalan/reflection/Platform.scala rename to core/jvm/src/main/scala/sigma/reflection/Platform.scala index 7129cfb814..6e5aac1b8e 100644 --- a/common/jvm/src/main/scala/scalan/reflection/Platform.scala +++ b/core/jvm/src/main/scala/sigma/reflection/Platform.scala @@ -1,7 +1,6 @@ -package scalan.reflection - -import sigmastate.RuntimePlatform +package sigma.reflection +import sigma.RuntimePlatform import scala.collection.concurrent.TrieMap /** Platform dependent implementation of reflection methods. */ diff --git a/common/jvm/src/test/scala/scalan/util/FileUtil.scala b/core/jvm/src/test/scala/sigma/util/FileUtil.scala similarity index 98% rename from common/jvm/src/test/scala/scalan/util/FileUtil.scala rename to core/jvm/src/test/scala/sigma/util/FileUtil.scala index c4a8d15595..cac749c6a3 100644 --- a/common/jvm/src/test/scala/scalan/util/FileUtil.scala +++ b/core/jvm/src/test/scala/sigma/util/FileUtil.scala @@ -1,7 +1,7 @@ -package scalan.util +package sigma.util -import scalan.util.CollectionUtil.AnyOps -import scalan.util.StringUtil.cleanFileName +import sigma.util.CollectionUtil.AnyOps +import sigma.util.StringUtil.cleanFileName import java.io._ import java.net.{JarURLConnection, URL} diff --git a/common/jvm/src/test/scala/scalan/util/FileUtilTests.scala b/core/jvm/src/test/scala/sigma/util/FileUtilTests.scala similarity index 93% rename from common/jvm/src/test/scala/scalan/util/FileUtilTests.scala rename to core/jvm/src/test/scala/sigma/util/FileUtilTests.scala index 2edb4289ce..7a09ad1685 100644 --- a/common/jvm/src/test/scala/scalan/util/FileUtilTests.scala +++ b/core/jvm/src/test/scala/sigma/util/FileUtilTests.scala @@ -1,6 +1,6 @@ -package scalan.util +package sigma.util -import scalan.BaseNestedTests +import sigma.BaseNestedTests class FileUtilTests extends BaseNestedTests { import FileUtil._ @@ -21,7 +21,7 @@ class FileUtilTests extends BaseNestedTests { } describe("File traversals") { - val root = file("common/shared/src/test/resources/root") + val root = file("core/shared/src/test/resources/root") val subdir = file(root, "subdir") val subsubdir = file(subdir, "subsubdir") val empty = { val dir = file(root, "empty"); dir.mkdir(); dir } diff --git a/common/jvm/src/test/scala/scalan/util/ProcessUtil.scala b/core/jvm/src/test/scala/sigma/util/ProcessUtil.scala similarity index 99% rename from common/jvm/src/test/scala/scalan/util/ProcessUtil.scala rename to core/jvm/src/test/scala/sigma/util/ProcessUtil.scala index f30d1fc2e0..7afa9bb616 100644 --- a/common/jvm/src/test/scala/scalan/util/ProcessUtil.scala +++ b/core/jvm/src/test/scala/sigma/util/ProcessUtil.scala @@ -1,4 +1,4 @@ -package scalan.util +package sigma.util import java.io.File import scala.collection.mutable diff --git a/common/shared/src/main/scala-2.11/sigmastate/kiama/util/Collections.scala b/core/shared/src/main/scala-2.11/sigma/kiama/util/Collections.scala similarity index 97% rename from common/shared/src/main/scala-2.11/sigmastate/kiama/util/Collections.scala rename to core/shared/src/main/scala-2.11/sigma/kiama/util/Collections.scala index 347a996452..476ea45dbd 100644 --- a/common/shared/src/main/scala-2.11/sigmastate/kiama/util/Collections.scala +++ b/core/shared/src/main/scala-2.11/sigma/kiama/util/Collections.scala @@ -8,7 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama +package sigma.kiama package util object Collections { diff --git a/common/shared/src/main/scala-2.12/sigmastate/kiama/util/Collections.scala b/core/shared/src/main/scala-2.12/sigma/kiama/util/Collections.scala similarity index 97% rename from common/shared/src/main/scala-2.12/sigmastate/kiama/util/Collections.scala rename to core/shared/src/main/scala-2.12/sigma/kiama/util/Collections.scala index 347a996452..476ea45dbd 100644 --- a/common/shared/src/main/scala-2.12/sigmastate/kiama/util/Collections.scala +++ b/core/shared/src/main/scala-2.12/sigma/kiama/util/Collections.scala @@ -8,7 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama +package sigma.kiama package util object Collections { diff --git a/common/shared/src/main/scala-2.13/sigmastate/kiama/util/Collections.scala b/core/shared/src/main/scala-2.13/sigma/kiama/util/Collections.scala similarity index 96% rename from common/shared/src/main/scala-2.13/sigmastate/kiama/util/Collections.scala rename to core/shared/src/main/scala-2.13/sigma/kiama/util/Collections.scala index 14f3936af1..812ac7707d 100644 --- a/common/shared/src/main/scala-2.13/sigmastate/kiama/util/Collections.scala +++ b/core/shared/src/main/scala-2.13/sigma/kiama/util/Collections.scala @@ -8,8 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama -package util +package sigma.kiama.util object Collections { diff --git a/common/shared/src/main/scala/java7/compat/Math.scala b/core/shared/src/main/scala/java7/compat/Math.scala similarity index 100% rename from common/shared/src/main/scala/java7/compat/Math.scala rename to core/shared/src/main/scala/java7/compat/Math.scala diff --git a/core-lib/shared/src/main/scala/special/collection/Colls.scala b/core/shared/src/main/scala/sigma/Colls.scala similarity index 99% rename from core-lib/shared/src/main/scala/special/collection/Colls.scala rename to core/shared/src/main/scala/sigma/Colls.scala index 027297de18..625120deac 100644 --- a/core-lib/shared/src/main/scala/special/collection/Colls.scala +++ b/core/shared/src/main/scala/sigma/Colls.scala @@ -1,6 +1,6 @@ -package special.collection +package sigma -import scalan._ +import sigma.data.RType /** Indexed (zero-based) collection of elements of type `A`. * NOTE: declaring it `abstract class` makes some performance benefits, but doesn't work diff --git a/common/shared/src/main/scala/sigmastate/Environment.scala b/core/shared/src/main/scala/sigma/Environment.scala similarity index 83% rename from common/shared/src/main/scala/sigmastate/Environment.scala rename to core/shared/src/main/scala/sigma/Environment.scala index f15752aa9c..959e02c1fb 100644 --- a/common/shared/src/main/scala/sigmastate/Environment.scala +++ b/core/shared/src/main/scala/sigma/Environment.scala @@ -1,4 +1,4 @@ -package sigmastate +package sigma /** Describes the current execution environment. */ sealed abstract class Environment { @@ -17,6 +17,6 @@ object Environment { implicit val current: Environment = new Environment { override def isJVM: Boolean = runtimePlatform == RuntimePlatform.JVM override def isJS: Boolean = runtimePlatform == RuntimePlatform.JS - override def runtimePlatform: RuntimePlatform = scalan.reflection.Platform.runtimePlatform + override def runtimePlatform: RuntimePlatform = sigma.reflection.Platform.runtimePlatform } } \ No newline at end of file diff --git a/core-lib/shared/src/main/scala/special/collection/Extensions.scala b/core/shared/src/main/scala/sigma/Extensions.scala similarity index 98% rename from core-lib/shared/src/main/scala/special/collection/Extensions.scala rename to core/shared/src/main/scala/sigma/Extensions.scala index 4256d91336..08087eced0 100644 --- a/core-lib/shared/src/main/scala/special/collection/Extensions.scala +++ b/core/shared/src/main/scala/sigma/Extensions.scala @@ -1,4 +1,4 @@ -package special.collection +package sigma import debox.cfor import scorex.util.encode.Base16 diff --git a/common/shared/src/main/scala/sigmastate/RuntimePlatform.scala b/core/shared/src/main/scala/sigma/RuntimePlatform.scala similarity index 95% rename from common/shared/src/main/scala/sigmastate/RuntimePlatform.scala rename to core/shared/src/main/scala/sigma/RuntimePlatform.scala index b6d0bc30fb..23d50cbcb3 100644 --- a/common/shared/src/main/scala/sigmastate/RuntimePlatform.scala +++ b/core/shared/src/main/scala/sigma/RuntimePlatform.scala @@ -1,4 +1,4 @@ -package sigmastate +package sigma /** Descriptor of a runtime platform. Can be used to conditionally execute code. */ sealed trait RuntimePlatform { diff --git a/core-lib/shared/src/main/scala/special/sigma/SigmaDsl.scala b/core/shared/src/main/scala/sigma/SigmaDsl.scala similarity index 94% rename from core-lib/shared/src/main/scala/special/sigma/SigmaDsl.scala rename to core/shared/src/main/scala/sigma/SigmaDsl.scala index b1f27f0899..7609d38356 100644 --- a/core-lib/shared/src/main/scala/special/sigma/SigmaDsl.scala +++ b/core/shared/src/main/scala/sigma/SigmaDsl.scala @@ -1,13 +1,8 @@ -package special.sigma +package sigma import java.math.BigInteger -import special.collection._ -import scalan._ -import scorex.crypto.authds.{ADDigest, ADValue} -import scorex.crypto.authds.avltree.batch.Operation - -import scala.util.Try +import sigma.data._ /** * All `modQ` operations assume that Q is a global constant (an order of the only one cryptographically strong group @@ -316,7 +311,7 @@ trait Box { * @tparam T expected type of the register. * @return Some(value) if the register is defined AND has the given type. * None otherwise - * @throws special.sigma.InvalidType exception when the type of the register value is + * @throws `sigmastate.eval.InvalidType` exception when the type of the register value is * different from cT. * @since 2.0 */ @@ -485,48 +480,15 @@ trait AvlTree { */ def remove(operations: Coll[Coll[Byte]], proof: Coll[Byte]): Option[AvlTree] - /** Creates a new instance of [[AvlTreeVerifier]] with the given `proof` and using - * properties of this AvlTree (digest, keyLength, valueLengthOpt) for constructor - * arguments. - * - * @param proof bytes of the serialized proof which is used to represent the tree. - */ - def createVerifier(proof: Coll[Byte]): AvlTreeVerifier +// /** Creates a new instance of [[AvlTreeVerifier]] with the given `proof` and using +// * properties of this AvlTree (digest, keyLength, valueLengthOpt) for constructor +// * arguments. +// * +// * @param proof bytes of the serialized proof which is used to represent the tree. +// */ +// def createVerifier(proof: Coll[Byte]): AvlTreeVerifier } -/** Represents operations of AVL tree verifier in an abstract (implementation independent) - * way which allows declaration of the [[AvlTree.createVerifier()]] method. - */ -trait AvlTreeVerifier { - /** - * If operation.key exists in the tree and the operation succeeds, - * returns Success(Some(v)), where v is the value associated with operation.key - * before the operation. - * If operation.key does not exists in the tree and the operation succeeds, returns Success(None). - * Returns Failure if the operation fails or the proof does not verify. - * After one failure, all subsequent operations will fail and digest - * is None. - * - * @param operation an operation descriptor - * @return - Success(Some(old value)), Success(None), or Failure - */ - def performOneOperation(operation: Operation): Try[Option[ADValue]] - - /** Returns the max height of the tree extracted from the root digest. */ - def treeHeight: Int - - /** - * Returns Some[the current digest of the authenticated data structure], - * where the digest contains the root hash and the root height - * Returns None if the proof verification failed at construction - * or during any of the operations. - * - * @return - Some[digest] or None - */ - def digest: Option[ADDigest] -} - - /** Only header fields that can be predicted by a miner. */ trait PreHeader { /** Block version, to be increased on every soft and hardfork. */ @@ -694,7 +656,7 @@ trait Context { * @tparam T expected type of the variable. * @return Some(value) if the variable is defined in the context AND has the given type. * None otherwise - * @throws special.sigma.InvalidType exception when the type of the variable value is + * @throws `sigmastate.eval.InvalidType` exception when the type of the variable value is * different from cT. */ def getVar[T](id: Byte)(implicit cT: RType[T]): Option[T] diff --git a/common/shared/src/main/scala/sigmastate/VersionContext.scala b/core/shared/src/main/scala/sigma/VersionContext.scala similarity index 98% rename from common/shared/src/main/scala/sigmastate/VersionContext.scala rename to core/shared/src/main/scala/sigma/VersionContext.scala index ef220d1109..14e6dc8b21 100644 --- a/common/shared/src/main/scala/sigmastate/VersionContext.scala +++ b/core/shared/src/main/scala/sigma/VersionContext.scala @@ -1,6 +1,6 @@ -package sigmastate +package sigma -import sigmastate.VersionContext.JitActivationVersion +import VersionContext.JitActivationVersion import scala.util.DynamicVariable diff --git a/common/shared/src/main/scala/scalan/AnyVals.scala b/core/shared/src/main/scala/sigma/data/AnyVals.scala similarity index 99% rename from common/shared/src/main/scala/scalan/AnyVals.scala rename to core/shared/src/main/scala/sigma/data/AnyVals.scala index ca0887401e..51262bfe71 100644 --- a/common/shared/src/main/scala/scalan/AnyVals.scala +++ b/core/shared/src/main/scala/sigma/data/AnyVals.scala @@ -1,4 +1,4 @@ -package scalan +package sigma.data import java.util.HashMap diff --git a/core-lib/shared/src/main/scala/special/collection/CollsOverArrays.scala b/core/shared/src/main/scala/sigma/data/CollsOverArrays.scala similarity index 95% rename from core-lib/shared/src/main/scala/special/collection/CollsOverArrays.scala rename to core/shared/src/main/scala/sigma/data/CollsOverArrays.scala index 7b91c0f50b..a5bb543e1b 100644 --- a/core-lib/shared/src/main/scala/special/collection/CollsOverArrays.scala +++ b/core/shared/src/main/scala/sigma/data/CollsOverArrays.scala @@ -1,15 +1,10 @@ -package special.collection - -import java.util -import scalan._ -import scalan.util.CollectionUtil -import scalan.RType -import Helpers._ -import debox.Buffer -import scalan.RType._ -import sigmastate.VersionContext -import sigmastate.util.{MaxArrayLength, safeConcatArrays_v5} -import debox.cfor +package sigma.data + +import debox.{Buffer, cfor} +import sigma.data.RType._ +import sigma.util.{CollectionUtil, MaxArrayLength, safeConcatArrays_v5} +import sigma.{Coll, CollBuilder, PairColl, VersionContext, requireSameLength} +import sigma.rtypeToClassTag class CollOverArray[@specialized A](val toArray: Array[A], val builder: CollBuilder) (implicit tA: RType[A]) extends Coll[A] { @@ -140,14 +135,14 @@ class CollOverArray[@specialized A](val toArray: Array[A], val builder: CollBuil override def equals(obj: scala.Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case obj: CollOverArray[_] if obj.tItem == this.tItem => - util.Objects.deepEquals(obj.toArray, toArray) + java.util.Objects.deepEquals(obj.toArray, toArray) case _ => false }) override def hashCode() = CollectionUtil.deepHashCode(toArray) } -class CollOverArrayBuilder extends CollBuilder { builder => +private[sigma] class CollOverArrayBuilder extends CollBuilder { builder => @inline override def pairColl[@specialized A, @specialized B](as: Coll[A], bs: Coll[B]): PairColl[A, B] = { if (VersionContext.current.isJitActivated) { @@ -248,14 +243,14 @@ class PairOfCols[@specialized L, @specialized R](val ls: Coll[L], val rs: Coll[R }) override def hashCode() = ls.hashCode() * 41 + rs.hashCode() - @inline implicit def tL = ls.tItem - @inline implicit def tR = rs.tItem + @inline implicit def tL: RType[L] = ls.tItem + @inline implicit def tR: RType[R] = rs.tItem override lazy val tItem: RType[(L, R)] = { RType.pairRType(tL, tR) } - override def builder: CollBuilder = new CollOverArrayBuilder + override def builder: CollBuilder = ls.builder override def toArray: Array[(L, R)] = ls.toArray.zip(rs.toArray) @inline override def length: Int = if (ls.length <= rs.length) ls.length else rs.length @inline override def apply(i: Int): (L, R) = (ls(i), rs(i)) @@ -399,7 +394,7 @@ class PairOfCols[@specialized L, @specialized R](val ls: Coll[L], val rs: Coll[R } override def unionSet(that: Coll[(L, R)]): Coll[(L, R)] = { - val set = new util.HashSet[(L,R)](32) + val set = new java.util.HashSet[(L,R)](32) implicit val ctL = ls.tItem.classTag implicit val ctR = rs.tItem.classTag val resL = Buffer.empty[L] diff --git a/common/shared/src/main/scala/scalan/DFunc.scala b/core/shared/src/main/scala/sigma/data/DFunc.scala similarity index 89% rename from common/shared/src/main/scala/scalan/DFunc.scala rename to core/shared/src/main/scala/sigma/data/DFunc.scala index 23f4766fa8..39c4ce0db7 100644 --- a/common/shared/src/main/scala/scalan/DFunc.scala +++ b/core/shared/src/main/scala/sigma/data/DFunc.scala @@ -1,4 +1,4 @@ -package scalan +package sigma.data /** Function interface which support specialization and thus unboxed invocations. */ abstract class DFunc[@specialized(Int) A, B] { diff --git a/common/shared/src/main/scala/scalan/Lazy.scala b/core/shared/src/main/scala/sigma/data/Lazy.scala similarity index 96% rename from common/shared/src/main/scala/scalan/Lazy.scala rename to core/shared/src/main/scala/sigma/data/Lazy.scala index bb0495fb5a..6e35a0b9b9 100644 --- a/common/shared/src/main/scala/scalan/Lazy.scala +++ b/core/shared/src/main/scala/sigma/data/Lazy.scala @@ -1,4 +1,4 @@ -package scalan +package sigma.data /** Non-thread safe (but efficient on single thread) immutable lazy value. * The `block` is executed only once. */ diff --git a/common/shared/src/main/scala/scalan/OverloadHack.scala b/core/shared/src/main/scala/sigma/data/OverloadHack.scala similarity index 97% rename from common/shared/src/main/scala/scalan/OverloadHack.scala rename to core/shared/src/main/scala/sigma/data/OverloadHack.scala index 81d92e6f0f..7de6892144 100644 --- a/common/shared/src/main/scala/scalan/OverloadHack.scala +++ b/core/shared/src/main/scala/sigma/data/OverloadHack.scala @@ -1,4 +1,4 @@ -package scalan +package sigma.data /** Scala specific trick to appease erasure of methods argument types. * Example usage: diff --git a/core/shared/src/main/scala/sigma/data/RType.scala b/core/shared/src/main/scala/sigma/data/RType.scala new file mode 100644 index 0000000000..281e032aa4 --- /dev/null +++ b/core/shared/src/main/scala/sigma/data/RType.scala @@ -0,0 +1,177 @@ +package sigma.data + +import sigma.{Coll, TupleData} +import sigma.data.RType.{SomeType, ThunkData} +import sigma.util.CollectionUtil + +import scala.reflect.ClassTag +import scala.annotation.{implicitNotFound, nowarn, unused} +import scala.language.implicitConversions + +/** Base type for all runtime type descriptors. Sigma uses type descriptors to + * represent structure of the data values. Data values of registers and context + * variables come equipped with type descriptors in order to check the actual type + * is the same as the type expected by the script. + * @see [[getReg]], [[getVar]] + */ +@implicitNotFound(msg = "No RType available for ${A}.") +sealed abstract class RType[A] { + /** Class tag suitable for construct instances of Array[A]. */ + def classTag: ClassTag[A] + + /** Syntactically correct type name (type expression as String) */ + def name: String = this.toString + + /** Creates empty immutable array of this type. */ + def emptyArray: Array[A] = Array.empty[A](classTag) +} + +/** Type descriptor for types with limited type information like Any, AnyRef, Nothing. + * It also used to wrap class tags which are GenericClassTag instances + * (also with limited information about type structure). + * To describe structure of the type more precisely use concrete classes + * in the hierarchy of RType. + */ +case class GeneralType[A](classTag: ClassTag[A]) extends RType[A] { + override def name: String = classTag match { + case ClassTag.Any => "Any" + case ClassTag.AnyRef => "AnyRef" + case ClassTag.Nothing => "Nothing" + case ct => ct.runtimeClass.getSimpleName() + } +} + +/** Descriptor used to represent primitive types. */ +case class PrimitiveType[A]( + classTag: ClassTag[A], + override val emptyArray: Array[A]) extends RType[A] { + override def name: String = classTag.toString() +} + +case class StringType() extends RType[String] { + override def classTag: ClassTag[String] = ClassTag[String](classOf[String]) + + override def name: String = "String" +} + +/** Descriptor of descriptor to represent type of RType[_] instances. + * This describes any possible descriptor, disregarding its underlying type. + * Thus the underlying type is assumed to be Any. */ +case object RTypeType extends RType[RType[_]] { + val classTag: ClassTag[RType[_]] = ClassTag[RType[_]](classOf[RType[_]]) + + override def name: String = s"RType[Any]" +} + +case class PairType[A, B](tFst: RType[A], tSnd: RType[B]) extends RType[(A, B)] { + val classTag: ClassTag[(A, B)] = scala.reflect.classTag[(A, B)] + + override def name: String = s"(${tFst.name}, ${tSnd.name})" +} + +case class ArrayType[A](tA: RType[A]) extends RType[Array[A]] { + val classTag: ClassTag[Array[A]] = { + @nowarn implicit val ctA: ClassTag[A] = tA.classTag + scala.reflect.classTag[Array[A]] + } + + override def name: String = s"Array[${tA.name}]" +} + +case class FuncType[A, B](tDom: RType[A], tRange: RType[B]) extends RType[A => B] { + val classTag: ClassTag[A => B] = scala.reflect.classTag[A => B] + + override def name: String = s"${tDom.name} => ${tRange.name}" +} + +case class OptionType[A](tA: RType[A]) extends RType[Option[A]] { + val classTag: ClassTag[Option[A]] = { + @unused // avoid warning about unused ctA + implicit val ctA: ClassTag[A] = tA.classTag + scala.reflect.classTag[Option[A]] + } + + override def name: String = s"Option[${tA.name}]" +} + +/** Type descriptor for `Coll[A]` type. */ +case class CollType[A](tItem: RType[A]) extends RType[Coll[A]] { + override val classTag: ClassTag[Coll[A]] = ClassTag[Coll[A]](classOf[Coll[A]]) + + override def name: String = s"Coll[${tItem.name}]" +} + +case class ThunkType[A](tA: RType[A]) extends RType[ThunkData[A]] { + val classTag: ClassTag[ThunkData[A]] = { + @unused // avoid warning about unused ctA + implicit val ctA: ClassTag[A] = tA.classTag + scala.reflect.classTag[ThunkData[A]] + } + + override def name: String = s"Thunk[${tA.name}]" +} + +/** Descriptor (in RType family) of tuple types. + * + * @param items types of tuple items + */ +case class TupleType(items: Array[SomeType]) extends RType[TupleData] { + override val classTag: ClassTag[TupleData] = scala.reflect.classTag[TupleData] + + override def name: String = items.map(_.name).mkString("(", ", ", ")") + + override def hashCode(): Int = CollectionUtil.deepHashCode(items) + + override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { + case that: TupleType => java.util.Arrays.equals(items.asInstanceOf[Array[AnyRef]], that.items.asInstanceOf[Array[AnyRef]]) + case _ => false + }) +} + +object RType { + /** Helper to request RType instances from an implicit scope.*/ + def apply[A](implicit t: RType[A]): RType[A] = t + + /** Helper cast from untyped descriptor to the typed one. */ + @inline def asType[T](t: RType[_]): RType[T] = t.asInstanceOf[RType[T]] + + def fromClassTag[A](ctA: ClassTag[A]): RType[A] = (ctA match { + case ClassTag.Boolean => sigma.BooleanType + case ClassTag.Byte => sigma.ByteType + case ClassTag.Short => sigma.ShortType + case ClassTag.Int => sigma.IntType + case ClassTag.Long => sigma.LongType + case ClassTag.Unit => sigma.UnitType + case _ => GeneralType[A](ctA) + }).asInstanceOf[RType[A]] + + type SomeType = RType[_] + + /** Underlying type of Thunk[A] values (or by-name values of type A). */ + type ThunkData[A] = () => A + + /** Implicitly obtain the single RTypeType descriptor casted to the given type A. */ + implicit def rtypeRType[A]: RType[RType[A]] = asType[RType[A]](RTypeType) + + implicit def pairRType[A,B](implicit tA: RType[A], tB: RType[B]): RType[(A,B)] = PairType(tA, tB) + + implicit def extendPairType[A,B](pt: RType[(A,B)]): PairType[A,B] = pt.asInstanceOf[PairType[A,B]] + + implicit def funcRType[A,B](implicit tDom: RType[A], tRange: RType[B]): RType[A => B] = FuncType(tDom, tRange) + + implicit def arrayRType[A](implicit tA: RType[A]): RType[Array[A]] = ArrayType(tA) + + implicit def optionRType[A](implicit tA: RType[A]): RType[Option[A]] = OptionType(tA) + + /** Conversion to underlying descriptor class. + * Allows syntax like + * + * ```val tColl: RType[Coll[A]] = ...; tColl.tItem``` + * + * where `tItem` is a method of `CollType`, but is not defined on `RType`. + */ + implicit def downcastCollType[A](ct: RType[Coll[A]]): CollType[A] = ct.asInstanceOf[CollType[A]] + + implicit def thunkRType[A](implicit tA: RType[A]): RType[ThunkData[A]] = ThunkType(tA) + +} diff --git a/core/shared/src/main/scala/sigma/data/package.scala b/core/shared/src/main/scala/sigma/data/package.scala new file mode 100644 index 0000000000..8c34f7e9b9 --- /dev/null +++ b/core/shared/src/main/scala/sigma/data/package.scala @@ -0,0 +1,41 @@ +package sigma + +import scala.annotation.nowarn +import scala.reflect.classTag + +/** Contains cores definitions which serves as a basis for [[sigma]] package implementations. */ +package object data { + /** Shadow the implicit from sigma package so it doesn't interfere with the resolution + * of ClassTags below. + */ + @nowarn private def rtypeToClassTag = ??? + + val BigIntClassTag = classTag[BigInt] + val GroupElementClassTag = classTag[GroupElement] + val SigmaPropClassTag = classTag[SigmaProp] + val AvlTreeClassTag = classTag[AvlTree] + val BoxClassTag = classTag[Box] + val ContextClassTag = classTag[Context] + val HeaderClassTag = classTag[Header] + val PreHeaderClassTag = classTag[PreHeader] + val AnyValueClassTag = classTag[AnyValue] + val SigmaDslBuilderClassTag = classTag[SigmaDslBuilder] + val CollBuilderClassTag = classTag[CollBuilder] + + /** Immutable empty array of integers, should be used instead of allocating new empty arrays. */ + val EmptyArrayOfInt = Array.empty[Int] + + /** Immutable empty Seq[Int] backed by empty array. + * You should prefer using it instead of `Seq[Int]()` or `Seq.empty[Int]` + */ + val EmptySeqOfInt: Seq[Int] = EmptyArrayOfInt + + /** Create a new empty buffer around pre-allocated empty array. + * This method is preferred, rather that creating empty debox.Buffer directly + * because it allows to avoid allocation of the empty array. + * Note, this method allocates a new Buffer, but the underlying empty array is shared. + * This is safe because empty arrays are immutable. + */ + def emptyDBufferOfInt: debox.Buffer[Int] = debox.Buffer.unsafe(EmptyArrayOfInt) + +} diff --git a/common/shared/src/main/scala/sigmastate/kiama/kiama.scala b/core/shared/src/main/scala/sigma/kiama/kiama.scala similarity index 98% rename from common/shared/src/main/scala/sigmastate/kiama/kiama.scala rename to core/shared/src/main/scala/sigma/kiama/kiama.scala index df8518f88d..d6b69f7b6d 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/kiama.scala +++ b/core/shared/src/main/scala/sigma/kiama/kiama.scala @@ -1,4 +1,4 @@ -package sigmastate +package sigma /** * Kiama is a Scala library for language processing. It is a project of the diff --git a/common/shared/src/main/scala/sigmastate/kiama/rewriting/CallbackRewriter.scala b/core/shared/src/main/scala/sigma/kiama/rewriting/CallbackRewriter.scala similarity index 97% rename from common/shared/src/main/scala/sigmastate/kiama/rewriting/CallbackRewriter.scala rename to core/shared/src/main/scala/sigma/kiama/rewriting/CallbackRewriter.scala index 157f6f172b..c6ed0858ee 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/rewriting/CallbackRewriter.scala +++ b/core/shared/src/main/scala/sigma/kiama/rewriting/CallbackRewriter.scala @@ -8,8 +8,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama -package rewriting +package sigma.kiama.rewriting + +import sigma.kiama.{===>, ==>} /** * Strategy-based term rewriting with callbacks. Clients can register diff --git a/common/shared/src/main/scala/sigmastate/kiama/rewriting/PlusStrategy.scala b/core/shared/src/main/scala/sigma/kiama/rewriting/PlusStrategy.scala similarity index 96% rename from common/shared/src/main/scala/sigmastate/kiama/rewriting/PlusStrategy.scala rename to core/shared/src/main/scala/sigma/kiama/rewriting/PlusStrategy.scala index 26ac3ae2c5..e92f939d96 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/rewriting/PlusStrategy.scala +++ b/core/shared/src/main/scala/sigma/kiama/rewriting/PlusStrategy.scala @@ -8,7 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama.rewriting +package sigma.kiama.rewriting /** * Helper class to contain commonality of choice in non-deterministic diff --git a/common/shared/src/main/scala/sigmastate/kiama/rewriting/Rewriter.scala b/core/shared/src/main/scala/sigma/kiama/rewriting/Rewriter.scala similarity index 99% rename from common/shared/src/main/scala/sigmastate/kiama/rewriting/Rewriter.scala rename to core/shared/src/main/scala/sigma/kiama/rewriting/Rewriter.scala index 8a1711c9d7..d5e9fd2f7e 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/rewriting/Rewriter.scala +++ b/core/shared/src/main/scala/sigma/kiama/rewriting/Rewriter.scala @@ -8,10 +8,10 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama +package sigma.kiama package rewriting -import scalan.reflection.{Platform, RClass, RConstructor} +import sigma.reflection.{Platform, RClass, RConstructor} /** * Strategy-based term rewriting in the style of Stratego (http://strategoxt.org/). @@ -23,8 +23,8 @@ import scalan.reflection.{Platform, RClass, RConstructor} */ trait Rewriter { - import sigmastate.kiama.util.Comparison.same - import sigmastate.kiama.util.Collections.{CanBuildFrom, Factory, newBuilder} + import sigma.kiama.util.Comparison.same + import sigma.kiama.util.Collections.{CanBuildFrom, Factory, newBuilder} /** * Rewrite a term. Apply the strategy `s` to a term returning the result term diff --git a/common/shared/src/main/scala/sigmastate/kiama/rewriting/Strategy.scala b/core/shared/src/main/scala/sigma/kiama/rewriting/Strategy.scala similarity index 98% rename from common/shared/src/main/scala/sigmastate/kiama/rewriting/Strategy.scala rename to core/shared/src/main/scala/sigma/kiama/rewriting/Strategy.scala index faf856e8d7..a6e15fcd90 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/rewriting/Strategy.scala +++ b/core/shared/src/main/scala/sigma/kiama/rewriting/Strategy.scala @@ -8,8 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama -package rewriting +package sigma.kiama.rewriting /** * Any-rewriting strategies. A strategy is a function that takes a term diff --git a/common/shared/src/main/scala/sigmastate/kiama/util/Comparison.scala b/core/shared/src/main/scala/sigma/kiama/util/Comparison.scala similarity index 98% rename from common/shared/src/main/scala/sigmastate/kiama/util/Comparison.scala rename to core/shared/src/main/scala/sigma/kiama/util/Comparison.scala index 91d302a76a..2d45e382fd 100644 --- a/common/shared/src/main/scala/sigmastate/kiama/util/Comparison.scala +++ b/core/shared/src/main/scala/sigma/kiama/util/Comparison.scala @@ -8,8 +8,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package sigmastate.kiama -package util +package sigma.kiama.util /** * Utility module for comparison routines. diff --git a/core/shared/src/main/scala/sigma/package.scala b/core/shared/src/main/scala/sigma/package.scala new file mode 100644 index 0000000000..f7f2321096 --- /dev/null +++ b/core/shared/src/main/scala/sigma/package.scala @@ -0,0 +1,77 @@ + +import sigma.data._ +import sigma.data.RType.SomeType + +import scala.reflect.ClassTag + +/** The following implicit values are used as type descriptors of all the predefined Sigma types. + * @see [[RType]] class + */ +package object sigma { + + val AnyType: RType[Any] = GeneralType[Any](ClassTag.Any) + + implicit val BooleanType: RType[Boolean] = PrimitiveType[Boolean](ClassTag.Boolean, Array.emptyBooleanArray) + + implicit val ByteType : RType[Byte] = PrimitiveType[Byte](ClassTag.Byte, Array.emptyByteArray) + + 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) + + implicit val UnitType : RType[Unit] = PrimitiveType[Unit](ClassTag.Unit, Array[Unit]()(ClassTag.Unit)) + + implicit val StringType : RType[String] = sigma.data.StringType() + + implicit val BigIntRType: RType[BigInt] = GeneralType(BigIntClassTag) + implicit val GroupElementRType: RType[GroupElement] = GeneralType(GroupElementClassTag) + implicit val SigmaPropRType: RType[SigmaProp] = GeneralType(SigmaPropClassTag) + implicit val AvlTreeRType: RType[AvlTree] = GeneralType(AvlTreeClassTag) + + implicit val BoxRType: RType[Box] = GeneralType(BoxClassTag) + implicit val ContextRType: RType[Context] = GeneralType(ContextClassTag) + + implicit val HeaderRType: RType[Header] = GeneralType(HeaderClassTag) + implicit val PreHeaderRType: RType[PreHeader] = GeneralType(PreHeaderClassTag) + + implicit val AnyValueRType: RType[AnyValue] = RType.fromClassTag(AnyValueClassTag) + + implicit val SigmaDslBuilderRType: RType[SigmaDslBuilder] = RType.fromClassTag(SigmaDslBuilderClassTag) + + /** Implicit resolution of `Coll[A]` type descriptor, given a descriptor of `A`. */ + implicit def collRType[A](implicit tA: RType[A]): RType[Coll[A]] = CollType[A](tA) + + /** Allows implicit resolution to find appropriate instance of ClassTag in + * the scope where RType is implicitly available. + * NOTE, this implicit is shadowed internally in some places (search for `def rtypeToClassTag`), + * hence renaming it requires changing of the shadowing methods. + */ + implicit def rtypeToClassTag[A](implicit t: RType[A]): ClassTag[A] = t.classTag + + implicit val collBuilderRType: RType[CollBuilder] = RType.fromClassTag(CollBuilderClassTag) + + private def sameLengthErrorMsg[A, B](xs: Coll[A], ys: Coll[B]) = + s"Collections should have same length but was ${xs.length} and ${ys.length}:\n xs=$xs;\n ys=$ys" + + def requireSameLength[A, B](xs: Coll[A], ys: Coll[B]) = { + require(xs.length == ys.length, sameLengthErrorMsg(xs, ys)) + } + + /** Generic representation of tuples values. */ + type TupleData = Coll[Any] + + /** Returns an RType object representing a tuple type with the given SomeType array types. + * + * @param types An array of SomeType representing the types of each item in the tuple. + * @return An RType object for the tuple type. + */ + def tupleRType(types: Array[SomeType]): RType[TupleData] = TupleType(types) + + /** The primary reference to global Coll operations. Can be used to create collections from Array etc. + * + * @see CollBuilder + */ + val Colls: CollBuilder = new CollOverArrayBuilder +} \ No newline at end of file diff --git a/common/shared/src/main/scala/scalan/reflection/RClass.scala b/core/shared/src/main/scala/sigma/reflection/RClass.scala similarity index 99% rename from common/shared/src/main/scala/scalan/reflection/RClass.scala rename to core/shared/src/main/scala/sigma/reflection/RClass.scala index 32e8aeb2e3..6c843253aa 100644 --- a/common/shared/src/main/scala/scalan/reflection/RClass.scala +++ b/core/shared/src/main/scala/sigma/reflection/RClass.scala @@ -1,4 +1,4 @@ -package scalan.reflection +package sigma.reflection /** A representation of a field of a class, providing reflective access to the field's type. */ abstract class RField { diff --git a/core-lib/shared/src/main/scala/special/CoreLibReflection.scala b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala similarity index 85% rename from core-lib/shared/src/main/scala/special/CoreLibReflection.scala rename to core/shared/src/main/scala/sigma/reflection/ReflectionData.scala index 53c8d34ddf..cdab5d5be7 100644 --- a/core-lib/shared/src/main/scala/special/CoreLibReflection.scala +++ b/core/shared/src/main/scala/sigma/reflection/ReflectionData.scala @@ -1,21 +1,80 @@ -package special +package sigma.reflection -import scalan.RType -import scalan.reflection.CommonReflection.registerClassEntry -import scalan.reflection._ -import special.collection.{CollBuilder, Coll} -import special.sigma._ -import special.wrappers.{OptionWrapSpec, RTypeWrapSpec} +import sigma._ +import sigma.data.RType -/** Registrations of reflection metadata for core-lib module. +import scala.collection.compat.immutable.ArraySeq +import scala.collection.mutable +import scala.collection.immutable + +/** Reflection metadata and global dictionaries to access it. * For each class of this module that needs reflection metadata, * we register a class entry with the necessary information. * Only information that is needed at runtime is registered. */ -object CoreLibReflection { - val reflection = CommonReflection +object ReflectionData { + /** Descriptors of classes. */ + val classes = mutable.HashMap.empty[Class[_], SRClass[_]] + + /** Registers a class entry in the map of classes. + * + * @tparam T the type of the class to be registered + * @param clazz the class to be registered + * @param constructors the constructors of the class + * @param fields the fields of the class + * @param methods the methods of the class (represented as a map of method names and argument types to the corresponding RMethod instances) + */ + def registerClassEntry[T](clazz: Class[T], + constructors: Seq[SRConstructor[_]] = ArraySeq.empty, + fields: Map[String, SRField] = Map.empty, + methods: Map[(String, Seq[Class[_]]), RMethod] = Map.empty): Unit = classes.synchronized { + classes.put(clazz, new SRClass(clazz, constructors, fields, methods)) + } + + registerClassEntry(classOf[Boolean]) + + registerClassEntry(classOf[Byte]) + + registerClassEntry(classOf[Short]) + + registerClassEntry(classOf[Int]) + + registerClassEntry(classOf[Long]) + + registerClassEntry(classOf[Product2[_, _]]) + + registerClassEntry(classOf[immutable.$colon$colon[_]], + constructors = Array( + mkConstructor(Array(classOf[java.lang.Object], classOf[immutable.List[_]])) { args => + new immutable.$colon$colon(args(0).asInstanceOf[java.lang.Object], args(1).asInstanceOf[immutable.List[_]]) + } + ) + ) + + { val clazz = classOf[scala.Option[_]] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "filter", Array(classOf[scala.Function1[_,_]])) { (obj, args) => + obj.asInstanceOf[Option[Any]].filter(args(0).asInstanceOf[Any => Boolean]) + }, + mkMethod(clazz, "map", Array(classOf[scala.Function1[_,_]])) { (obj, args) => + obj.asInstanceOf[Option[Any]].map(args(0).asInstanceOf[Any => Any]) + } + ) + ) + } - { val clazz = classOf[SigmaProp] + { val clazz = classOf[scala.Some[_]] + registerClassEntry(clazz, + constructors = Array( + mkConstructor(Array(classOf[java.lang.Object])) { args => + new scala.Some(args(0).asInstanceOf[java.lang.Object]) + } + ) + ) + } + { + val clazz = classOf[SigmaProp] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "$bar$bar", Array[Class[_]](classOf[SigmaProp])) { (obj, args) => @@ -33,8 +92,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[special.sigma.BigInt] + { + val clazz = classOf[sigma.BigInt] val paramTypes = Array[Class[_]](clazz) registerClassEntry(clazz, methods = Map( @@ -62,8 +121,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[CollBuilder] + { + val clazz = classOf[CollBuilder] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "xor", Array[Class[_]](classOf[Coll[_]], classOf[Coll[_]])) { (obj, args) => @@ -82,34 +141,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[OptionWrapSpec] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "getOrElse", Array[Class[_]](classOf[Option[_]], classOf[Function0[_]])) { (obj, args) => - val opt = args(0).asInstanceOf[Option[Any]] - val defaultFunc = args(1).asInstanceOf[Function0[Any]] - obj.asInstanceOf[OptionWrapSpec].getOrElse(opt, defaultFunc()) - }, - mkMethod(clazz, "isDefined", Array[Class[_]](classOf[Option[_]])) { (obj, args) => - obj.asInstanceOf[OptionWrapSpec].isDefined(args(0).asInstanceOf[Option[_]]) - }, - mkMethod(clazz, "filter", Array[Class[_]](classOf[Option[_]], classOf[Function1[_,_]])) { (obj, args) => - obj.asInstanceOf[OptionWrapSpec].filter( - args(0).asInstanceOf[Option[Any]], args(1).asInstanceOf[Any => Boolean]) - }, - mkMethod(clazz, "map", Array[Class[_]](classOf[Option[_]], classOf[Function1[_,_]])) { (obj, args) => - obj.asInstanceOf[OptionWrapSpec].map( - args(0).asInstanceOf[Option[Any]], args(1).asInstanceOf[Any => Any]) - }, - mkMethod(clazz, "get", Array[Class[_]](classOf[Option[_]])) { (obj, args) => - obj.asInstanceOf[OptionWrapSpec].get(args(0).asInstanceOf[Option[_]]) - } - ) - ) - } - - { val clazz = classOf[Coll[_]] + { + val clazz = classOf[Coll[_]] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "updated", Array[Class[_]](classOf[Int], classOf[java.lang.Object])) { (obj, args) => @@ -134,8 +167,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[AvlTree] + { + val clazz = classOf[AvlTree] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "updateOperations", Array[Class[_]](classOf[Byte])) { (obj, args) => @@ -191,8 +224,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[Box] + { + val clazz = classOf[Box] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "value", Array[Class[_]]()) { (obj, _) => @@ -213,7 +246,7 @@ object CoreLibReflection { mkMethod(clazz, "getReg", Array[Class[_]](classOf[Int], classOf[RType[_]])) { (obj, args) => obj.asInstanceOf[Box].getReg(args(0).asInstanceOf[Int])(args(1).asInstanceOf[RType[_]]) }, - mkMethod (clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, _) => + mkMethod(clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, _) => obj.asInstanceOf[Box].bytesWithoutRef }, mkMethod(clazz, "propositionBytes", Array[Class[_]]()) { (obj, _) => @@ -222,8 +255,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[Context] + { + val clazz = classOf[Context] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "LastBlockUtxoRootHash", Array[Class[_]]()) { (obj, _) => @@ -262,8 +295,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[GroupElement] + { + val clazz = classOf[GroupElement] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "exp", Array[Class[_]](classOf[BigInt])) { (obj, args) => @@ -281,8 +314,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[Header] + { + val clazz = classOf[Header] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => @@ -333,8 +366,8 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[PreHeader] + { + val clazz = classOf[PreHeader] registerClassEntry(clazz, methods = Map( mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) => @@ -361,9 +394,9 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[SigmaDslBuilder] - val cColl = classOf[Coll[_]] + { + val clazz = classOf[SigmaDslBuilder] + val cColl = classOf[Coll[_]] val cGroupElement = classOf[GroupElement] registerClassEntry(clazz, methods = Map( @@ -430,14 +463,4 @@ object CoreLibReflection { ) ) } - - { val clazz = classOf[RTypeWrapSpec] - registerClassEntry(clazz, - methods = Map( - mkMethod(clazz, "name", Array[Class[_]](classOf[RType[_]])) { (obj, args) => - obj.asInstanceOf[RTypeWrapSpec].name(args(0).asInstanceOf[RType[_]]) - } - ) - ) - } } diff --git a/common/shared/src/main/scala/scalan/reflection/StaticImpl.scala b/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala similarity index 99% rename from common/shared/src/main/scala/scalan/reflection/StaticImpl.scala rename to core/shared/src/main/scala/sigma/reflection/StaticImpl.scala index ff6a39348e..e95eea1f59 100644 --- a/common/shared/src/main/scala/scalan/reflection/StaticImpl.scala +++ b/core/shared/src/main/scala/sigma/reflection/StaticImpl.scala @@ -1,4 +1,4 @@ -package scalan.reflection +package sigma.reflection /** * Represents a field in an Sigma Reflection metadata. diff --git a/common/shared/src/main/scala/scalan/reflection/package.scala b/core/shared/src/main/scala/sigma/reflection/package.scala similarity index 99% rename from common/shared/src/main/scala/scalan/reflection/package.scala rename to core/shared/src/main/scala/sigma/reflection/package.scala index 96a9556628..6b98056968 100644 --- a/common/shared/src/main/scala/scalan/reflection/package.scala +++ b/core/shared/src/main/scala/sigma/reflection/package.scala @@ -1,4 +1,4 @@ -package scalan +package sigma import scala.collection.mutable diff --git a/common/shared/src/main/scala/scalan/util/CollectionUtil.scala b/core/shared/src/main/scala/sigma/util/CollectionUtil.scala similarity index 93% rename from common/shared/src/main/scala/scalan/util/CollectionUtil.scala rename to core/shared/src/main/scala/sigma/util/CollectionUtil.scala index 0ee4030e2c..d6bcd69767 100644 --- a/common/shared/src/main/scala/scalan/util/CollectionUtil.scala +++ b/core/shared/src/main/scala/sigma/util/CollectionUtil.scala @@ -1,6 +1,4 @@ -package scalan.util - -import java.util +package sigma.util import scala.collection.{Seq, mutable, GenIterable} import scala.collection.mutable.{HashMap, ArrayBuffer} @@ -52,15 +50,15 @@ object CollectionUtil { * @param arr the input array for which the deep hash code is to be calculated */ def deepHashCode[T](arr: Array[T]): Int = arr match { - case arr: Array[AnyRef] => util.Arrays.deepHashCode(arr) - case arr: Array[Byte] => util.Arrays.hashCode(arr) - case arr: Array[Short] => util.Arrays.hashCode(arr) - case arr: Array[Int] => util.Arrays.hashCode(arr) - case arr: Array[Long] => util.Arrays.hashCode(arr) - case arr: Array[Char] => util.Arrays.hashCode(arr) - case arr: Array[Float] => util.Arrays.hashCode(arr) - case arr: Array[Double] => util.Arrays.hashCode(arr) - case arr: Array[Boolean] => util.Arrays.hashCode(arr) + case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr) + case arr: Array[Byte] => java.util.Arrays.hashCode(arr) + case arr: Array[Short] => java.util.Arrays.hashCode(arr) + case arr: Array[Int] => java.util.Arrays.hashCode(arr) + case arr: Array[Long] => java.util.Arrays.hashCode(arr) + case arr: Array[Char] => java.util.Arrays.hashCode(arr) + case arr: Array[Float] => java.util.Arrays.hashCode(arr) + case arr: Array[Double] => java.util.Arrays.hashCode(arr) + case arr: Array[Boolean] => java.util.Arrays.hashCode(arr) } /** Group the given sequence of pairs by first values as keys. diff --git a/common/shared/src/main/scala/scalan/util/Extensions.scala b/core/shared/src/main/scala/sigma/util/Extensions.scala similarity index 99% rename from common/shared/src/main/scala/scalan/util/Extensions.scala rename to core/shared/src/main/scala/sigma/util/Extensions.scala index 457a60a72e..1d38173e1f 100644 --- a/common/shared/src/main/scala/scalan/util/Extensions.scala +++ b/core/shared/src/main/scala/sigma/util/Extensions.scala @@ -1,4 +1,4 @@ -package scalan.util +package sigma.util import java.math.BigInteger import java.nio.ByteBuffer diff --git a/common/shared/src/main/scala/scalan/util/GraphUtil.scala b/core/shared/src/main/scala/sigma/util/GraphUtil.scala similarity index 98% rename from common/shared/src/main/scala/scalan/util/GraphUtil.scala rename to core/shared/src/main/scala/sigma/util/GraphUtil.scala index 88df8d94b4..11400b348a 100644 --- a/common/shared/src/main/scala/scalan/util/GraphUtil.scala +++ b/core/shared/src/main/scala/sigma/util/GraphUtil.scala @@ -1,6 +1,6 @@ -package scalan.util +package sigma.util -import scalan.DFunc +import sigma.data.DFunc import debox.{Set => DSet, Buffer => DBuffer} import debox.cfor import scala.reflect.ClassTag diff --git a/common/shared/src/main/scala/scalan/util/MemoizedFunc.scala b/core/shared/src/main/scala/sigma/util/MemoizedFunc.scala similarity index 94% rename from common/shared/src/main/scala/scalan/util/MemoizedFunc.scala rename to core/shared/src/main/scala/sigma/util/MemoizedFunc.scala index 48df94788a..de5e4fc56a 100644 --- a/common/shared/src/main/scala/scalan/util/MemoizedFunc.scala +++ b/core/shared/src/main/scala/sigma/util/MemoizedFunc.scala @@ -1,6 +1,6 @@ -package scalan.util +package sigma.util -import scalan.AVHashMap +import sigma.data.AVHashMap /** Transforms a given function into memoized equivalent function. * Memoization is implemented by computing function f only once for each diff --git a/common/shared/src/main/scala/scalan/util/StringUtil.scala b/core/shared/src/main/scala/sigma/util/StringUtil.scala similarity index 98% rename from common/shared/src/main/scala/scalan/util/StringUtil.scala rename to core/shared/src/main/scala/sigma/util/StringUtil.scala index 9dcf42daab..5bef3e1612 100644 --- a/common/shared/src/main/scala/scalan/util/StringUtil.scala +++ b/core/shared/src/main/scala/sigma/util/StringUtil.scala @@ -1,4 +1,4 @@ -package scalan.util +package sigma.util import debox.cfor diff --git a/common/shared/src/main/scala/sigmastate/util.scala b/core/shared/src/main/scala/sigma/util/package.scala similarity index 89% rename from common/shared/src/main/scala/sigmastate/util.scala rename to core/shared/src/main/scala/sigma/util/package.scala index e499ab9825..87b3b6a805 100644 --- a/common/shared/src/main/scala/sigmastate/util.scala +++ b/core/shared/src/main/scala/sigma/util/package.scala @@ -1,10 +1,8 @@ -package sigmastate - -import scalan.util.CollectionUtil +package sigma import scala.reflect.ClassTag -object util { +package object util { /** Maximum length of an allocatable array. */ val MaxArrayLength: Int = 100000 @@ -24,7 +22,8 @@ object util { /** Concatenate two arrays checking length limit of the resulting array. * Should be used in implementation of Coll operations of v5.0 and above. */ - final def safeConcatArrays_v5[A](arr1: Array[A], arr2: Array[A])(implicit tA: ClassTag[A]): Array[A] = { + final def safeConcatArrays_v5[A](arr1: Array[A], arr2: Array[A]) + (implicit tA: ClassTag[A]): Array[A] = { checkLength[A](arr1.length + arr2.length) CollectionUtil.concatArrays_v5(arr1, arr2) } diff --git a/common/shared/src/test/resources/root/A.txt b/core/shared/src/test/resources/root/A.txt similarity index 100% rename from common/shared/src/test/resources/root/A.txt rename to core/shared/src/test/resources/root/A.txt diff --git a/common/shared/src/test/resources/root/B.txt b/core/shared/src/test/resources/root/B.txt similarity index 100% rename from common/shared/src/test/resources/root/B.txt rename to core/shared/src/test/resources/root/B.txt diff --git a/common/shared/src/test/resources/root/subdir/C.txt b/core/shared/src/test/resources/root/subdir/C.txt similarity index 100% rename from common/shared/src/test/resources/root/subdir/C.txt rename to core/shared/src/test/resources/root/subdir/C.txt diff --git a/common/shared/src/test/resources/root/subdir/subsubdir/D.txt b/core/shared/src/test/resources/root/subdir/subsubdir/D.txt similarity index 100% rename from common/shared/src/test/resources/root/subdir/subsubdir/D.txt rename to core/shared/src/test/resources/root/subdir/subsubdir/D.txt diff --git a/common/shared/src/test/scala/scalan/BaseTests.scala b/core/shared/src/test/scala/sigma/BaseTests.scala similarity index 98% rename from common/shared/src/test/scala/scalan/BaseTests.scala rename to core/shared/src/test/scala/sigma/BaseTests.scala index e015ff948e..9ea0fcaf56 100644 --- a/common/shared/src/test/scala/scalan/BaseTests.scala +++ b/core/shared/src/test/scala/sigma/BaseTests.scala @@ -1,4 +1,4 @@ -package scalan +package sigma import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.funspec.AnyFunSpec diff --git a/core-lib/shared/src/test/scala/special/collections/CollGens.scala b/core/shared/src/test/scala/sigma/CollGens.scala similarity index 93% rename from core-lib/shared/src/test/scala/special/collections/CollGens.scala rename to core/shared/src/test/scala/sigma/CollGens.scala index 858ce9f3f4..2c8b044546 100644 --- a/core-lib/shared/src/test/scala/special/collections/CollGens.scala +++ b/core/shared/src/test/scala/sigma/CollGens.scala @@ -1,18 +1,17 @@ -package special.collections +package sigma import org.scalacheck.util.Buildable import org.scalacheck.{Arbitrary, Gen} -import scalan._ -import scalan.RType -import special.collection.{Coll, CollBuilder, CollOverArrayBuilder, PairColl} +import sigma.data.RType import spire.scalacompat.BuilderCompat + import scala.collection.mutable import scala.collection.mutable.ArrayBuffer trait CollGens { testSuite => import Gen._ - val builder: CollBuilder = new CollOverArrayBuilder + val builder: CollBuilder = sigma.Colls val valGen = choose(-100, 100) val byteGen = choose[Byte](-100, 100) val indexGen = choose(0, 100) @@ -115,8 +114,8 @@ trait CollGens { testSuite => val superGenByte = getSuperGen(1, Gen.oneOf(bytesOverArrayGen, replBytesCollGen)) val superGen = Gen.oneOf(superGenInt, superGenByte) val allGen = Gen.oneOf(superGen, collGen) - implicit val arbColl = Arbitrary(collGen) - implicit val arbBytes = Arbitrary(bytesGen) + implicit val arbColl : Arbitrary[Coll[Int]] = Arbitrary(collGen) + implicit val arbBytes: Arbitrary[Coll[Byte]] = Arbitrary(bytesGen) def eq0(x: Int) = x == 0 @@ -139,7 +138,7 @@ trait CollGens { testSuite => res } - implicit def buildableColl[T: RType] = new Buildable[T, Coll[T]] { + implicit def buildableColl[T: RType]: Buildable[T, Coll[T]] = new Buildable[T, Coll[T]] { def builder = new BuilderCompat[T, Coll[T]] { val al = new ArrayBuffer[T] diff --git a/core-lib/shared/src/test/scala/special/collections/CollsTests.scala b/core/shared/src/test/scala/sigma/CollsTests.scala similarity index 96% rename from core-lib/shared/src/test/scala/special/collections/CollsTests.scala rename to core/shared/src/test/scala/sigma/CollsTests.scala index f1fe708a7f..4886112742 100644 --- a/core-lib/shared/src/test/scala/special/collections/CollsTests.scala +++ b/core/shared/src/test/scala/sigma/CollsTests.scala @@ -1,19 +1,17 @@ -package special.collections +package sigma import org.scalacheck.Gen import org.scalatest.exceptions.TestFailedException import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks -import scalan._ -import sigmastate.{VersionContext, VersionTestingProperty} -import special.collection.{Coll, CollOverArray, PairOfCols} +import sigma.data._ -import scala.language.{existentials} +import scala.language.existentials class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers with CollGens with VersionTestingProperty { testSuite => import Gen._ - import special.collection.Extensions._ + import sigma.Extensions._ def squared[A](f: A => A): ((A, A)) => (A, A) = (p: (A, A)) => (f(p._1), f(p._2)) @@ -491,8 +489,8 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers /* TODO: simplify the above code * match-case removal gives the following compilation error: type mismatch; - found : special.collection.PairColl[_$1(in value res),_$2(in value res)] where type _$2(in value res), type _$1(in value res) - required: special.collection.Coll[(_$1(in method getSuperGen), _$2(in method getSuperGen))] + found : sigma.PairColl[_$1(in value res),_$2(in value res)] where type _$2(in value res), type _$1(in value res) + required: sigma.Coll[(_$1(in method getSuperGen), _$2(in method getSuperGen))] val res = col1.unionSet(col1) */ } @@ -511,8 +509,8 @@ class CollsTests extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers /* TODO: simplify the above code * match-case removal gives the following compilation error: type mismatch; - found : special.collection.PairColl[_$1(in value res),_$2(in value res)] where type _$2(in value res), type _$1(in value res) - required: special.collection.Coll[(_$1(in method getSuperGen), _$2(in method getSuperGen))] + found : sigma.PairColl[_$1(in value res),_$2(in value res)] where type _$2(in value res), type _$1(in value res) + required: sigma.Coll[(_$1(in method getSuperGen), _$2(in method getSuperGen))] val res = col.diff(col) */ builder.replicate(2, 10).diff(builder.replicate(1, 10)).toArray shouldBe Array(10) diff --git a/common/shared/src/test/scala/scalan/TestUtils.scala b/core/shared/src/test/scala/sigma/TestUtils.scala similarity index 89% rename from common/shared/src/test/scala/scalan/TestUtils.scala rename to core/shared/src/test/scala/sigma/TestUtils.scala index a7471b3a62..082f1d10ac 100644 --- a/common/shared/src/test/scala/scalan/TestUtils.scala +++ b/core/shared/src/test/scala/sigma/TestUtils.scala @@ -1,10 +1,10 @@ -package scalan +package sigma -import scalan.util.StringUtil import org.scalactic.TripleEquals import org.scalatest.matchers.should.Matchers -import org.scalatest.{TestSuite, Inside} -import scalan.util.StringUtil.{cleanFileName, StringUtilExtensions} +import org.scalatest.{Inside, TestSuite} +import sigma.util.StringUtil +import sigma.util.StringUtil.{StringUtilExtensions, cleanFileName} /** * Created by slesarenko on 11/10/2017. diff --git a/core-lib/shared/src/test/scala/special/TypesTests.scala b/core/shared/src/test/scala/sigma/TypesTests.scala similarity index 72% rename from core-lib/shared/src/test/scala/special/TypesTests.scala rename to core/shared/src/test/scala/sigma/TypesTests.scala index b0c6ce5808..9d946fbee4 100644 --- a/core-lib/shared/src/test/scala/special/TypesTests.scala +++ b/core/shared/src/test/scala/sigma/TypesTests.scala @@ -1,8 +1,7 @@ -package special +package sigma -import scalan.{BaseTests, RType} -import RType._ -import Types._ +import sigma.data.RType._ +import sigma.data.RType class TypesTests extends BaseTests { @@ -10,7 +9,7 @@ class TypesTests extends BaseTests { def test[A](t: RType[A], n: String) = { t.name shouldBe n } - test(tupleRType(Array(IntType, LongType, RType[(Byte, special.sigma.BigInt)], RType[Option[Boolean]])), + test(tupleRType(Array(IntType, LongType, RType[(Byte, sigma.BigInt)], RType[Option[Boolean]])), "(Int, Long, (Byte, BigInt), Option[Boolean])") } diff --git a/common/shared/src/test/scala/sigmastate/VersionTesting.scala b/core/shared/src/test/scala/sigma/VersionTesting.scala similarity index 93% rename from common/shared/src/test/scala/sigmastate/VersionTesting.scala rename to core/shared/src/test/scala/sigma/VersionTesting.scala index a92dd7bfa4..a17fc7a7f9 100644 --- a/common/shared/src/test/scala/sigmastate/VersionTesting.scala +++ b/core/shared/src/test/scala/sigma/VersionTesting.scala @@ -1,4 +1,4 @@ -package sigmastate +package sigma import debox.cfor @@ -12,7 +12,7 @@ trait VersionTesting { protected val activatedVersions: Seq[Byte] = (0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray[Byte] - private[sigmastate] val _currActivatedVersion = new DynamicVariable[Byte](2) // v5.x by default + private[sigma] val _currActivatedVersion = new DynamicVariable[Byte](2) // v5.x by default /** Current activated version used in tests. */ def activatedVersionInTests: Byte = _currActivatedVersion.value @@ -20,7 +20,7 @@ trait VersionTesting { val ergoTreeVersions: Seq[Byte] = (0 to VersionContext.MaxSupportedScriptVersion).map(_.toByte).toArray[Byte] - private[sigmastate] val _currErgoTreeVersion = new DynamicVariable[Byte](0) + private[sigma] val _currErgoTreeVersion = new DynamicVariable[Byte](0) /** Current ErgoTree version assigned dynamically. */ def ergoTreeVersionInTests: Byte = _currErgoTreeVersion.value diff --git a/common/shared/src/test/scala/sigmastate/VersionTestingProperty.scala b/core/shared/src/test/scala/sigma/VersionTestingProperty.scala similarity index 98% rename from common/shared/src/test/scala/sigmastate/VersionTestingProperty.scala rename to core/shared/src/test/scala/sigma/VersionTestingProperty.scala index bfa6cace28..2c25359a89 100644 --- a/common/shared/src/test/scala/sigmastate/VersionTestingProperty.scala +++ b/core/shared/src/test/scala/sigma/VersionTestingProperty.scala @@ -1,4 +1,4 @@ -package sigmastate +package sigma import org.scalactic.source.Position import org.scalatest.propspec.AnyPropSpec diff --git a/common/shared/src/test/scala/scalan/util/BenchmarkUtil.scala b/core/shared/src/test/scala/sigma/util/BenchmarkUtil.scala similarity index 98% rename from common/shared/src/test/scala/scalan/util/BenchmarkUtil.scala rename to core/shared/src/test/scala/sigma/util/BenchmarkUtil.scala index a06a7d859d..ce79d045c4 100644 --- a/common/shared/src/test/scala/scalan/util/BenchmarkUtil.scala +++ b/core/shared/src/test/scala/sigma/util/BenchmarkUtil.scala @@ -1,4 +1,4 @@ -package scalan.util +package sigma.util import debox.cfor diff --git a/common/shared/src/test/scala/scalan/util/CollectionUtilTests.scala b/core/shared/src/test/scala/sigma/util/CollectionUtilTests.scala similarity index 98% rename from common/shared/src/test/scala/scalan/util/CollectionUtilTests.scala rename to core/shared/src/test/scala/sigma/util/CollectionUtilTests.scala index 2b394755aa..24b03f9d88 100644 --- a/common/shared/src/test/scala/scalan/util/CollectionUtilTests.scala +++ b/core/shared/src/test/scala/sigma/util/CollectionUtilTests.scala @@ -1,12 +1,12 @@ -package scalan.util +package sigma.util -import scalan.BaseTests +import sigma.BaseTests import scala.collection.{Seq, mutable} import scala.reflect.ClassTag class CollectionUtilTests extends BaseTests { - import scalan.util.CollectionUtil._ + import sigma.util.CollectionUtil._ test("updateMany") { val xs: Seq[Byte] = Array[Byte](1,2,3) diff --git a/common/shared/src/test/scala/scalan/util/GraphUtilTests.scala b/core/shared/src/test/scala/sigma/util/GraphUtilTests.scala similarity index 95% rename from common/shared/src/test/scala/scalan/util/GraphUtilTests.scala rename to core/shared/src/test/scala/sigma/util/GraphUtilTests.scala index 213d8bc688..61fd9b5089 100644 --- a/common/shared/src/test/scala/scalan/util/GraphUtilTests.scala +++ b/core/shared/src/test/scala/sigma/util/GraphUtilTests.scala @@ -1,7 +1,8 @@ -package scalan.util +package sigma.util -import scalan.{BaseNestedTests, DFunc} +import sigma.{BaseNestedTests} import debox.{Set => DSet, Buffer => DBuffer} +import sigma.data.DFunc class GraphUtilTests extends BaseNestedTests { import GraphUtil._ diff --git a/common/shared/src/test/scala/scalan/util/PrintExtensions.scala b/core/shared/src/test/scala/sigma/util/PrintExtensions.scala similarity index 99% rename from common/shared/src/test/scala/scalan/util/PrintExtensions.scala rename to core/shared/src/test/scala/sigma/util/PrintExtensions.scala index d3b87441dd..2adc563c32 100644 --- a/common/shared/src/test/scala/scalan/util/PrintExtensions.scala +++ b/core/shared/src/test/scala/sigma/util/PrintExtensions.scala @@ -1,4 +1,4 @@ -package scalan.util +package sigma.util /** Helper methods for pretty printing of collections and optional values. */ object PrintExtensions { diff --git a/common/shared/src/test/scala/scalan/util/StringUtilTests.scala b/core/shared/src/test/scala/sigma/util/StringUtilTests.scala similarity index 79% rename from common/shared/src/test/scala/scalan/util/StringUtilTests.scala rename to core/shared/src/test/scala/sigma/util/StringUtilTests.scala index 4a2fc3b14f..12ddf792a8 100644 --- a/common/shared/src/test/scala/scalan/util/StringUtilTests.scala +++ b/core/shared/src/test/scala/sigma/util/StringUtilTests.scala @@ -1,6 +1,6 @@ -package scalan.util +package sigma.util -import scalan.BaseNestedTests +import sigma.BaseNestedTests class StringUtilTests extends BaseNestedTests { import StringUtil._ diff --git a/common/shared/src/test/scala/scalan/util/StronglyConnectedComponentsTests.scala b/core/shared/src/test/scala/sigma/util/StronglyConnectedComponentsTests.scala similarity index 58% rename from common/shared/src/test/scala/scalan/util/StronglyConnectedComponentsTests.scala rename to core/shared/src/test/scala/sigma/util/StronglyConnectedComponentsTests.scala index 2019515885..f6076d4fed 100644 --- a/common/shared/src/test/scala/scalan/util/StronglyConnectedComponentsTests.scala +++ b/core/shared/src/test/scala/sigma/util/StronglyConnectedComponentsTests.scala @@ -1,6 +1,6 @@ -package scalan.util +package sigma.util -import scalan.BaseTests +import sigma.BaseTests class StronglyConnectedComponentsTests extends BaseTests { diff --git a/interpreter/js/src/main/scala/sigmastate/Platform.scala b/interpreter/js/src/main/scala/sigmastate/Platform.scala index 98cf6a9ea3..bff11b53a8 100644 --- a/interpreter/js/src/main/scala/sigmastate/Platform.scala +++ b/interpreter/js/src/main/scala/sigmastate/Platform.scala @@ -1,12 +1,13 @@ package sigmastate import org.ergoplatform.ErgoBox -import scalan.Nullable +import sigma.data.Nullable +import sigma.VersionContext import sigmastate.Values.{Constant, FalseLeaf, SigmaBoolean, TrueLeaf} import sigmastate.eval.{Evaluation, SigmaDsl} import sigmastate.lang.SigmaBuilder -import special.collection.Coll -import special.sigma.{AnyValue, AvlTree, GroupElement, SigmaProp} +import sigma.Coll +import sigma.{AnyValue, AvlTree, GroupElement, SigmaProp} import java.math.BigInteger @@ -31,7 +32,7 @@ object Platform { 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 n: special.sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, 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)) @@ -46,7 +47,7 @@ object Platform { // this case is added in v5.0 and it can be useful when the box value comes from a // register or a context variable is passed to SubstConstants. - case b: special.sigma.Box => + case b: sigma.Box => if (VersionContext.current.isJitActivated) Nullable(mkConstant[SBox.type](b, SBox)) else diff --git a/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala b/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala index ba5460e517..fdb3b128fd 100644 --- a/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala +++ b/interpreter/js/src/main/scala/sigmastate/crypto/Platform.scala @@ -1,16 +1,15 @@ package sigmastate.crypto -import scalan.RType +import sigma.data.RType import scorex.util.encode.Base16 import sigmastate._ -import special.collection.Coll -import special.sigma._ +import sigma.Coll +import sigma._ import java.math.BigInteger import scala.scalajs.js import scala.scalajs.js.UnicodeNormalizationForm import scala.scalajs.js.typedarray.Uint8Array -import scala.util.Random /** JVM specific implementation of crypto methods (NOT yet implemented). */ object Platform { @@ -245,7 +244,7 @@ object Platform { */ def isCorrectType[T <: SType](value: Any, tpe: T): Boolean = value match { case c: Coll[_] => tpe match { - case STuple(items) => c.tItem == RType.AnyType && c.length == items.length + case STuple(items) => c.tItem == sigma.AnyType && c.length == items.length case tpeColl: SCollection[_] => true case _ => sys.error(s"Collection value $c has unexpected type $tpe") } diff --git a/interpreter/jvm/src/main/scala/sigmastate/Platform.scala b/interpreter/jvm/src/main/scala/sigmastate/Platform.scala index f094e290b8..fa44f9a16f 100644 --- a/interpreter/jvm/src/main/scala/sigmastate/Platform.scala +++ b/interpreter/jvm/src/main/scala/sigmastate/Platform.scala @@ -1,12 +1,13 @@ package sigmastate import org.ergoplatform.ErgoBox -import scalan.Nullable +import sigma.data.Nullable +import sigma.VersionContext import sigmastate.Values.{Constant, FalseLeaf, SigmaBoolean, TrueLeaf} import sigmastate.eval.{Evaluation, SigmaDsl} import sigmastate.lang.SigmaBuilder -import special.collection.Coll -import special.sigma.{AvlTree, GroupElement, SigmaProp} +import sigma.Coll +import sigma.{AvlTree, GroupElement, SigmaProp} import java.math.BigInteger @@ -31,7 +32,7 @@ object Platform { 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 n: special.sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, 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)) @@ -46,7 +47,7 @@ object Platform { // this case is added in v5.0 and it can be useful when the box value comes from a // register or a context variable is passed to SubstConstants. - case b: special.sigma.Box => + case b: sigma.Box => if (VersionContext.current.isJitActivated) Nullable(mkConstant[SBox.type](b, SBox)) else diff --git a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala index 3b74ba4714..1c5c63b197 100644 --- a/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala +++ b/interpreter/jvm/src/main/scala/sigmastate/crypto/Platform.scala @@ -5,13 +5,11 @@ import org.bouncycastle.crypto.ec.CustomNamedCurves import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator import org.bouncycastle.crypto.params.KeyParameter import org.bouncycastle.math.ec.{ECCurve, ECFieldElement, ECPoint} -import scalan.RType import java.math.BigInteger import sigmastate._ -import sigmastate.basics.BcDlogGroup -import special.collection.Coll -import special.sigma._ +import sigma.Coll +import sigma._ import java.text.Normalizer.Form.NFKD import java.text.Normalizer @@ -175,7 +173,7 @@ object Platform { */ def isCorrectType[T <: SType](value: Any, tpe: T): Boolean = value match { case c: Coll[_] => tpe match { - case STuple(items) => c.tItem == RType.AnyType && c.length == items.length + case STuple(items) => c.tItem == sigma.AnyType && c.length == items.length case _: SCollection[_] => true case _ => sys.error(s"Collection value $c has unexpected type $tpe") } diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoAddress.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoAddress.scala index 6d6371494b..5813ff99e7 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoAddress.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoAddress.scala @@ -2,15 +2,15 @@ package org.ergoplatform import scorex.utils.Ints import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix -import scorex.crypto.hash.{Digest32, Blake2b256} +import scorex.crypto.hash.{Blake2b256, Digest32} import scorex.util.encode.Base58 import sigmastate.Values._ import sigmastate._ -import sigmastate.basics.DLogProtocol.{ProveDlogProp, ProveDlog} +import sigmastate.crypto.DLogProtocol.{ProveDlog, ProveDlogProp} import sigmastate.exceptions.SigmaException import sigmastate.serialization._ import sigmastate.utxo.{DeserializeContext, Slice} -import special.collection.Coll +import sigma.Coll import scala.util.Try @@ -128,7 +128,9 @@ object P2PKAddress { } } -/** Implementation of pay-to-script-hash [[ErgoAddress]]. */ +/** Implementation of pay-to-script-hash [[ErgoAddress]]. + * @param scriptHash first 192 bits of the Blake2b256 hash of serialized script bytes + */ class Pay2SHAddress(val scriptHash: Array[Byte])(implicit val encoder: ErgoAddressEncoder) extends ErgoAddress { override val addressTypePrefix: Byte = Pay2SHAddress.addressTypePrefix @@ -141,12 +143,12 @@ class Pay2SHAddress(val scriptHash: Array[Byte])(implicit val encoder: ErgoAddre /** The proposition which checks that `contextVar(scriptId)` has original script * (whose hash equals to this [[scriptHash]]) which evaluates to true. * - * Assumes the context variable is accessed as `getVar[Coll[Byte]](1).get` + * Assumes the context variable is accessed as `getVar[Coll[Byte]](126).get` * and contains serialized original script bytes. * - * NOTE: This script is not stored in [[contentBytes]] of the address. + * NOTE: This `script` field is not stored in [[contentBytes]] of the address. * So the address doesn't depend on this script which means this specific script can be - * changed without breaking the addresses. + * changed without breaking the existing p2sh addresses. * * NOTE: The ErgoTree is created without segregation of the constants. * @@ -158,7 +160,7 @@ class Pay2SHAddress(val scriptHash: Array[Byte])(implicit val encoder: ErgoAddre override val script = { val hashEquals = EQ( Slice(CalcBlake2b256(GetVarByteArray(scriptId).get), IntConstant(0), IntConstant(24)), - scriptHash + ByteArrayConstant(scriptHash) ) val scriptIsCorrect = DeserializeContext(scriptId, SSigmaProp) ErgoTree.withoutSegregation(SigmaAnd(hashEquals.toSigmaProp, scriptIsCorrect)) @@ -176,9 +178,10 @@ class Pay2SHAddress(val scriptHash: Array[Byte])(implicit val encoder: ErgoAddre object Pay2SHAddress { /** An id of the context variable used in pay-to-script-hash address script. + * Note, value 127 is used for strage rent in Ergo node, see org.ergoplatform.wallet.interpreter.ErgoInterpreter * @see [[Pay2SHAddress.script]] */ - val scriptId = 1: Byte + val scriptId = 126: Byte /** Value added to the prefix byte in the serialized bytes of an encoded P2SH address. * @see [[ErgoAddressEncoder.toString]] @@ -300,7 +303,7 @@ case class ErgoAddressEncoder(networkPrefix: NetworkPrefix) { new P2PKAddress(ProveDlog(p), contentBytes) case Pay2SHAddress.addressTypePrefix => if (contentBytes.length != 24) { //192-bits hash used - throw new Exception(s"Improper content in P2SH script: $addrBase58Str") + throw new Exception(s"Invalid length of the hash bytes in P2SH address: $addrBase58Str") } new Pay2SHAddress(contentBytes) case Pay2SAddress.addressTypePrefix => @@ -328,7 +331,8 @@ case class ErgoAddressEncoder(networkPrefix: NetworkPrefix) { } /** Converts the given [[ErgoTree]] to the corresponding [[ErgoAddress]]. - * It is inverse of [[ErgoAddress.script]] such that `fromProposition(addr.script) == addr` + * It is inverse of [[ErgoAddress.script]] such that + * `ErgoAddressEncoder.fromProposition(addr.script) == addr` * * @return Failure(ex) if the `proposition` cannot be converted to any type of address. */ diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala index dadd0d5c7a..670d51d123 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBox.scala @@ -15,7 +15,7 @@ import sigmastate.eval._ import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{Helpers, SigmaByteReader, SigmaByteWriter} import sigmastate.utxo.ExtractCreationInfo -import special.collection._ +import sigma.{Colls, _} /** * Box (aka coin, or an unspent output) is a basic concept of a UTXO-based cryptocurrency. In Bitcoin, such an object diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala index da1fdc94fd..a167b95143 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoBoxCandidate.scala @@ -1,21 +1,20 @@ package org.ergoplatform -import java.util +import debox.cfor import org.ergoplatform.ErgoBox._ import org.ergoplatform.settings.ErgoAlgos import scorex.util.{ModifierId, bytesToId} +import sigma.Extensions.CollOps +import sigma.util.safeNewArray +import sigma.{Coll, Colls} +import sigmastate.SType.AnyOps import sigmastate.Values._ import sigmastate._ -import sigmastate.SType.AnyOps -import sigmastate.serialization.{SigmaSerializer, ValueSerializer} -import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import special.collection.Coll -import sigmastate.eval._ import sigmastate.eval.Extensions._ +import sigmastate.eval._ import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer -import sigmastate.util.safeNewArray -import debox.cfor -import special.collection.Extensions.CollOps +import sigmastate.serialization.SigmaSerializer +import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import scala.collection.{immutable, mutable} import scala.runtime.ScalaRunTime @@ -85,7 +84,7 @@ class ErgoBoxCandidate(val value: Long, override def equals(arg: Any): Boolean = { arg match { - case x: ErgoBoxCandidate => util.Arrays.equals(bytesWithNoRef, x.bytesWithNoRef) + case x: ErgoBoxCandidate => java.util.Arrays.equals(bytesWithNoRef, x.bytesWithNoRef) case _ => false } } diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeContext.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeContext.scala index 3b356fd4ec..05b5bde4e2 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeContext.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeContext.scala @@ -11,9 +11,8 @@ import sigmastate.interpreter.{ContextExtension, ErgoTreeEvaluator, Interpreter, import sigmastate.exceptions.InterpreterException import sigmastate.serialization.OpCodes import sigmastate.serialization.OpCodes.OpCode -import special.collection.Coll -import special.sigma -import special.sigma.{AnyValue, Header, PreHeader} +import sigma.Coll +import sigma.{AnyValue, Header, PreHeader} import debox.cfor /** Represents a script evaluation context to be passed to a prover and a verifier to execute and @@ -112,7 +111,7 @@ class ErgoLikeContext(val lastBlockUtxoRoot: AvlTreeData, /** Current version of the ErgoTree executed by the interpreter. * This property is used to implement version dependent operations and passed to - * interpreter via [[special.sigma.Context]]. + * interpreter via [[sigma.Context]]. * The value cannot be assigned on [[ErgoLikeContext]] construction and must be * attached using [[withErgoTreeVersion()]] method. * When the value is None, the [[InterpreterException]] is thrown by the interpreter. @@ -327,7 +326,7 @@ case object Self extends NotReadyValueBox with FixedCostValueCompanion { } } -/** When interpreted evaluates to the singleton instance of [[special.sigma.Context]]. +/** When interpreted evaluates to the singleton instance of [[sigma.Context]]. * Corresponds to `CONTEXT` variable in ErgoScript which can be used like `CONTEXT.headers`. */ case object Context extends NotReadyValue[SContext.type] with ValueCompanion { @@ -345,7 +344,7 @@ case object Context extends NotReadyValue[SContext.type] with ValueCompanion { } } -/** When interpreted evaluates to the singleton instance of [[special.sigma.SigmaDslBuilder]]. +/** When interpreted evaluates to the singleton instance of [[sigma.SigmaDslBuilder]]. * Corresponds to `Global` variable in ErgoScript which can be used like `Global.groupGenerator`. */ case object Global extends NotReadyValue[SGlobal.type] with FixedCostValueCompanion { diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeTransaction.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeTransaction.scala index f5b8a2c15f..fcfdbc922b 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeTransaction.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoLikeTransaction.scala @@ -1,17 +1,18 @@ package org.ergoplatform +import debox.cfor import org.ergoplatform.ErgoBox.TokenId import scorex.crypto.authds.ADKey import scorex.crypto.hash.Blake2b256 import scorex.util._ -import sigmastate.SType._ +import sigma.Colls +import sigma.util.safeNewArray +import sigmastate._ import sigmastate.eval.Extensions._ import sigmastate.eval._ import sigmastate.interpreter.ProverResult -import sigmastate.serialization.{SigmaSerializer, ValueSerializer} -import sigmastate.util.safeNewArray +import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import debox.cfor import scala.util.Try diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoTreePredef.scala b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoTreePredef.scala index d8fbf16b8f..8f01a46864 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/ErgoTreePredef.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/ErgoTreePredef.scala @@ -1,8 +1,8 @@ package org.ergoplatform import org.ergoplatform.settings.MonetarySettings -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.CryptoConstants import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer import sigmastate.SCollection.SByteArray import sigmastate.Values.{LongConstant, SigmaPropConstant, IntArrayConstant, TrueSigmaProp, Value, FalseSigmaProp, SigmaPropValue, IntConstant, ErgoTree} diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala b/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala index d8bd8c6d1d..e0b4830797 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/Input.scala @@ -18,7 +18,7 @@ case class DataInput(boxId: BoxId) { override def toString: String = s"DataInput(${ErgoAlgos.encode(boxId)})" override def equals(obj: Any): Boolean = obj match { - case x: DataInput => util.Arrays.equals(boxId, x.boxId) + case x: DataInput => java.util.Arrays.equals(boxId, x.boxId) case _ => false } @@ -39,7 +39,7 @@ class UnsignedInput(val boxId: BoxId, val extension: ContextExtension) { // todo check whether it is correct to compare inputs (Input use the same equals) by boxId only? override def equals(obj: Any): Boolean = obj match { - case x: UnsignedInput => util.Arrays.equals(boxId, x.boxId) + case x: UnsignedInput => java.util.Arrays.equals(boxId, x.boxId) case _ => false } diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/SigmaConstants.scala b/interpreter/shared/src/main/scala/org/ergoplatform/SigmaConstants.scala index be745d8d7d..74dc98ade9 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/SigmaConstants.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/SigmaConstants.scala @@ -1,7 +1,7 @@ package org.ergoplatform -import scalan.util.CollectionUtil.TraversableOps // used in Scala 2.11 -import sigmastate.basics.CryptoConstants +import sigma.util.CollectionUtil.TraversableOps // used in Scala 2.11 +import sigmastate.crypto.CryptoConstants /** Descriptor of a constant which represents some size value. * @tparam T type of the constant value diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/dsl/AvlTreeHelpers.scala b/interpreter/shared/src/main/scala/org/ergoplatform/dsl/AvlTreeHelpers.scala index 31eadc836c..627b0a3f54 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/dsl/AvlTreeHelpers.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/dsl/AvlTreeHelpers.scala @@ -1,11 +1,11 @@ package org.ergoplatform.dsl -import special.collection.Coll +import sigma.Coll import sigmastate.eval.{CAvlTree, CostingSigmaDslBuilder} import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash.{Digest32, Blake2b256} import sigmastate.{AvlTreeData, AvlTreeFlags} -import special.sigma.AvlTree +import sigma.AvlTree import scorex.crypto.authds.avltree.batch.{BatchAVLProver, Insert} import CostingSigmaDslBuilder.Colls diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/settings/ErgoAlgos.scala b/interpreter/shared/src/main/scala/org/ergoplatform/settings/ErgoAlgos.scala index 624e713654..e6b3141f9c 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/settings/ErgoAlgos.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/settings/ErgoAlgos.scala @@ -2,7 +2,7 @@ package org.ergoplatform.settings import scorex.crypto.hash.Blake2b256 import scorex.util._ -import special.collection.Coll +import sigma.Coll import scala.util.Try diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala b/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala index f40a916701..789016abfb 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/validation/RuleStatus.scala @@ -45,11 +45,11 @@ case class ReplacedRule(newRuleId: Short) extends RuleStatus { case class ChangedRule(newValue: Array[Byte]) extends RuleStatus { val statusCode: Byte = RuleStatus.ChangedRuleCode - override def hashCode(): Int = util.Arrays.hashCode(newValue) + override def hashCode(): Int = java.util.Arrays.hashCode(newValue) override def canEqual(that: Any): Boolean = that.isInstanceOf[ChangedRule] override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { - case that: ChangedRule => util.Arrays.equals(newValue, that.newValue) + case that: ChangedRule => java.util.Arrays.equals(newValue, that.newValue) }) } 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 667d8f4989..2c5156ccae 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/validation/SigmaValidationSettingsSerializer.scala @@ -2,7 +2,7 @@ package org.ergoplatform.validation import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import scalan.util.Extensions.{IntOps, LongOps} +import sigma.util.Extensions.IntOps import sigmastate.exceptions.SerializerException /** The rules are serialized ordered by ruleId. diff --git a/interpreter/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala b/interpreter/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala index 2573d3f592..442faed890 100644 --- a/interpreter/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala +++ b/interpreter/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala @@ -1,6 +1,6 @@ package org.ergoplatform.validation -import scalan.util.Extensions.toUByte +import sigma.util.Extensions.toUByte import sigmastate.Values.{ErgoTree, SValue} import sigmastate._ import sigmastate.exceptions.{InterpreterException, InvalidOpCode, ReaderPositionLimitExceeded, SerializerException, SigmaException} diff --git a/interpreter/shared/src/main/scala/sigmastate/AvlTreeData.scala b/interpreter/shared/src/main/scala/sigmastate/AvlTreeData.scala index 6533aa857c..83f9b756c7 100644 --- a/interpreter/shared/src/main/scala/sigmastate/AvlTreeData.scala +++ b/interpreter/shared/src/main/scala/sigmastate/AvlTreeData.scala @@ -1,10 +1,9 @@ package sigmastate -import sigmastate.basics.CryptoConstants -import sigmastate.eval.Colls +import sigmastate.crypto.CryptoConstants import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import special.collection.Coll +import sigma.{Coll, Colls} case class AvlTreeFlags(insertAllowed: Boolean, updateAllowed: Boolean, removeAllowed: Boolean) { diff --git a/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala b/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala index eab9c461b8..0bba6c0dc4 100644 --- a/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/DataValueComparer.scala @@ -1,16 +1,14 @@ package sigmastate -import scalan.{AVHashMap, Nullable, RType} +import sigma.data.{AVHashMap, CollOverArray, Nullable, PairOfCols, RType} import debox.{cfor, sp} -import scalan.RType._ import sigmastate.Values.SigmaBoolean -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.ProveDHTuple import sigmastate.eval.SigmaDsl -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.interpreter.{ErgoTreeEvaluator, NamedDesc, OperationCostInfo} -import special.sigma.{AvlTree, AvlTreeRType, BigInt, BigIntRType, Box, BoxRType, GroupElement, GroupElementRType, Header, HeaderRType, PreHeader, PreHeaderRType, SigmaProp} -import special.collection.{Coll, CollOverArray, PairOfCols} +import sigma._ /** Implementation of data equality for two arbitrary ErgoTree data types. * @see [[DataValueComparer.equalDataValues]] diff --git a/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala b/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala index cce29d51da..c6cec6c3da 100644 --- a/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala +++ b/interpreter/shared/src/main/scala/sigmastate/InterpreterReflection.scala @@ -1,21 +1,19 @@ package sigmastate import org.ergoplatform.ErgoBox.RegisterId -import scalan.reflection.CommonReflection.registerClassEntry -import scalan.reflection.{SRConstructor, mkConstructor, mkMethod, SRMethod} +import sigma.reflection.ReflectionData.registerClassEntry +import sigma.reflection.{ReflectionData, mkConstructor, mkMethod} +import sigma.Coll +import sigma.{AvlTree, SigmaDslBuilder} import sigmastate.SAvlTree.KeyValueColl -import sigmastate.SCollection.{SIntArray, SByteArray, SBooleanArray} +import sigmastate.SCollection.{SBooleanArray, SByteArray, SIntArray} import sigmastate.Values._ -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.VerifierMessage.Challenge import sigmastate.crypto.GF2_192_Poly import sigmastate.interpreter.ErgoTreeEvaluator import sigmastate.lang.Terms._ -import sigmastate.lang.{CheckingSigmaBuilder, Terms} import sigmastate.serialization.OpCodes.OpCode import sigmastate.utxo._ -import special.CoreLibReflection -import special.collection.Coll -import special.sigma.{SigmaDslBuilder, AvlTree} /** Reflection metadata for `interpreter` module. * For each class of this module that needs reflection metadata, @@ -23,7 +21,7 @@ import special.sigma.{SigmaDslBuilder, AvlTree} * Only information that is needed at runtime is registered. */ object InterpreterReflection { - val reflection = CoreLibReflection + val reflection = ReflectionData registerClassEntry(classOf[AND], constructors = Array( diff --git a/interpreter/shared/src/main/scala/sigmastate/SigSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/SigSerializer.scala index f003586d85..20341cbcc6 100644 --- a/interpreter/shared/src/main/scala/sigmastate/SigSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/SigSerializer.scala @@ -3,13 +3,13 @@ package sigmastate import sigmastate.crypto.{BigIntegers, GF2_192_Poly} import scorex.util.encode.Base16 import sigmastate.Values.SigmaBoolean -import sigmastate.basics.DLogProtocol.{ProveDlog, SecondDLogProverMessage} -import sigmastate.basics.VerifierMessage.Challenge -import sigmastate.basics.{CryptoConstants, ProveDHTuple, SecondDHTupleProverMessage} +import sigmastate.crypto.DLogProtocol.{ProveDlog, SecondDLogProverMessage} +import sigmastate.crypto.VerifierMessage.Challenge +import sigmastate.crypto.{CryptoConstants, ProveDHTuple, SecondDHTupleProverMessage} import sigmastate.interpreter.ErgoTreeEvaluator.{fixedCostOp, perItemCostOp} import sigmastate.interpreter.{ErgoTreeEvaluator, NamedDesc, OperationCostInfo} import sigmastate.serialization.SigmaSerializer -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.{Helpers, SigmaByteReader, SigmaByteWriter} import debox.cfor import sigmastate.eval.Extensions.ArrayOps diff --git a/interpreter/shared/src/main/scala/sigmastate/UncheckedTree.scala b/interpreter/shared/src/main/scala/sigmastate/UncheckedTree.scala index 4b4b28fa0d..a8b9bf4faf 100644 --- a/interpreter/shared/src/main/scala/sigmastate/UncheckedTree.scala +++ b/interpreter/shared/src/main/scala/sigmastate/UncheckedTree.scala @@ -1,9 +1,8 @@ package sigmastate -import sigmastate.basics.DLogProtocol.{FirstDLogProverMessage, ProveDlog, SecondDLogProverMessage} -import sigmastate.basics.VerifierMessage.Challenge -import sigmastate.Values.SigmaBoolean -import sigmastate.basics.{FirstDHTupleProverMessage, ProveDHTuple, SecondDHTupleProverMessage} +import sigmastate.crypto.DLogProtocol.{FirstDLogProverMessage, ProveDlog, SecondDLogProverMessage} +import sigmastate.crypto.VerifierMessage.Challenge +import sigmastate.crypto.{FirstDHTupleProverMessage, ProveDHTuple, SecondDHTupleProverMessage} import sigmastate.crypto.GF2_192_Poly sealed trait UncheckedTree extends ProofTree diff --git a/interpreter/shared/src/main/scala/sigmastate/UnprovenTree.scala b/interpreter/shared/src/main/scala/sigmastate/UnprovenTree.scala index a01c937a1f..4e45c230f2 100644 --- a/interpreter/shared/src/main/scala/sigmastate/UnprovenTree.scala +++ b/interpreter/shared/src/main/scala/sigmastate/UnprovenTree.scala @@ -2,9 +2,9 @@ package sigmastate import java.math.BigInteger import sigmastate.Values.{ErgoTree, SigmaBoolean, SigmaPropConstant} -import sigmastate.basics.DLogProtocol.{FirstDLogProverMessage, ProveDlog} -import sigmastate.basics.VerifierMessage.Challenge -import sigmastate.basics.{FirstDHTupleProverMessage, FirstProverMessage, ProveDHTuple} +import sigmastate.crypto.DLogProtocol.{FirstDLogProverMessage, ProveDlog} +import sigmastate.crypto.VerifierMessage.Challenge +import sigmastate.crypto.{FirstDHTupleProverMessage, FirstProverMessage, ProveDHTuple} import sigmastate.interpreter.{ErgoTreeEvaluator, NamedDesc, OperationCostInfo} import sigmastate.interpreter.ErgoTreeEvaluator.fixedCostOp import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer diff --git a/interpreter/shared/src/main/scala/sigmastate/Values.scala b/interpreter/shared/src/main/scala/sigmastate/Values.scala index 840df3ab56..df79471ee8 100644 --- a/interpreter/shared/src/main/scala/sigmastate/Values.scala +++ b/interpreter/shared/src/main/scala/sigmastate/Values.scala @@ -2,25 +2,25 @@ package sigmastate import java.math.BigInteger import java.util.{Arrays, Objects} -import sigmastate.kiama.rewriting.Rewriter.{count, everywherebu, strategy} +import sigma.kiama.rewriting.Rewriter.{count, everywherebu, strategy} import org.ergoplatform.settings.ErgoAlgos import org.ergoplatform.validation.ValidationException -import scalan.{Nullable, RType} -import scalan.util.CollectionUtil._ +import sigma.data.{Nullable, RType} +import sigma.util.CollectionUtil._ import sigmastate.SCollection.{SByteArray, SIntArray} -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.interpreter.{CompanionDesc, ErgoTreeEvaluator, Interpreter, NamedDesc} import sigmastate.serialization._ import sigmastate.serialization.OpCodes._ import sigmastate.TrivialProp.{FalseProp, TrueProp} import sigmastate.Values.ErgoTree.substConstants -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.{CryptoConstants, ProveDHTuple} +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{CryptoConstants, ProveDHTuple} import sigmastate.lang.Terms._ import sigmastate.utxo._ import sigmastate.eval._ import sigmastate.eval.Extensions._ -import scalan.util.Extensions.ByteOps +import sigma.util.Extensions.ByteOps import sigmastate.interpreter.ErgoTreeEvaluator._ import debox.cfor import scorex.util.encode.Base16 @@ -32,10 +32,9 @@ import sigmastate.lang.CheckingSigmaBuilder._ import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer import sigmastate.serialization.transformers.ProveDHTupleSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import special.sigma.{AvlTree, Header, PreHeader, _} +import sigma.{AvlTree, Coll, Colls, Header, PreHeader, _} import sigmastate.lang.SourceContext -import sigmastate.util.safeNewArray -import special.collection.Coll +import sigma.util.safeNewArray import scala.collection.compat.immutable.ArraySeq import scala.collection.mutable @@ -847,7 +846,7 @@ object Values { override lazy val value = { val xs = items.cast[EvaluatedValue[SAny.type]].map(_.value) - Colls.fromArray(xs.toArray(SAny.classTag.asInstanceOf[ClassTag[SAny.WrappedType]]))(RType.AnyType) + Colls.fromArray(xs.toArray(SAny.classTag.asInstanceOf[ClassTag[SAny.WrappedType]]))(sigma.AnyType) } protected final override def eval(env: DataEnv)(implicit E: ErgoTreeEvaluator): Any = { diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/BcDlogGroup.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/BcDlogGroup.scala similarity index 99% rename from interpreter/shared/src/main/scala/sigmastate/basics/BcDlogGroup.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/BcDlogGroup.scala index f4b9b4c8f3..030b333032 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/BcDlogGroup.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/BcDlogGroup.scala @@ -1,4 +1,4 @@ -package sigmastate.basics +package sigmastate.crypto import java.math.BigInteger import sigmastate.crypto.BigIntegers diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/CryptoConstants.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/CryptoConstants.scala similarity index 97% rename from interpreter/shared/src/main/scala/sigmastate/basics/CryptoConstants.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/CryptoConstants.scala index b82892291c..59525bec7e 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/CryptoConstants.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/CryptoConstants.scala @@ -1,7 +1,6 @@ -package sigmastate.basics +package sigmastate.crypto import java.math.BigInteger -import sigmastate.crypto.Ecp /** Constants used in crypto operations implementation. */ object CryptoConstants { diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/CryptoFunctions.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/CryptoFunctions.scala similarity index 95% rename from interpreter/shared/src/main/scala/sigmastate/basics/CryptoFunctions.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/CryptoFunctions.scala index 58eaa70598..ff8d395d44 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/CryptoFunctions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/CryptoFunctions.scala @@ -1,4 +1,4 @@ -package sigmastate.basics +package sigmastate.crypto import scorex.crypto.hash.Blake2b256 diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/DLogProtocol.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/DLogProtocol.scala similarity index 96% rename from interpreter/shared/src/main/scala/sigmastate/basics/DLogProtocol.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/DLogProtocol.scala index 9b801d7ad1..a078da2ceb 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/DLogProtocol.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/DLogProtocol.scala @@ -1,18 +1,17 @@ -package sigmastate.basics +package sigmastate.crypto import java.math.BigInteger -import sigmastate.crypto.BigIntegers import sigmastate.Values._ import Value.PropositionCode import scorex.util.encode.Base16 import sigmastate._ import sigmastate.eval._ -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.VerifierMessage.Challenge import CryptoConstants.{EcPointType, dlogGroup} import sigmastate.serialization.{OpCodes, GroupElementSerializer} import sigmastate.serialization.OpCodes.OpCode -import special.sigma.SigmaProp +import sigma.SigmaProp object DLogProtocol { diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/DiffieHellmanTupleProtocol.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/DiffieHellmanTupleProtocol.scala similarity index 97% rename from interpreter/shared/src/main/scala/sigmastate/basics/DiffieHellmanTupleProtocol.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/DiffieHellmanTupleProtocol.scala index e39508bf4f..a30e187105 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/DiffieHellmanTupleProtocol.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/DiffieHellmanTupleProtocol.scala @@ -1,16 +1,15 @@ -package sigmastate.basics +package sigmastate.crypto import java.math.BigInteger -import sigmastate.crypto.BigIntegers import sigmastate.Values.Value.PropositionCode import sigmastate._ -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.VerifierMessage.Challenge import sigmastate.eval.SigmaDsl import CryptoConstants.EcPointType import sigmastate.serialization.{OpCodes, GroupElementSerializer} import sigmastate.serialization.OpCodes.OpCode -import special.sigma.SigmaProp +import sigma.SigmaProp trait DiffieHellmanTupleProtocol extends SigmaProtocol[DiffieHellmanTupleProtocol] { @@ -44,7 +43,7 @@ object DiffieHellmanTupleProverInput { /** First message of Diffie Hellman tuple sigma protocol. * @param a commitment to secret randomness `a = g^r`, where `g` is default generator of the group * @param b commitment to secret randomness `b = h^r`, where `h` is another random generator of the group - * @see createRandomGenerator in [[sigmastate.basics.CryptoConstants.dlogGroup]] + * @see createRandomGenerator in [[sigmastate.crypto.CryptoConstants.dlogGroup]] */ case class FirstDHTupleProverMessage(a: EcPointType, b: EcPointType) extends FirstProverMessage { diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/DlogGroup.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/DlogGroup.scala similarity index 98% rename from interpreter/shared/src/main/scala/sigmastate/basics/DlogGroup.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/DlogGroup.scala index 07e989d119..80ab2e372d 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/DlogGroup.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/DlogGroup.scala @@ -1,7 +1,6 @@ -package sigmastate.basics +package sigmastate.crypto import java.math.BigInteger -import sigmastate.crypto.{Ecp, CryptoFacade, SecureRandom} /** This is the general interface for the discrete logarithm prime-order group. * Every class in the DlogGroup family implements this interface. diff --git a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala index 36e8343e2b..bb0ad60a84 100644 --- a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192.scala @@ -113,7 +113,7 @@ class GF2_192 extends AnyRef { } } - override def hashCode = util.Arrays.hashCode(word) + override def hashCode = java.util.Arrays.hashCode(word) /** * diff --git a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala index 344305a157..a9212fe565 100644 --- a/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/GF2_192_Poly.scala @@ -164,14 +164,14 @@ class GF2_192_Poly { def coeff0Bytes: Array[Byte] = c(0).toByteArray override def hashCode: Int = { - 31 * util.Arrays.deepHashCode(c.asInstanceOf[Array[AnyRef]]) + deg + 31 * java.util.Arrays.deepHashCode(c.asInstanceOf[Array[AnyRef]]) + deg } override def equals(obj: Any): Boolean = { if (this eq obj.asInstanceOf[AnyRef]) return true obj match { case that: GF2_192_Poly => - util.Arrays.deepEquals(c.asInstanceOf[Array[AnyRef]], that.c.asInstanceOf[Array[AnyRef]]) && + java.util.Arrays.deepEquals(c.asInstanceOf[Array[AnyRef]], that.c.asInstanceOf[Array[AnyRef]]) && deg == that.deg case _ => false } diff --git a/interpreter/shared/src/main/scala/sigmastate/basics/SigmaProtocolFunctions.scala b/interpreter/shared/src/main/scala/sigmastate/crypto/SigmaProtocolFunctions.scala similarity index 92% rename from interpreter/shared/src/main/scala/sigmastate/basics/SigmaProtocolFunctions.scala rename to interpreter/shared/src/main/scala/sigmastate/crypto/SigmaProtocolFunctions.scala index 2350c3f1d2..176edb201c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/basics/SigmaProtocolFunctions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/crypto/SigmaProtocolFunctions.scala @@ -1,10 +1,9 @@ -package sigmastate.basics +package sigmastate.crypto import sigmastate.SigmaLeaf -import sigmastate.basics.CryptoConstants.dlogGroup -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} -import sigmastate.basics.VerifierMessage.Challenge -import special.collection.Coll +import sigmastate.crypto.CryptoConstants.dlogGroup +import sigmastate.crypto.VerifierMessage.Challenge +import sigma.Coll import supertagged.TaggedType import java.math.BigInteger diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/BigIntegerOps.scala b/interpreter/shared/src/main/scala/sigmastate/eval/BigIntegerOps.scala index 90ce2bd63b..058676b0fe 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/BigIntegerOps.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/BigIntegerOps.scala @@ -1,21 +1,14 @@ package sigmastate.eval -import java.math.BigInteger - -import scalan.{ExactOrderingImpl, ExactIntegral} +import sigma.data.{ExactOrderingImpl, ExactIntegral} import scala.math.{Integral, Ordering} -import special.sigma._ +import sigma._ import sigmastate.eval.Extensions._ object OrderingOps { def apply[T](implicit ord: Ordering[T]) = ord - trait BigIntegerOrdering extends Ordering[BigInteger] { - def compare(x: BigInteger, y: BigInteger) = x.compareTo(y) - } - implicit object BigIntegerOrdering extends BigIntegerOrdering - trait BigIntOrdering extends Ordering[BigInt] { def compare(x: BigInt, y: BigInt) = x.compareTo(y) } @@ -60,7 +53,7 @@ object NumericOps { /** The instance of Integral for BigInt. * - * Note: ExactIntegral was not defined for [[special.sigma.BigInt]] in v4.x. + * Note: ExactIntegral was not defined for [[sigma.BigInt]] in v4.x. * This is because arithmetic BigInt operations were handled in a special way * (see `case op: ArithOp[t] if op.tpe == SBigInt =>` in RuntimeCosting.scala). * As result [[scalan.primitives.UnBinOps.ApplyBinOp]] nodes were not created for diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala b/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala index 72cd34b725..870cbbb5bf 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/CostingDataContext.scala @@ -1,35 +1,33 @@ package sigmastate.eval import debox.cfor -import org.ergoplatform.validation.{SigmaValidationSettings, ValidationRules} -import org.ergoplatform.{ErgoBox, SigmaConstants} -import scalan.OverloadHack.Overloaded1 -import scalan.RType -import scalan.util.Extensions.BigIntegerOps +import org.ergoplatform.validation.{ValidationRules, SigmaValidationSettings} +import org.ergoplatform.{SigmaConstants, ErgoBox} +import sigma.data.OverloadHack.Overloaded1 +import sigma.data.RType +import sigma.util.Extensions.BigIntegerOps import scorex.crypto.authds.avltree.batch._ -import scorex.crypto.authds.{ADDigest, ADKey, ADValue, SerializedAdProof} +import scorex.crypto.authds.{SerializedAdProof, ADDigest, ADValue, ADKey} import scorex.crypto.hash.{Blake2b256, Digest32, Sha256} -import scorex.utils.{Ints, Longs} +import scorex.utils.{Longs, Ints} import sigmastate.SCollection.SByteArray import sigmastate.Values.ErgoTree.EmptyConstants -import sigmastate.Values.{ConstantNode, ErgoTree, EvaluatedValue, SValue, SigmaBoolean} +import sigmastate.Values.{EvaluatedValue, SValue, ConstantNode, ErgoTree, SigmaBoolean} import sigmastate._ -import sigmastate.basics.CryptoConstants.EcPointType -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.{CryptoConstants, ProveDHTuple} -import sigmastate.crypto.{CryptoFacade, Ecp} +import sigmastate.crypto.CryptoConstants.EcPointType +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{ProveDHTuple, CryptoConstants, Ecp, CryptoFacade} import sigmastate.eval.Extensions._ import sigmastate.interpreter.Interpreter import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer import sigmastate.serialization.{GroupElementSerializer, SigmaSerializer} -import special.collection._ -import special.sigma._ +import sigma.{VersionContext, _} import java.math.BigInteger import java.util.Arrays import scala.annotation.unused import scala.reflect.ClassTag -import scala.util.{Failure, Success} +import scala.util.{Success, Failure} /** Interface implmented by wrappers to provide access to the underlying wrapped value. */ trait WrapperOf[T] { @@ -149,31 +147,42 @@ case class CSigmaProp(sigmaTree: SigmaBoolean) extends SigmaProp with WrapperOf[ override def toString: String = s"SigmaProp(${wrappedValue.showToString})" } -/** Implementation of the [[special.sigma.AvlTreeVerifier]] trait based on +/** Implements operations of AVL tree verifier based on * [[scorex.crypto.authds.avltree.batch.BatchAVLVerifier]]. * - * @see BatchAVLVerifier, AvlTreeVerifier + * @see BatchAVLVerifier */ -class CAvlTreeVerifier(startingDigest: ADDigest, +class AvlTreeVerifier private (startingDigest: ADDigest, proof: SerializedAdProof, override val keyLength: Int, override val valueLengthOpt: Option[Int]) extends BatchAVLVerifier[Digest32, Blake2b256.type]( - startingDigest, proof, keyLength, valueLengthOpt) - with AvlTreeVerifier { - override def treeHeight: Int = rootNodeHeight + startingDigest, proof, keyLength, valueLengthOpt) { + def treeHeight: Int = rootNodeHeight /** Override default logging which outputs stack trace to the console. */ override protected def logError(t: Throwable): Unit = {} } +object AvlTreeVerifier { + /** Create an instance of [[AvlTreeVerifier]] for the given tree and proof. + * Both tree and proof are immutable. + * @param tree represents a tree state to verify + * @param proof proof of tree operations leading to the state digest in the tree + * @return a new verifier instance + */ + def apply(tree: AvlTree, proof: Coll[Byte]): AvlTreeVerifier = { + val treeData = tree.asInstanceOf[CAvlTree].treeData + val adProof = SerializedAdProof @@ proof.toArray + val bv = new AvlTreeVerifier( + ADDigest @@ treeData.digest.toArray, adProof, treeData.keyLength, treeData.valueLengthOpt) + bv + } +} /** A default implementation of [[AvlTree]] interface. * @see [[AvlTree]] for detailed descriptions */ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTreeData] { - val builder = CostingSigmaDslBuilder - val Colls = builder.Colls - override def wrappedValue: AvlTreeData = treeData override def keyLength: Int = treeData.keyLength @@ -200,16 +209,9 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre this.copy(treeData = td) } - override def createVerifier(proof: Coll[Byte]): AvlTreeVerifier = { - val adProof = SerializedAdProof @@ proof.toArray - val bv = new CAvlTreeVerifier( - ADDigest @@ treeData.digest.toArray, adProof, treeData.keyLength, treeData.valueLengthOpt) - bv - } - override def contains(key: Coll[Byte], proof: Coll[Byte]): Boolean = { val keyBytes = key.toArray - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) bv.performOneOperation(Lookup(ADKey @@ keyBytes)) match { case Success(r) => r match { case Some(_) => true @@ -221,7 +223,7 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre override def get(key: Coll[Byte], proof: Coll[Byte]): Option[Coll[Byte]] = { val keyBytes = key.toArray - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) bv.performOneOperation(Lookup(ADKey @@ keyBytes)) match { case Success(r) => r match { case Some(v) => Some(Colls.fromArray(v)) @@ -232,7 +234,7 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre } override def getMany(keys: Coll[Coll[Byte]], proof: Coll[Byte]): Coll[Option[Coll[Byte]]] = { - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) keys.map { key => bv.performOneOperation(Lookup(ADKey @@ key.toArray)) match { case Success(r) => r match { @@ -248,7 +250,7 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre if (!isInsertAllowed) { None } else { - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) entries.forall { case (key, value) => val insertRes = bv.performOneOperation(Insert(ADKey @@ key.toArray, ADValue @@ value.toArray)) if (insertRes.isFailure) { @@ -267,7 +269,7 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre if (!isUpdateAllowed) { None } else { - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) operations.forall { case (key, value) => bv.performOneOperation(Update(ADKey @@ key.toArray, ADValue @@ value.toArray)).isSuccess } @@ -282,7 +284,7 @@ case class CAvlTree(treeData: AvlTreeData) extends AvlTree with WrapperOf[AvlTre if (!isRemoveAllowed) { None } else { - val bv = createVerifier(proof) + val bv = AvlTreeVerifier(this, proof) cfor(0)(_ < operations.length, _ + 1) { i => val key = operations(i).toArray bv.performOneOperation(Remove(ADKey @@ key)) @@ -493,8 +495,7 @@ object CHeader { class CostingSigmaDslBuilder extends SigmaDslBuilder { dsl => implicit val validationSettings: SigmaValidationSettings = ValidationRules.currentSettings - // manual fix - override val Colls: CollBuilder = new CollOverArrayBuilder + override val Colls: CollBuilder = sigma.Colls override def BigInt(n: BigInteger): BigInt = CBigInt(n) @@ -533,7 +534,7 @@ class CostingSigmaDslBuilder extends SigmaDslBuilder { dsl => /** Wraps the given [[ErgoBox]] into SigmaDsl value of type [[Box]]. * @param ebox the value to be wrapped - * @see [[sigmastate.SBox]], [[special.sigma.Box]] + * @see [[sigmastate.SBox]], [[sigma.Box]] */ def Box(ebox: ErgoBox): Box = CostingBox(ebox) diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala index fa8b50a6c9..8771fe2b32 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Evaluation.scala @@ -1,15 +1,14 @@ package sigmastate.eval import org.ergoplatform._ -import scalan.RType -import scalan.RType._ +import sigma.data._ +import sigma.data.RType._ import sigmastate.SType._ import sigmastate.Values.SigmaBoolean import sigmastate._ -import special.Types._ import debox.cfor import sigmastate.exceptions.CostLimitException -import java.math.BigInteger + import scala.reflect.ClassTag import scala.util.Try @@ -17,8 +16,8 @@ import scala.util.Try /** Helper methods used as part of ErgoTree evaluation. */ object Evaluation { - import special.collection._ - import special.sigma._ + import sigma._ + import sigma._ def msgCostLimitError(cost: Long, limit: Long) = s"Estimated execution cost $cost exceeds the limit $limit" @@ -99,12 +98,8 @@ object Evaluation { case StringType => SString case AnyType => SAny case UnitType => SUnit - - case BigIntegerRType => SBigInt case BigIntRType => SBigInt - case GroupElementRType => SGroupElement - case AvlTreeRType => SAvlTree case ot: OptionType[_] => sigmastate.SOption(rtypeToSType(ot.tA)) case BoxRType => SBox @@ -123,7 +118,8 @@ object Evaluation { } /** Tries to reconstruct RType of the given value. - * If not successfull returns failure. */ + * If not successfull returns failure. + * NOTE, this method is NOT used in consensus. */ def rtypeOf(value: Any): Try[RType[_]] = Try { value match { case arr if arr.getClass.isArray => val itemClass = arr.getClass.getComponentType @@ -143,19 +139,19 @@ object Evaluation { case _: Long => LongType case _: String => StringType case _: Unit => UnitType - - case _: BigInteger => BigIntegerRType - case _: special.sigma.BigInt => BigIntRType - + case _: sigma.BigInt => BigIntRType case _: GroupElement => GroupElementRType - + // TODO remove this case to allow removing of RType instances + // for ErgoBox, AvlTreeData, SigmaBoolean. + // RType describes only the types that can be put into registers, context variables and + // used as ErgoTree evaluation intermediate values. case _: ErgoBox => ErgoBoxRType case _: Box => BoxRType - case _: AvlTreeData => AvlTreeDataRType + case _: AvlTreeData => AvlTreeDataRType // TODO remove this RType case _: AvlTree => AvlTreeRType - case _: SigmaBoolean => SigmaBooleanRType + case _: SigmaBoolean => SigmaBooleanRType // TODO remove this RType case _: SigmaProp => SigmaPropRType case _: Context => ContextRType case _ => @@ -165,7 +161,7 @@ object Evaluation { /** Convert SigmaDsl representation of tuple to ErgoTree serializable representation. */ def fromDslTuple(value: Any, tupleTpe: STuple): Coll[Any] = value match { case t: Tuple2[_,_] => TupleColl(t._1, t._2) - case a: Coll[Any]@unchecked if a.tItem == RType.AnyType => a + case a: Coll[Any]@unchecked if a.tItem == sigma.AnyType => a case _ => sys.error(s"Cannot execute fromDslTuple($value, $tupleTpe)") } diff --git a/common/shared/src/main/scala/scalan/ExactIntegral.scala b/interpreter/shared/src/main/scala/sigmastate/eval/ExactIntegral.scala similarity index 97% rename from common/shared/src/main/scala/scalan/ExactIntegral.scala rename to interpreter/shared/src/main/scala/sigmastate/eval/ExactIntegral.scala index 57e6e55dd3..34e2f47f63 100644 --- a/common/shared/src/main/scala/scalan/ExactIntegral.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/ExactIntegral.scala @@ -1,6 +1,6 @@ -package scalan +package sigma.data -import scalan.util.Extensions._ +import sigma.util.Extensions.{ByteOps, ShortOps} /** Type-class which defines the operations on Integral types (Byte, Short, Int, Long, BigInt) * with overflow checks. diff --git a/common/shared/src/main/scala/scalan/ExactNumeric.scala b/interpreter/shared/src/main/scala/sigmastate/eval/ExactNumeric.scala similarity index 96% rename from common/shared/src/main/scala/scalan/ExactNumeric.scala rename to interpreter/shared/src/main/scala/sigmastate/eval/ExactNumeric.scala index 5967785de5..2e9b799a61 100644 --- a/common/shared/src/main/scala/scalan/ExactNumeric.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/ExactNumeric.scala @@ -1,6 +1,6 @@ -package scalan +package sigma.data -import scalan.ExactIntegral._ +import sigma.data.ExactIntegral._ /** Numeric operations with overflow checks. * Raise exception when overflow is detected. diff --git a/common/shared/src/main/scala/scalan/ExactOrdering.scala b/interpreter/shared/src/main/scala/sigmastate/eval/ExactOrdering.scala similarity index 98% rename from common/shared/src/main/scala/scalan/ExactOrdering.scala rename to interpreter/shared/src/main/scala/sigmastate/eval/ExactOrdering.scala index a727233588..7c65b53075 100644 --- a/common/shared/src/main/scala/scalan/ExactOrdering.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/ExactOrdering.scala @@ -1,4 +1,4 @@ -package scalan +package sigma.data import scala.math.Numeric.{ByteIsIntegral, LongIsIntegral, ShortIsIntegral, IntIsIntegral} diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala index b4efc58348..c7cac60d81 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala @@ -3,7 +3,7 @@ package sigmastate.eval import debox.{cfor, Buffer => DBuffer} import org.ergoplatform.ErgoBox import org.ergoplatform.ErgoBox.TokenId -import scalan.{Nullable, RType} +import sigma.data.{Nullable, RType} import scorex.util.encode.Base16 import sigmastate.SType.AnyOps import sigmastate.Values.{Constant, ConstantNode} @@ -11,13 +11,12 @@ import sigmastate.crypto.{CryptoFacade, Ecp} import sigmastate.lang.{CheckingSigmaBuilder, TransformingSigmaBuilder} import sigmastate.utils.Helpers import sigmastate.{Platform, SCollection, SCollectionType, SType} -import special.collection.Coll -import special.sigma._ +import sigma.Coll +import sigma._ import java.math.BigInteger object Extensions { - private val Colls = CostingSigmaDslBuilder.Colls implicit class ByteExt(val b: Byte) extends AnyVal { @inline def toBigInt: BigInt = CostingSigmaDslBuilder.BigInt(BigInteger.valueOf(b.toLong)) diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Profiler.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Profiler.scala index 74e187b809..80266c9063 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Profiler.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Profiler.scala @@ -5,7 +5,7 @@ import sigmastate.Values.SValue import sigmastate.serialization.{OpCodes, ValueSerializer} import sigmastate.serialization.OpCodes.OpCode import sigmastate.serialization.ValueSerializer.getSerializer -import scalan.util.Extensions.ByteOps +import sigma.util.Extensions.ByteOps import debox.{Buffer => DBuffer, Map => DMap} import debox.sp import sigmastate.eval.Extensions.DBufferOps diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/package.scala b/interpreter/shared/src/main/scala/sigmastate/eval/package.scala index cb4ebb9c05..12b73de5f6 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/package.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/package.scala @@ -3,12 +3,12 @@ package sigmastate import java.math.BigInteger import org.ergoplatform.ErgoBox -import scalan.RType +import sigma.data.RType import scorex.crypto.hash.Digest32 import sigmastate.Values.SigmaBoolean -import sigmastate.basics.CryptoConstants.EcPointType -import special.collection.{Coll, CollBuilder} -import special.sigma._ +import sigmastate.crypto.CryptoConstants.EcPointType +import sigma.{Coll, CollBuilder} +import sigma._ import supertagged.TaggedType import scala.language.implicitConversions @@ -22,16 +22,11 @@ package object eval { */ val SigmaDsl = CostingSigmaDslBuilder - /** The primary reference to global Coll operations. Can be used to create collections from Array etc. - * @see CollBuilder - */ - val Colls: CollBuilder = SigmaDsl.Colls - /** Constructor of tuple value with more than 2 items. * Such long tuples are represented as Coll[Any]. * This representaion of tuples is different from representation of pairs (x, y), * where Tuple2 type is used instead of Coll. */ - def TupleColl(items: Any*): Coll[Any] = Colls.fromItems(items:_*)(RType.AnyType) + def TupleColl(items: Any*): Coll[Any] = Colls.fromItems(items:_*)(sigma.AnyType) trait BaseDigestColl extends TaggedType[Coll[Byte]] @@ -39,11 +34,10 @@ package object eval { type Digest32Coll = Digest32Coll.Type implicit val Digest32CollRType: RType[Digest32Coll] = RType[Coll[Byte]].asInstanceOf[RType[Digest32Coll] ] - implicit val Digest32RType: RType[Digest32] = RType[Array[Byte]].asInstanceOf[RType[Digest32] ] /** Implicit conversions between Dsl type and the type wrapped by the corresponding type Dsl type. * Here BigInt is Dsl type and BigInteger is wrapped type. - * @see `special.sigma.CBigInt` + * @see `sigma.CBigInt` */ implicit def bigIntegerToBigInt(bi: BigInteger): BigInt = SigmaDsl.BigInt(bi) implicit def bigIntToBigInteger(bi: BigInt): BigInteger = SigmaDsl.toBigInteger(bi) diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ErgoTreeEvaluator.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ErgoTreeEvaluator.scala index de6ad39789..e1bcd3119c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ErgoTreeEvaluator.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ErgoTreeEvaluator.scala @@ -1,17 +1,17 @@ package sigmastate.interpreter import org.ergoplatform.ErgoLikeContext -import sigmastate.{PerItemCost, VersionContext, TypeBasedCost, FixedCost, SType, JitCost} +import sigmastate.{FixedCost, JitCost, PerItemCost, SType, TypeBasedCost} import sigmastate.Values._ import sigmastate.eval.Profiler import sigmastate.interpreter.ErgoTreeEvaluator.DataEnv import sigmastate.interpreter.Interpreter.ReductionResult -import special.sigma.{Context, SigmaProp} -import scalan.util.Extensions._ +import sigma.{Context, SigmaProp} +import sigma.util.Extensions._ import sigmastate.interpreter.EvalSettings._ import supertagged.TaggedType import debox.{Buffer => DBuffer} - +import sigma.VersionContext import scala.collection.compat.immutable.ArraySeq import scala.util.DynamicVariable @@ -103,8 +103,8 @@ case class JitEvalResult[A](value: A, cost: JitCost) * transaction. No additional transformation is performed. * ErgoTree is interpreted directly and all the intermediate data is stored in the * runtime types. - * The runtime types are such types as [[special.collection.Coll]], - * [[special.sigma.SigmaProp]], [[special.sigma.AvlTree]], [[BigInt]], etc. + * The runtime types are such types as [[sigma.Coll]], + * [[sigma.SigmaProp]], [[sigma.AvlTree]], [[BigInt]], etc. * It also use immutable Map to keep current [[DataEnv]] of computed [[ValDef]]s, as * result only addition is used from the map, and deletion is essentially a garbage * collection. @@ -500,7 +500,7 @@ object ErgoTreeEvaluator { /** Evaluate the given expression in the given Ergo context using the given settings. * The given Value is evaluated as-is and is not changed during evaluation. * - * @param sigmaContext [[special.sigma.Context]] instance used for script execution + * @param sigmaContext [[sigma.Context]] instance used for script execution * @param costAccumulator [[CostAccumulator]] instance used for accumulating costs * @param constants collection of segregated constants which can be refered by * [[ConstantPlaceholder]]s in `exp` diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Hint.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Hint.scala index ab2530f653..2e894502f4 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Hint.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Hint.scala @@ -3,8 +3,8 @@ package sigmastate.interpreter import java.math.BigInteger import sigmastate.{NodePosition, SigmaLeaf, UncheckedTree} import sigmastate.Values.SigmaBoolean -import sigmastate.basics.FirstProverMessage -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.FirstProverMessage +import sigmastate.crypto.VerifierMessage.Challenge /** * A hint for a prover which helps the prover to prove a statement. For example, if the statement is "pk1 && pk2", diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala index e606e72525..cb519e12ae 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala @@ -1,16 +1,15 @@ package sigmastate.interpreter import java.util -import sigmastate.kiama.rewriting.Rewriter.{everywherebu, rule, strategy} -import sigmastate.kiama.rewriting.Strategy +import sigma.kiama.rewriting.Rewriter.{everywherebu, rule, strategy} import org.ergoplatform.ErgoLikeContext import org.ergoplatform.validation.SigmaValidationSettings import org.ergoplatform.validation.ValidationRules._ -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.SCollection.SByteArray import sigmastate.Values._ -import sigmastate.basics.DLogProtocol.{ProveDlog, DLogInteractiveProver, FirstDLogProverMessage} -import sigmastate.basics._ +import sigmastate.crypto.DLogProtocol.{DLogInteractiveProver, FirstDLogProverMessage, ProveDlog} +import sigmastate.crypto._ import sigmastate.interpreter.Interpreter._ import sigmastate.serialization.{SigmaSerializer, ValueSerializer} import sigmastate.utxo.DeserializeContext @@ -23,7 +22,10 @@ import sigmastate.interpreter.ErgoTreeEvaluator.fixedCostOp import sigmastate.utils.Helpers._ import sigmastate.lang.Terms.ValueOps import debox.cfor +import sigma.VersionContext +import sigma.kiama.rewriting.Strategy import sigmastate.exceptions.{CostLimitException, InterpreterException} + import scala.util.{Success, Try} /** Base (verifying) interpreter of ErgoTrees. @@ -169,7 +171,7 @@ trait Interpreter { val (resProp, cost) = { val ctx = context.asInstanceOf[ErgoLikeContext] ErgoTreeEvaluator.eval(ctx, ErgoTree.EmptyConstants, exp, evalSettings) match { - case (p: special.sigma.SigmaProp, c) => (p, c) + case (p: sigma.SigmaProp, c) => (p, c) case (res, _) => sys.error(s"Invalid result type of $res: expected SigmaProp when evaluating $exp") } @@ -383,7 +385,7 @@ trait Interpreter { * (and, if applicable, the associated data). Reject otherwise. */ val expectedChallenge = CryptoFunctions.hashFn(bytes) - util.Arrays.equals(newRoot.challenge.toArray, expectedChallenge) + java.util.Arrays.equals(newRoot.challenge.toArray, expectedChallenge) } /** diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/InterpreterContext.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/InterpreterContext.scala index 937aa37fda..017af3ff9b 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/InterpreterContext.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/InterpreterContext.scala @@ -6,8 +6,7 @@ import sigmastate.Values.EvaluatedValue import sigmastate.interpreter.ContextExtension.VarBinding import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import special.sigma -import special.sigma.AnyValue +import sigma.AnyValue import scala.collection.mutable @@ -109,8 +108,8 @@ trait InterpreterContext { /** Creates a new instance with given validation settings. */ def withValidationSettings(newVs: SigmaValidationSettings): InterpreterContext - /** Creates `special.sigma.Context` instance based on this context. The created instance - * contains all data represented using types form [[special.sigma]] package. + /** Creates `sigma.Context` instance based on this context. The created instance + * contains all data represented using types form [[sigma]] package. * These types are used internally by ErgoTree interpreter. * Thus, this method performs transformation from Ergo to internal Sigma representation * of all context data. diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala index e9dfa6b052..2953e8ed0c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverInterpreter.scala @@ -1,20 +1,21 @@ package sigmastate.interpreter -import sigmastate.kiama.rewriting.Rewriter.{everywherebu, everywheretd, rule} -import sigmastate.kiama.rewriting.Strategy -import scalan.util.CollectionUtil._ +import sigma.kiama.rewriting.Rewriter.{everywherebu, everywheretd, rule} +import sigma.util.CollectionUtil._ +import sigma.VersionContext +import sigma.kiama.rewriting.Strategy import sigmastate.TrivialProp.{FalseProp, TrueProp} import sigmastate.Values._ -import sigmastate.VersionContext.MaxSupportedScriptVersion +import sigma.VersionContext.MaxSupportedScriptVersion import sigmastate._ -import sigmastate.basics.DLogProtocol._ -import sigmastate.basics.VerifierMessage.Challenge -import sigmastate.basics._ +import sigmastate.crypto.DLogProtocol._ +import sigmastate.crypto.VerifierMessage.Challenge +import sigmastate.crypto._ import sigmastate.crypto.{GF2_192, GF2_192_Poly} import sigmastate.eval.Extensions.ArrayOps import sigmastate.exceptions.InterpreterException import sigmastate.utils.Helpers -import special.collection.Coll +import sigma.Coll import java.math.BigInteger import scala.util.Try diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala index a6824a1570..45d6159d8c 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverResult.scala @@ -13,12 +13,12 @@ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} * @param extension - user-defined variables to be put into context */ class ProverResult(val proof: Array[Byte], val extension: ContextExtension) { - override def hashCode(): Int = util.Arrays.hashCode(proof) * 31 + extension.hashCode() + override def hashCode(): Int = java.util.Arrays.hashCode(proof) * 31 + extension.hashCode() override def equals(obj: scala.Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case obj: ProverResult => - util.Arrays.equals(proof, obj.proof) && extension == obj.extension + java.util.Arrays.equals(proof, obj.proof) && extension == obj.extension case _ => false }) diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverUtils.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverUtils.scala index e2b0fe8f5a..0e66cb55c5 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverUtils.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/ProverUtils.scala @@ -2,9 +2,8 @@ package sigmastate.interpreter import sigmastate._ import sigmastate.Values.{ErgoTree, SigmaBoolean} -import sigmastate.basics.DLogProtocol.{DLogInteractiveProver, ProveDlog} -import sigmastate.basics.{DiffieHellmanTupleInteractiveProver, ProveDHTuple} -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.DLogProtocol.{DLogInteractiveProver, ProveDlog} +import sigmastate.crypto.{DiffieHellmanTupleInteractiveProver, ProveDHTuple} trait ProverUtils extends Interpreter { diff --git a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala index 55d1575ff9..8d87d8ffce 100644 --- a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala +++ b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaBuilder.scala @@ -2,7 +2,8 @@ package sigmastate.lang import debox.cfor import org.ergoplatform.ErgoBox.RegisterId -import scalan.Nullable +import sigma.data.Nullable +import sigma.{AnyValue, Coll, Colls, Environment} import sigmastate.SCollection.{SByteArray, SIntArray} import sigmastate.SOption.SIntOption import sigmastate.Values._ @@ -14,8 +15,6 @@ import sigmastate.lang.Terms.{STypeSubst, _} import sigmastate.serialization.OpCodes import sigmastate.serialization.OpCodes.OpCode import sigmastate.utxo._ -import special.collection.Coll -import special.sigma.AnyValue import scala.util.DynamicVariable diff --git a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaPredef.scala b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaPredef.scala index 7c958918e5..5b1d3dc2ca 100644 --- a/interpreter/shared/src/main/scala/sigmastate/lang/SigmaPredef.scala +++ b/interpreter/shared/src/main/scala/sigmastate/lang/SigmaPredef.scala @@ -2,7 +2,7 @@ package sigmastate.lang import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix import org.ergoplatform.{ErgoAddressEncoder, P2PKAddress} -import scalan.Nullable +import sigma.data.Nullable import scorex.util.encode.{Base64, Base58, Base16} import sigmastate.SCollection.{SIntArray, SByteArray} import sigmastate.SOption._ diff --git a/interpreter/shared/src/main/scala/sigmastate/lang/Terms.scala b/interpreter/shared/src/main/scala/sigmastate/lang/Terms.scala index 4cc8dea0d6..bbb19434bf 100644 --- a/interpreter/shared/src/main/scala/sigmastate/lang/Terms.scala +++ b/interpreter/shared/src/main/scala/sigmastate/lang/Terms.scala @@ -1,7 +1,7 @@ package sigmastate.lang -import sigmastate.kiama.rewriting.Rewriter._ -import scalan.Nullable +import sigma.kiama.rewriting.Rewriter._ +import sigma.data.Nullable import sigmastate.SCollection.{SIntArray, SByteArray} import sigmastate.Values._ import sigmastate.utils.Overloading.Overload1 diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/BlockValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/BlockValueSerializer.scala index 522a1310e4..6e4056e275 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/BlockValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/BlockValueSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.Values._ import sigmastate._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import ValueSerializer._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, U, Vlq} import debox.cfor diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionBooleanConstantSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionBooleanConstantSerializer.scala index c3a2af686d..0419fd6e04 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionBooleanConstantSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionBooleanConstantSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.{SCollection, SBoolean, ArgInfo} import sigmastate.Values._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import SigmaByteWriter._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import debox.cfor case class ConcreteCollectionBooleanConstantSerializer(cons: (IndexedSeq[Value[SBoolean.type]], SBoolean.type) => Value[SCollection[SBoolean.type]]) diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionSerializer.scala index bcbbfe8305..c11452dde8 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ConcreteCollectionSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.{SCollection, ArgInfo, SType} import sigmastate.Values._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import ValueSerializer._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, U, Vlq} import debox.cfor diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala index f38fd97309..65fb2cc0c7 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/DataSerializer.scala @@ -5,13 +5,12 @@ import java.nio.charset.StandardCharsets import org.ergoplatform.ErgoBox import org.ergoplatform.validation.ValidationRules.CheckSerializableTypeCode -import scalan.RType +import sigma.data.RType import sigmastate.Values.SigmaBoolean import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate._ import sigmastate.eval.{Evaluation, _} -import special.collection._ -import special.sigma._ +import sigma._ import debox.cfor import sigmastate.exceptions.SerializerException import scala.collection.mutable @@ -126,7 +125,7 @@ object DataSerializer { val arr = tuple.items.map { t => deserialize(t, r) }.toArray[Any] - val coll = Colls.fromArray(arr)(RType.AnyType) + val coll = Colls.fromArray(arr)(sigma.AnyType) Evaluation.toDslTuple(coll, tuple) case t => CheckSerializableTypeCode(t.typeCode) @@ -147,7 +146,7 @@ object DataSerializer { case tTup: STuple if tTup.items.length == 2 => Evaluation.stypeToRType(tpeElem) case _: STuple => - collRType(RType.AnyType) + collRType(sigma.AnyType) case _ => Evaluation.stypeToRType(tpeElem) }).asInstanceOf[RType[T#WrappedType]] diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala index dd3c9f7d13..f8c5221945 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ErgoTreeSerializer.scala @@ -2,15 +2,16 @@ package sigmastate.serialization import org.ergoplatform.validation.ValidationRules.{CheckDeserializedScriptIsSigmaProp, CheckHeaderSizeBit, CheckPositionLimit} import org.ergoplatform.validation.{SigmaValidationSettings, ValidationException} -import sigmastate.{SType, VersionContext} +import sigmastate.{SType} import sigmastate.Values.{Constant, ErgoTree, UnparsedErgoTree} import sigmastate.lang.DeserializationSigmaBuilder import sigmastate.lang.Terms.ValueOps import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.Values.ErgoTree.EmptyConstants -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utxo.ComplexityTable import debox.cfor +import sigma.VersionContext import sigmastate.exceptions.{SerializerException, ReaderPositionLimitExceeded} import java.util @@ -274,7 +275,7 @@ class ErgoTreeSerializer { // allocate array of back references: forall i: positionsBackref(i) is index in `positions` val positionsBackref = safeNewArray[Int](positionsRange) // mark all positions are not assigned - util.Arrays.fill(positionsBackref, -1) + java.util.Arrays.fill(positionsBackref, -1) cfor(0)(_ < positions.length, _ + 1) { iPos => val pos = positions(iPos) diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/FuncValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/FuncValueSerializer.scala index c7ab6208e9..d9f9ea752d 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/FuncValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/FuncValueSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.Values._ import sigmastate._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import ValueSerializer._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, U, Vlq} import debox.cfor diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/GroupElementSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/GroupElementSerializer.scala index f54606082f..e54c41e426 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/GroupElementSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/GroupElementSerializer.scala @@ -1,9 +1,9 @@ package sigmastate.serialization -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.crypto.CryptoFacade import CryptoConstants.EcPointType -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} /** diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/MethodCallSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/MethodCallSerializer.scala index 8167790492..e474d8a7c2 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/MethodCallSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/MethodCallSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.Values._ import sigmastate._ import sigmastate.lang.Terms.STypeSubst import sigmastate.lang.Terms.MethodCall -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, valuesItemInfo} import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.utxo.ComplexityTable diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ProveDlogSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ProveDlogSerializer.scala index edf7b175f4..89400938fe 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ProveDlogSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ProveDlogSerializer.scala @@ -1,9 +1,9 @@ package sigmastate.serialization -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.{SGroupElement, CreateProveDlog} import sigmastate.Values.{Value, SValue, SigmaPropValue} -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.lang.Terms._ import sigmastate.utils.SigmaByteWriter.DataInfo import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/TupleSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/TupleSerializer.scala index c400630e6d..a88a17fa5f 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/TupleSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/TupleSerializer.scala @@ -4,7 +4,7 @@ import sigmastate.{SType, ArgInfo} import sigmastate.Values._ import sigmastate.utils.{SigmaByteWriter, SigmaByteReader} import sigmastate.serialization.ValueSerializer._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, U} import debox.cfor diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/TypeSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/TypeSerializer.scala index 3d0f44007e..4dc9335ff3 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/TypeSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/TypeSerializer.scala @@ -3,7 +3,7 @@ package sigmastate.serialization import java.nio.charset.StandardCharsets import org.ergoplatform.validation.ValidationRules.{CheckPrimitiveTypeCode, CheckTypeCode} import sigmastate._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import debox.cfor import sigmastate.exceptions.InvalidTypePrefix diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ValDefSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ValDefSerializer.scala index e2086a0381..cdac6309f8 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ValDefSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ValDefSerializer.scala @@ -6,7 +6,7 @@ import sigmastate.serialization.OpCodes._ import scorex.util.Extensions._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import ValueSerializer._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import debox.cfor case class ValDefSerializer(override val opDesc: ValueCompanion) extends ValueSerializer[ValDef] { diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala index ca5a60926c..056da7587b 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/ValueSerializer.scala @@ -2,14 +2,14 @@ package sigmastate.serialization import org.ergoplatform.validation.ValidationRules.CheckValidOpCode import org.ergoplatform._ +import sigma.util.Extensions.toUByte import sigmastate.SCollection.SByteArray import sigmastate.Values._ import sigmastate._ import sigmastate.lang.DeserializationSigmaBuilder import sigmastate.serialization.OpCodes._ import sigmastate.serialization.transformers._ -import sigmastate.serialization.trees.{Relation2Serializer, QuadrupleSerializer} -import scalan.util.Extensions._ +import sigmastate.serialization.trees.{QuadrupleSerializer, Relation2Serializer} import sigmastate.utils.SigmaByteWriter.DataInfo import sigmastate.utils._ import sigmastate.utxo.ComplexityTable._ diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/ProveDHTupleSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/ProveDHTupleSerializer.scala index b25d13d8de..39406a35c0 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/ProveDHTupleSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/ProveDHTupleSerializer.scala @@ -2,8 +2,8 @@ package sigmastate.serialization.transformers import sigmastate.{SGroupElement, CreateProveDHTuple} import sigmastate.Values.{Value, SigmaPropValue} -import sigmastate.basics.ProveDHTuple -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.ProveDHTuple +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.lang.Terms._ import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.serialization._ diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/SigmaTransformerSerializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/SigmaTransformerSerializer.scala index 9cce78c64b..e7981bb725 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/SigmaTransformerSerializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/transformers/SigmaTransformerSerializer.scala @@ -3,7 +3,7 @@ package sigmastate.serialization.transformers import sigmastate.{SigmaTransformerCompanion, SigmaTransformer} import sigmastate.Values.{SigmaPropValue, SValue} import sigmastate.serialization.ValueSerializer -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.SigmaByteWriter.{DataInfo, valuesItemInfo} import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import debox.cfor diff --git a/interpreter/shared/src/main/scala/sigmastate/serialization/trees/Relation2Serializer.scala b/interpreter/shared/src/main/scala/sigmastate/serialization/trees/Relation2Serializer.scala index 23f6fcb6d4..655fa8f2d2 100644 --- a/interpreter/shared/src/main/scala/sigmastate/serialization/trees/Relation2Serializer.scala +++ b/interpreter/shared/src/main/scala/sigmastate/serialization/trees/Relation2Serializer.scala @@ -6,7 +6,7 @@ import sigmastate.serialization.OpCodes._ import sigmastate.serialization.ValueSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import sigmastate.serialization.ValueSerializer._ -import scalan.util.Extensions._ +import sigma.util.Extensions._ case class Relation2Serializer[S1 <: SType, S2 <: SType, R <: Value[SBoolean.type]] (override val opDesc: RelationCompanion, diff --git a/interpreter/shared/src/main/scala/sigmastate/sigmastate.scala b/interpreter/shared/src/main/scala/sigmastate/sigmastate.scala index 96d11e8a2e..185fbebb9d 100644 --- a/interpreter/shared/src/main/scala/sigmastate/sigmastate.scala +++ b/interpreter/shared/src/main/scala/sigmastate/sigmastate.scala @@ -1,9 +1,31 @@ +import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, ErgoLikeContext} +import sigma.data.{RType, GeneralType} import sigmastate.Values._ import sigmastate.lang.CheckingSigmaBuilder +import scala.annotation.nowarn +import scala.reflect.classTag + package object sigmastate { import CheckingSigmaBuilder._ + /** Shadow the implicit from sigma package so it doesn't interfere with the resolution + * of ClassTags below. + */ + @nowarn private def rtypeToClassTag = ??? + + /** RType descriptors for predefined types used in AOTC-based interpreter. */ + + implicit val SigmaBooleanRType : RType[SigmaBoolean] = RType.fromClassTag(classTag[SigmaBoolean]) + + implicit val ErgoBoxRType : RType[ErgoBox] = RType.fromClassTag(classTag[ErgoBox]) + + implicit val ErgoBoxCandidateRType: RType[ErgoBoxCandidate] = RType.fromClassTag(classTag[ErgoBoxCandidate]) + + implicit val AvlTreeDataRType : RType[AvlTreeData] = GeneralType(classTag[AvlTreeData]) + + implicit val ErgoLikeContextRType : RType[ErgoLikeContext] = RType.fromClassTag(classTag[ErgoLikeContext]) + /** Helper method to create "+" operation node. */ def Plus[T <: SNumericType](left: Value[T], right: Value[T]): Value[T] = mkPlus(left, right) diff --git a/interpreter/shared/src/main/scala/sigmastate/trees.scala b/interpreter/shared/src/main/scala/sigmastate/trees.scala index 254aa7c317..2346ccd9e6 100644 --- a/interpreter/shared/src/main/scala/sigmastate/trees.scala +++ b/interpreter/shared/src/main/scala/sigmastate/trees.scala @@ -3,11 +3,12 @@ package sigmastate import debox.{cfor, Map => DMap} import org.ergoplatform.SigmaConstants import org.ergoplatform.validation.SigmaValidationSettings -import scalan.ExactIntegral._ -import scalan.ExactOrdering._ -import scalan.OverloadHack.Overloaded1 -import scalan.{ExactIntegral, ExactOrdering} +import sigma.data.ExactIntegral._ +import sigma.data.ExactOrdering._ +import sigma.data.OverloadHack.Overloaded1 +import sigma.data.{ExactIntegral, ExactOrdering} import scorex.crypto.hash.{Blake2b256, CryptographicHash32, Sha256} +import sigma.{Coll, Colls, GroupElement, SigmaProp, VersionContext} import sigmastate.ArithOp.OperationImpl import sigmastate.Operations._ import sigmastate.SCollection.{SByteArray, SIntArray} @@ -15,14 +16,12 @@ import sigmastate.SOption.SIntOption import sigmastate.Values._ import sigmastate.eval.Extensions.EvalCollOps import sigmastate.eval.NumericOps.{BigIntIsExactIntegral, BigIntIsExactOrdering} -import sigmastate.eval.{Colls, SigmaDsl} +import sigmastate.eval.SigmaDsl import sigmastate.interpreter.ErgoTreeEvaluator import sigmastate.interpreter.ErgoTreeEvaluator.DataEnv import sigmastate.serialization.OpCodes._ import sigmastate.serialization._ import sigmastate.utxo.{SimpleTransformerCompanion, Transformer} -import special.collection.Coll -import special.sigma.{GroupElement, SigmaProp} import scala.collection.mutable import scala.collection.mutable.ArrayBuffer @@ -36,7 +35,7 @@ trait SigmaConjecture extends SigmaBoolean { /** * Basic trait for leafs of crypto-trees, such as - * [[sigmastate.basics.DLogProtocol.ProveDlog]] and [[sigmastate.basics.ProveDHTuple]] + * [[sigmastate.crypto.DLogProtocol.ProveDlog]] and [[sigmastate.crypto.ProveDHTuple]] * instances. * It plays the same role as [[SigmaConjecture]]. It used in prover to distinguish leafs from * other nodes and have logic common to leaves regardless of the concrete leaf type. @@ -1176,7 +1175,7 @@ case class Exponentiate(override val left: Value[SGroupElement.type], protected final override def eval(env: DataEnv)(implicit E: ErgoTreeEvaluator): Any = { val leftV = left.evalTo[GroupElement](env) - val rightV = right.evalTo[special.sigma.BigInt](env) + val rightV = right.evalTo[sigma.BigInt](env) addCost(Exponentiate.costKind) leftV.exp(rightV) } diff --git a/interpreter/shared/src/main/scala/sigmastate/types.scala b/interpreter/shared/src/main/scala/sigmastate/types.scala index e4fd826304..586a06432e 100644 --- a/interpreter/shared/src/main/scala/sigmastate/types.scala +++ b/interpreter/shared/src/main/scala/sigmastate/types.scala @@ -3,39 +3,35 @@ package sigmastate import java.math.BigInteger import org.ergoplatform._ import org.ergoplatform.validation._ -import scalan.{RType, Nullable} -import scalan.RType.GeneralType -import sigmastate.SType.{TypeCode, AnyOps} +import sigma.data.{Nullable, RType} +import sigma.data.GeneralType +import sigmastate.SType.TypeCode import sigmastate.interpreter._ import sigmastate.utils.Overloading.Overload1 -import sigmastate.utils.SparseArrayContainer -import scalan.util.Extensions._ -import scorex.crypto.authds.{ADValue, ADKey} -import scorex.crypto.authds.avltree.batch.{Lookup, Remove, Insert, Update} -import scorex.crypto.hash.Blake2b256 +import scorex.crypto.authds.{ADKey, ADValue} +import scorex.crypto.authds.avltree.batch.{Insert, Lookup, Remove, Update} import sigmastate.Values._ import sigmastate.lang.Terms._ import sigmastate.lang.{SigmaBuilder, Terms} import sigmastate.SCollection._ -import sigmastate.basics.CryptoConstants.{hashLength, EcPointType} +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.serialization.OpCodes -import special.collection.Coll -import special.sigma._ +import sigma.Coll +import sigma._ import scala.language.implicitConversions -import scala.reflect.{classTag, ClassTag} +import scala.reflect.{ClassTag, classTag} import scala.collection.compat.immutable.ArraySeq -import sigmastate.SMethod.{InvokeDescBuilder, MethodCostFunc, givenCost, javaMethodOf, MethodCallIrBuilder} +import sigmastate.SMethod.{InvokeDescBuilder, MethodCallIrBuilder, MethodCostFunc, javaMethodOf} import sigmastate.utxo._ import sigmastate.lang.Terms.STypeSubst import sigmastate.eval.Evaluation.stypeToRType import sigmastate.eval._ -import sigmastate.exceptions.MethodNotFound import debox.cfor -import scalan.reflection.{CommonReflection, RClass, RMethod} +import sigma.reflection.{RClass, RMethod} +import sigma.util.Extensions.{IntOps, LongOps, ShortOps} -import scala.collection.mutable -import scala.util.{Success, Failure} +import scala.util.{Failure, Success} /** Base type for all AST nodes of sigma lang. */ trait SigmaNode extends Product @@ -104,27 +100,20 @@ object SType { val DummyValue = 0.asWrappedType - implicit val typeByte = SByte - implicit val typeShort = SShort - implicit val typeInt = SInt - implicit val typeLong = SLong - implicit val typeBigInt = SBigInt - implicit val typeBoolean = SBoolean - implicit val typeAvlTree = SAvlTree - implicit val typeGroupElement = SGroupElement - implicit val typeSigmaProp = SSigmaProp - implicit val typeBox = SBox + implicit val typeByte : SByte.type = SByte + implicit val typeShort : SShort.type = SShort + implicit val typeInt : SInt.type = SInt + implicit val typeLong : SLong.type = SLong + implicit val typeBigInt : SBigInt.type = SBigInt + implicit val typeBoolean : SBoolean.type = SBoolean + implicit val typeAvlTree : SAvlTree.type = SAvlTree + implicit val typeGroupElement: SGroupElement.type = SGroupElement + implicit val typeSigmaProp : SSigmaProp.type = SSigmaProp + implicit val typeBox : SBox.type = SBox /** Costructs a collection type with the given type of elements. */ implicit def typeCollection[V <: SType](implicit tV: V): SCollection[V] = SCollection[V](tV) - /** RType descriptors for predefined types used in AOTC-based interpreter. */ - implicit val SigmaBooleanRType: RType[SigmaBoolean] = RType.fromClassTag(classTag[SigmaBoolean]) - implicit val ErgoBoxRType: RType[ErgoBox] = RType.fromClassTag(classTag[ErgoBox]) - implicit val ErgoBoxCandidateRType: RType[ErgoBoxCandidate] = RType.fromClassTag(classTag[ErgoBoxCandidate]) - implicit val AvlTreeDataRType: RType[AvlTreeData] = GeneralType(classTag[AvlTreeData]) - implicit val ErgoLikeContextRType: RType[ErgoLikeContext] = RType.fromClassTag(classTag[ErgoLikeContext]) - /** Named type variables and parameters used in generic types and method signatures. * Generic type terms like `(Coll[IV],(IV) => Boolean) => Boolean` are used to represent * method types of `Coll`` and `Option`` types. Each such type is an instance of [[SFunc]]. @@ -273,7 +262,7 @@ object SType { case SShort => reflect.classTag[Short] case SInt => reflect.classTag[Int] case SLong => reflect.classTag[Long] - case SBigInt => reflect.classTag[BigInteger] + case SBigInt => reflect.classTag[BigInt] case SAvlTree => reflect.classTag[AvlTree] case SGroupElement => reflect.classTag[EcPointType] case SSigmaProp => reflect.classTag[SigmaBoolean] @@ -2186,7 +2175,7 @@ case object SAvlTree extends SProduct with SPredefType with SMonoType { def createVerifier(tree: AvlTree, proof: Coll[Byte])(implicit E: ErgoTreeEvaluator) = { // the cost of tree reconstruction from proof is O(proof.length) E.addSeqCost(CreateAvlVerifier_Info, proof.length) { () => - tree.createVerifier(proof) + AvlTreeVerifier(tree, proof) } } @@ -2563,7 +2552,7 @@ case object SPreHeader extends SProduct with SPredefType with SMonoType { /** This type is introduced to unify handling of global and non-global (i.e. methods) operations. * It unifies implementation of global operation with implementation of methods and avoids code * duplication (following DRY principle https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). - * The WrappedType is `special.sigma.SigmaDslBuilder`, which is an interface implemented by + * The WrappedType is `sigma.SigmaDslBuilder`, which is an interface implemented by * the singleton sigmastate.eval.CostingSigmaDslBuilder * * The Constant(...) tree node of this type are not allowed, as well as using it in register and diff --git a/interpreter/shared/src/main/scala/sigmastate/utils/Extensions.scala b/interpreter/shared/src/main/scala/sigmastate/utils/Extensions.scala index 5cdb9f70fc..9490f76965 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utils/Extensions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utils/Extensions.scala @@ -4,7 +4,7 @@ import org.ergoplatform.ErgoBox.TokenId import scorex.util.{ModifierId, idToBytes} import scorex.utils.{Ints, Longs, Shorts} import sigmastate.eval.{Digest32Coll, SigmaDsl} -import special.collection.Coll +import sigma.{Coll, Colls} object Extensions { implicit class ByteOpsForSigma(val b: Byte) extends AnyVal { @@ -25,7 +25,7 @@ object Extensions { * For example, the Short value {@code 0x1213} would yield the * byte array {@code {0x12, 0x13}}. */ - def toBytes: Coll[Byte] = SigmaDsl.Colls.fromArray(Shorts.toByteArray(x)) + def toBytes: Coll[Byte] = Colls.fromArray(Shorts.toByteArray(x)) /** Returns a big-endian representation of this numeric in a collection of Booleans. * Each boolean corresponds to one bit. @@ -38,7 +38,7 @@ object Extensions { * For example, the Int value {@code 0x12131415} would yield the * byte array {@code {0x12, 0x13, 0x14, 0x15}}. */ - def toBytes: Coll[Byte] = SigmaDsl.Colls.fromArray(Ints.toByteArray(x)) + def toBytes: Coll[Byte] = Colls.fromArray(Ints.toByteArray(x)) /** Returns a big-endian representation of this numeric in a collection of Booleans. * Each boolean corresponds to one bit. @@ -51,7 +51,7 @@ object Extensions { * For example, the Long value {@code 0x1213141516171819} would yield the * byte array {@code {0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19}}. */ - def toBytes: Coll[Byte] = SigmaDsl.Colls.fromArray(Longs.toByteArray(x)) + def toBytes: Coll[Byte] = Colls.fromArray(Longs.toByteArray(x)) /** Returns a big-endian representation of this numeric in a collection of Booleans. * Each boolean corresponds to one bit. @@ -67,7 +67,7 @@ object Extensions { */ implicit class ModifierIdOps(val id: ModifierId) extends AnyVal { /** @return a `Coll[Byte]` representation of the `ModifierId` (decodes using Base16). */ - def toColl: Coll[Byte] = SigmaDsl.Colls.fromArray(idToBytes(id)) + def toColl: Coll[Byte] = Colls.fromArray(idToBytes(id)) /** Converts this modifier id to to token id. */ def toTokenId: TokenId = Digest32Coll @@ toColl diff --git a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala index 1b16ef05f9..5693def9af 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utils/Helpers.scala @@ -3,13 +3,11 @@ package sigmastate.utils import debox.cfor import io.circe.Decoder import org.ergoplatform.settings.ErgoAlgos -import scalan.{OverloadHack, RType} +import sigma.data.{OverloadHack, RType} import scorex.utils.Ints -import sigmastate.Environment -import sigmastate.eval.{CAnyValue, Colls, SigmaDsl} -import sigmastate.basics.CryptoConstants.EcPointType -import special.collection.Coll -import special.sigma.GroupElement +import sigma.{Coll, Colls, Environment, GroupElement} +import sigmastate.eval.{CAnyValue, SigmaDsl} +import sigmastate.crypto.CryptoConstants.EcPointType import java.util import java.util.concurrent.locks.Lock @@ -80,15 +78,15 @@ object Helpers { } def deepHashCode[T](arr: Array[T]): Int = arr match { - case arr: Array[AnyRef] => util.Arrays.deepHashCode(arr) - case arr: Array[Byte] => util.Arrays.hashCode(arr) - case arr: Array[Short] => util.Arrays.hashCode(arr) - case arr: Array[Int] => util.Arrays.hashCode(arr) - case arr: Array[Long] => util.Arrays.hashCode(arr) - case arr: Array[Char] => util.Arrays.hashCode(arr) - case arr: Array[Float] => util.Arrays.hashCode(arr) - case arr: Array[Double] => util.Arrays.hashCode(arr) - case arr: Array[Boolean] => util.Arrays.hashCode(arr) + case arr: Array[AnyRef] => java.util.Arrays.deepHashCode(arr) + case arr: Array[Byte] => java.util.Arrays.hashCode(arr) + case arr: Array[Short] => java.util.Arrays.hashCode(arr) + case arr: Array[Int] => java.util.Arrays.hashCode(arr) + case arr: Array[Long] => java.util.Arrays.hashCode(arr) + case arr: Array[Char] => java.util.Arrays.hashCode(arr) + case arr: Array[Float] => java.util.Arrays.hashCode(arr) + case arr: Array[Double] => java.util.Arrays.hashCode(arr) + case arr: Array[Boolean] => java.util.Arrays.hashCode(arr) } /** Optimized hashCode for array of bytes when it represents some hash thus it have @@ -97,7 +95,7 @@ object Helpers { */ @inline final def safeIdHashCode(id: Array[Byte]): Int = if (id != null && id.length >= 4) Ints.fromBytes(id(0), id(1), id(2), id(3)) - else util.Arrays.hashCode(id) + else java.util.Arrays.hashCode(id) implicit class TryOps[+A](val source: Try[A]) extends AnyVal { def fold[B](onError: Throwable => B, onSuccess: A => B) = source match { diff --git a/interpreter/shared/src/main/scala/sigmastate/utils/SigmaByteReader.scala b/interpreter/shared/src/main/scala/sigmastate/utils/SigmaByteReader.scala index 2faae121d8..00f900c741 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utils/SigmaByteReader.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utils/SigmaByteReader.scala @@ -6,7 +6,7 @@ import scorex.util.serialization.Reader import sigmastate.SType import sigmastate.Values.{SValue, Value} import sigmastate.serialization._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import debox.cfor import sigmastate.exceptions.DeserializeCallDepthExceeded diff --git a/interpreter/shared/src/main/scala/sigmastate/utxo/ComplexityTableStat.scala b/interpreter/shared/src/main/scala/sigmastate/utxo/ComplexityTableStat.scala index c9f68138d9..e595fa2b6a 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utxo/ComplexityTableStat.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utxo/ComplexityTableStat.scala @@ -2,7 +2,7 @@ package sigmastate.utxo import sigmastate.serialization.ValueSerializer.getSerializer import sigmastate.serialization.OpCodes.OpCode -import scalan.util.Extensions.ByteOps +import sigma.util.Extensions.ByteOps import sigmastate.SMethod import sigmastate.serialization.OpCodes diff --git a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala index a3bcdf0da1..3d1ec92872 100644 --- a/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala +++ b/interpreter/shared/src/main/scala/sigmastate/utxo/transformers.scala @@ -7,14 +7,14 @@ import sigmastate._ import sigmastate.serialization.OpCodes.OpCode import sigmastate.serialization.OpCodes import org.ergoplatform.ErgoBox.RegisterId -import scalan.RType +import sigma.data.RType import sigmastate.Operations._ import sigmastate.eval.{Evaluation, SigmaDsl} import sigmastate.exceptions.InterpreterException import sigmastate.interpreter.ErgoTreeEvaluator import sigmastate.interpreter.ErgoTreeEvaluator.{DataEnv, error} -import special.collection.Coll -import special.sigma.{Box, SigmaProp} +import sigma.Coll +import sigma.{Box, SigmaProp} // TODO refactor: remove this trait as it doesn't have semantic meaning @@ -390,7 +390,7 @@ case class ExtractAmount(input: Value[SBox.type]) extends Extract[SLong.type] wi object ExtractAmount extends SimpleTransformerCompanion with FixedCostValueCompanion { val OpType = SFunc(SBox, SLong) override def opCode: OpCode = OpCodes.ExtractAmountCode - /** Cost of: 1) access `value` property of a [[special.sigma.Box]] */ + /** Cost of: 1) access `value` property of a [[sigma.Box]] */ override val costKind = FixedCost(JitCost(8)) override def argInfos: Seq[ArgInfo] = ExtractAmountInfo.argInfos } @@ -572,7 +572,7 @@ object DeserializeRegister extends ValueCompanion { baseCost = JitCost(1), perChunkCost = JitCost(10), chunkSize = 128) } -/** See [[special.sigma.Context.getVar()]] for detailed description. */ +/** See [[sigma.Context.getVar()]] for detailed description. */ case class GetVar[V <: SType](varId: Byte, override val tpe: SOption[V]) extends NotReadyValue[SOption[V]] { override def companion = GetVar override val opType = SFunc(SContext.ContextFuncDom, tpe) diff --git a/interpreter/shared/src/test/scala/sigmastate/SigmaProtocolSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/SigmaProtocolSpecification.scala index 669cb09da5..5e059e3355 100644 --- a/interpreter/shared/src/test/scala/sigmastate/SigmaProtocolSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/SigmaProtocolSpecification.scala @@ -1,8 +1,8 @@ package sigmastate -import sigmastate.basics.VerifierMessage.Challenge +import sigmastate.crypto.VerifierMessage.Challenge import sigmastate.crypto.{GF2_192, GF2_192_Poly} -import special.sigma.SigmaTestingData +import sigma.SigmaTestingData class SigmaProtocolSpecification extends SigmaTestingData { diff --git a/interpreter/shared/src/test/scala/sigmastate/TestsBase.scala b/interpreter/shared/src/test/scala/sigmastate/TestsBase.scala index 4e40d91c23..57ecd5e5e8 100644 --- a/interpreter/shared/src/test/scala/sigmastate/TestsBase.scala +++ b/interpreter/shared/src/test/scala/sigmastate/TestsBase.scala @@ -1,8 +1,9 @@ package sigmastate import org.scalatest.matchers.should.Matchers -import sigmastate.Values.{SigmaPropValue, SigmaBoolean, ErgoTree} +import sigmastate.Values.{ErgoTree, SigmaBoolean, SigmaPropValue} import org.ergoplatform.ErgoTreePredef +import sigma.VersionTesting trait TestsBase extends Matchers with VersionTesting { /** Set this to true to enable debug console output in tests */ diff --git a/interpreter/shared/src/test/scala/sigmastate/crypto/GroupLawsSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/crypto/GroupLawsSpecification.scala index 45863a18a6..d177a26e4c 100644 --- a/interpreter/shared/src/test/scala/sigmastate/crypto/GroupLawsSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/crypto/GroupLawsSpecification.scala @@ -2,7 +2,7 @@ package sigmastate.crypto import java.math.BigInteger import org.scalacheck.Gen -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import CryptoConstants.EcPointType import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks diff --git a/interpreter/shared/src/test/scala/sigmastate/crypto/SigningSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/crypto/SigningSpecification.scala index 4ac2f7c8da..724a0171dc 100644 --- a/interpreter/shared/src/test/scala/sigmastate/crypto/SigningSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/crypto/SigningSpecification.scala @@ -4,11 +4,11 @@ import org.scalacheck.Gen import scorex.util.encode.Base16 import sigmastate.{AtLeast, COR, CAND} import sigmastate.Values.SigmaBoolean -import sigmastate.basics.DLogProtocol.DLogProverInput +import sigmastate.crypto.DLogProtocol.DLogProverInput import sigmastate.helpers.{ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter, TestingCommons} import sigmastate.interpreter.{HintsBag, ContextExtension, ProverResult} import sigmastate.serialization.transformers.ProveDHTupleSerializer -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.ProveDHTuple class SigningSpecification extends TestingCommons { diff --git a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala index d4f05a4050..07b8fdcddb 100644 --- a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala +++ b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala @@ -5,8 +5,8 @@ import org.scalatest.matchers.should.Matchers import java.math.BigInteger import sigmastate.TrivialProp -import sigmastate.basics.SecP256K1Group -import special.sigma.{ContractsTestkit, SigmaDslBuilder, SigmaProp} +import sigmastate.crypto.SecP256K1Group +import sigma.{ContractsTestkit, SigmaDslBuilder, SigmaProp} import scala.language.implicitConversions diff --git a/interpreter/shared/src/test/scala/sigmastate/helpers/ContextEnrichingTestProvingInterpreter.scala b/interpreter/shared/src/test/scala/sigmastate/helpers/ContextEnrichingTestProvingInterpreter.scala index e9f77b65c6..641142f43c 100644 --- a/interpreter/shared/src/test/scala/sigmastate/helpers/ContextEnrichingTestProvingInterpreter.scala +++ b/interpreter/shared/src/test/scala/sigmastate/helpers/ContextEnrichingTestProvingInterpreter.scala @@ -3,8 +3,8 @@ package sigmastate.helpers import scorex.utils.Random import sigmastate.SType import sigmastate.Values._ -import sigmastate.basics.DLogProtocol.DLogProverInput -import sigmastate.basics.DiffieHellmanTupleProverInput +import sigmastate.crypto.DLogProtocol.DLogProverInput +import sigmastate.crypto.DiffieHellmanTupleProverInput class ContextEnrichingTestProvingInterpreter extends ErgoLikeTestProvingInterpreter with ContextEnrichingProverInterpreter { diff --git a/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeContextTesting.scala b/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeContextTesting.scala index 702d890147..70f644bd66 100644 --- a/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeContextTesting.scala +++ b/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeContextTesting.scala @@ -4,13 +4,12 @@ import org.ergoplatform.ErgoLikeContext.Height import org.ergoplatform._ import org.ergoplatform.validation.{SigmaValidationSettings, ValidationRules} import sigmastate.AvlTreeData -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.eval._ import sigmastate.interpreter.ContextExtension import sigmastate.interpreter.ErgoTreeEvaluator.DefaultEvalSettings import sigmastate.serialization.{GroupElementSerializer, SigmaSerializer} -import special.collection.Coll -import special.sigma.{Box, Header, PreHeader} +import sigma.{Box, Coll, Colls, Header, PreHeader} object ErgoLikeContextTesting { /* NO HF PROOF: diff --git a/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeTestProvingInterpreter.scala b/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeTestProvingInterpreter.scala index 2a3609a3fc..5500d7aa66 100644 --- a/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeTestProvingInterpreter.scala +++ b/interpreter/shared/src/test/scala/sigmastate/helpers/ErgoLikeTestProvingInterpreter.scala @@ -1,8 +1,8 @@ package sigmastate.helpers import sigmastate.UnprovenConjecture -import sigmastate.basics.DLogProtocol.DLogProverInput -import sigmastate.basics.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} +import sigmastate.crypto.DLogProtocol.DLogProverInput +import sigmastate.crypto.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} import sigmastate.interpreter.ProverInterpreter class ErgoLikeTestProvingInterpreter diff --git a/interpreter/shared/src/test/scala/sigmastate/helpers/TestingCommons.scala b/interpreter/shared/src/test/scala/sigmastate/helpers/TestingCommons.scala index 9c61e52aed..19a8efe608 100644 --- a/interpreter/shared/src/test/scala/sigmastate/helpers/TestingCommons.scala +++ b/interpreter/shared/src/test/scala/sigmastate/helpers/TestingCommons.scala @@ -9,7 +9,7 @@ import sigmastate.eval.SigmaDsl import scorex.crypto.hash.Blake2b256 import org.ergoplatform.{ErgoBox, ErgoLikeContext} import org.scalatest.matchers.should.Matchers -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType trait TestingCommons extends AnyPropSpec with ScalaCheckPropertyChecks diff --git a/interpreter/shared/src/test/scala/sigmastate/helpers/TestingHelpers.scala b/interpreter/shared/src/test/scala/sigmastate/helpers/TestingHelpers.scala index fa1b9f163c..c0255b6adc 100644 --- a/interpreter/shared/src/test/scala/sigmastate/helpers/TestingHelpers.scala +++ b/interpreter/shared/src/test/scala/sigmastate/helpers/TestingHelpers.scala @@ -4,12 +4,13 @@ import org.ergoplatform.ErgoBox.{AdditionalRegisters, Token, allZerosModifierId} import org.ergoplatform.validation.SigmaValidationSettings import org.ergoplatform._ import scorex.util.ModifierId +import sigma.data.{CollOverArray, PairOfCols} import sigmastate.AvlTreeData import sigmastate.Values.ErgoTree -import sigmastate.eval.{CostingSigmaDslBuilder, _} +import sigmastate.eval._ import sigmastate.interpreter.ContextExtension -import special.collection.{Coll, CollOverArray, PairOfCols} -import special.sigma.{Header, PreHeader} +import sigma.Coll +import sigma.{Header, PreHeader} import scala.collection.compat.immutable.ArraySeq diff --git a/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala b/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala index 8fa3ad0304..657ded51ce 100644 --- a/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala +++ b/interpreter/shared/src/test/scala/sigmastate/lang/SigmaBuilderTest.scala @@ -3,14 +3,15 @@ package sigmastate.lang import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks -import scalan.{Nullable, RType} +import sigma.data.{Nullable, RType} +import sigma.{Environment, VersionContext} import sigmastate.Values._ import sigmastate._ import sigmastate.eval.Extensions.ArrayOps import sigmastate.eval.{CAnyValue, CAvlTree, CostingBox, SigmaDsl} import sigmastate.exceptions.ConstraintFailed import sigmastate.serialization.OpCodes -import special.sigma.SigmaTestingData +import sigma.SigmaTestingData import java.math.BigInteger diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/AvlTreeSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/AvlTreeSpecification.scala index 42c71278ef..8a0b4b9255 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/AvlTreeSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/AvlTreeSpecification.scala @@ -3,6 +3,7 @@ package sigmastate.serialization import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.authds.avltree.batch.{BatchAVLProver, Insert} import scorex.crypto.hash.{Blake2b256, Digest32} +import sigma.Colls import sigmastate.Values.AvlTreeConstant import sigmastate.AvlTreeFlags import sigmastate._ diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala index 42df295d53..04b016376a 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/ConstantSerializerSpecification.scala @@ -3,16 +3,16 @@ package sigmastate.serialization import java.math.BigInteger import org.ergoplatform._ import org.scalacheck.Arbitrary._ -import scalan.RType +import sigma.data.RType import sigmastate.SCollection.SByteArray import sigmastate.Values.{BigIntConstant, ByteArrayConstant, Constant, FalseLeaf, GroupGenerator, LongConstant, SValue, TrueLeaf} -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate._ import sigmastate.eval._ import sigmastate.eval.Extensions._ import sigmastate.Values._ import sigmastate.eval.Evaluation -import special.sigma.AvlTree +import sigma.{AvlTree, Colls} import SType.AnyOps import scorex.util.encode.Base16 import sigmastate.exceptions.SerializerException @@ -27,7 +27,7 @@ class ConstantSerializerSpecification extends TableSerializationSpecification { implicit val tT = Evaluation.stypeToRType(tpe) implicit val tag = tT.classTag forAll { xs: Array[T#WrappedType] => - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType roundTripTest(Constant[SCollection[T]](xs.toColl, SCollection(tpe))) roundTripTest(Constant[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe)))) // pairs are special case val triples = xs.toColl.map(x => TupleColl(x, x, x)).asWrappedType @@ -49,7 +49,7 @@ class ConstantSerializerSpecification extends TableSerializationSpecification { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tT = Evaluation.stypeToRType(tpe) @nowarn implicit val tag = tT.classTag - implicit val tAny: RType[Any] = RType.AnyType + implicit val tAny: RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundTripTest(Constant[SType]((x, y).asWrappedType, STuple(tpe, tpe))) diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala index d50f943d7a..c02df973dc 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/DataSerializerSpecification.scala @@ -3,15 +3,15 @@ package sigmastate.serialization import java.math.BigInteger import org.ergoplatform.ErgoBox import org.scalacheck.Arbitrary._ -import scalan.RType +import sigma.data.RType import sigmastate.SCollection.SByteArray import sigmastate.Values.{ErgoTree, SigmaBoolean} import sigmastate._ import sigmastate.eval.Evaluation import sigmastate.eval._ import sigmastate.eval.Extensions._ -import sigmastate.basics.CryptoConstants.EcPointType -import special.sigma.AvlTree +import sigmastate.crypto.CryptoConstants.EcPointType +import sigma.{AvlTree, Colls} import SType.AnyOps import sigmastate.exceptions.SerializerException import sigmastate.interpreter.{CostAccumulator, ErgoTreeEvaluator} @@ -51,7 +51,7 @@ class DataSerializerSpecification extends SerializationSpecification { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tT = Evaluation.stypeToRType(tpe) implicit val tagT = tT.classTag - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { xs: Array[T#WrappedType] => roundtrip[SCollection[T]](xs.toColl, SCollection(tpe)) roundtrip[SType](xs.toColl.map(x => (x, x)).asWrappedType, SCollection(STuple(tpe, tpe))) @@ -78,7 +78,7 @@ class DataSerializerSpecification extends SerializationSpecification { def testTuples[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) @nowarn implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny: RType[Any] = RType.AnyType + implicit val tAny: RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe)) @@ -107,7 +107,7 @@ class DataSerializerSpecification extends SerializationSpecification { property("Should check limits and fail") { val len = 0xFFFF + 1 - val tup = SigmaDsl.Colls.replicate(len, 1.asInstanceOf[Any])(RType.AnyType) + val tup = SigmaDsl.Colls.replicate(len, 1.asInstanceOf[Any])(sigma.AnyType) assertExceptionThrown({ val w = SigmaSerializer.startWriter() DataSerializer.serialize(tup.asWrappedType, STuple(Array.fill(len)(SInt)), w) diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/GroupElementSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/GroupElementSerializerSpecification.scala index a0a5c8c2c1..04c4a8e128 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/GroupElementSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/GroupElementSerializerSpecification.scala @@ -1,6 +1,6 @@ package sigmastate.serialization -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.crypto.CryptoFacade import sigmastate.eval._ diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/PDHTSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/PDHTSerializerSpecification.scala index 4df5ab5b61..dbca6fb190 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/PDHTSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/PDHTSerializerSpecification.scala @@ -1,6 +1,6 @@ package sigmastate.serialization -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.ProveDHTuple class PDHTSerializerSpecification extends SerializationSpecification { diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/ProveDlogSerializerSpec.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/ProveDlogSerializerSpec.scala index 1705fc325e..df791f248a 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/ProveDlogSerializerSpec.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/ProveDlogSerializerSpec.scala @@ -1,6 +1,6 @@ package sigmastate.serialization -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog class ProveDlogSerializerSpec extends SerializationSpecification { diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/SigSerializerSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/SigSerializerSpecification.scala index a66c56f2f2..52aaa89070 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/SigSerializerSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/SigSerializerSpecification.scala @@ -6,9 +6,9 @@ import org.scalacheck.{Arbitrary, Gen} import org.scalatest.Assertion import sigmastate.Values.SigmaBoolean import sigmastate._ -import sigmastate.basics.DLogProtocol.{ProveDlog, SecondDLogProverMessage} -import sigmastate.basics.VerifierMessage.Challenge -import sigmastate.basics.{ProveDHTuple, SecondDHTupleProverMessage} +import sigmastate.crypto.DLogProtocol.{ProveDlog, SecondDLogProverMessage} +import sigmastate.crypto.VerifierMessage.Challenge +import sigmastate.crypto.{ProveDHTuple, SecondDHTupleProverMessage} import sigmastate.crypto.GF2_192_Poly import sigmastate.eval.Extensions.ArrayOps import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTransactionTesting, TestingCommons} diff --git a/interpreter/shared/src/test/scala/sigmastate/serialization/generators/ObjectGenerators.scala b/interpreter/shared/src/test/scala/sigmastate/serialization/generators/ObjectGenerators.scala index d566e416ba..4c57f86246 100644 --- a/interpreter/shared/src/test/scala/sigmastate/serialization/generators/ObjectGenerators.scala +++ b/interpreter/shared/src/test/scala/sigmastate/serialization/generators/ObjectGenerators.scala @@ -8,22 +8,22 @@ import org.scalacheck.Arbitrary._ import org.scalacheck.Gen.{choose, frequency} import org.scalacheck.util.Buildable import org.scalacheck.{Arbitrary, Gen} -import scalan.RType +import sigma.data.RType import scorex.crypto.authds.{ADDigest, ADKey} import scorex.util.encode.{Base58, Base64} import scorex.util.{ModifierId, bytesToId} import sigmastate.Values._ -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.{CryptoConstants, ProveDHTuple} +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{CryptoConstants, ProveDHTuple} import sigmastate.eval.Extensions._ import sigmastate.eval.{CostingBox, SigmaDsl, _} -import sigmastate.basics.CryptoConstants.{EcPointType, dlogGroup} +import sigmastate.crypto.CryptoConstants.{EcPointType, dlogGroup} import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.lang.TransformingSigmaBuilder._ import sigmastate._ import sigmastate.utxo._ -import special.collection.Coll -import special.sigma._ +import sigma.Coll +import sigma._ import java.math.BigInteger import scala.collection.compat.immutable.ArraySeq @@ -238,7 +238,7 @@ trait ObjectGenerators extends TypeGenerators val unsignedShortGen: Gen[Short] = Gen.chooseNum(0, Short.MaxValue).map(_.toShort) lazy val contextExtensionGen: Gen[ContextExtension] = for { - values: collection.Seq[(Byte, EvaluatedValue[SType])] <- Gen.sequence(contextExtensionValuesGen(0, 5))(Buildable.buildableSeq) + values: scala.collection.Seq[(Byte, EvaluatedValue[SType])] <- Gen.sequence(contextExtensionValuesGen(0, 5))(Buildable.buildableSeq) } yield ContextExtension(mutable.LinkedHashMap[Byte, EvaluatedValue[SType]](values.sortBy(_._1).toSeq:_*)) lazy val serializedProverResultGen: Gen[ProverResult] = for { diff --git a/interpreter/shared/src/test/scala/sigmastate/utxo/ProverSpecification.scala b/interpreter/shared/src/test/scala/sigmastate/utxo/ProverSpecification.scala index 360754db6f..1334ee520f 100644 --- a/interpreter/shared/src/test/scala/sigmastate/utxo/ProverSpecification.scala +++ b/interpreter/shared/src/test/scala/sigmastate/utxo/ProverSpecification.scala @@ -4,8 +4,8 @@ import org.ergoplatform.ErgoLikeInterpreter import scorex.crypto.hash.Blake2b256 import sigmastate.Values.SigmaBoolean import sigmastate._ -import sigmastate.basics.DLogProtocol.FirstDLogProverMessage -import sigmastate.basics.{FirstDHTupleProverMessage, SecP256K1Group} +import sigmastate.crypto.DLogProtocol.FirstDLogProverMessage +import sigmastate.crypto.{FirstDHTupleProverMessage, SecP256K1Group} import sigmastate.exceptions.InterpreterException import sigmastate.helpers.{ErgoLikeTestProvingInterpreter, TestingCommons} import sigmastate.interpreter.{HintsBag, ProverInterpreter} diff --git a/interpreter/shared/src/test/scala/special/sigma/ContractsTestkit.scala b/interpreter/shared/src/test/scala/special/sigma/ContractsTestkit.scala index a544361d98..a1226b1d03 100644 --- a/interpreter/shared/src/test/scala/special/sigma/ContractsTestkit.scala +++ b/interpreter/shared/src/test/scala/special/sigma/ContractsTestkit.scala @@ -1,13 +1,12 @@ -package special.sigma +package sigma -import special.collection.{Coll, CollOverArrayBuilder} -import scalan.RType +import sigma.data.RType import sigmastate.Values.ErgoTree import sigmastate.{AvlTreeData, Values} import sigmastate.eval._ import sigmastate.eval.Extensions._ import sigmastate.helpers.TestingHelpers._ -import scalan._ +import sigma.data._ import scala.annotation.nowarn // imports implicit ClassTag diff --git a/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala b/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala index d2b2fa819e..f5e695e32d 100644 --- a/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala +++ b/interpreter/shared/src/test/scala/special/sigma/SigmaTestingData.scala @@ -1,4 +1,4 @@ -package special.sigma +package sigma import org.ergoplatform.ErgoBox import org.ergoplatform.settings.ErgoAlgos @@ -6,15 +6,15 @@ import org.scalacheck.Arbitrary.arbitrary import org.scalacheck.Gen.containerOfN import org.scalacheck.util.Buildable import org.scalacheck.{Arbitrary, Gen} -import scalan.RType +import sigma.data.RType import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash.{Blake2b256, Digest32} import scorex.util.ModifierId import sigmastate.Values.{ByteArrayConstant, ConcreteCollection, ConstantPlaceholder, ErgoTree, FalseLeaf, IntConstant, LongConstant, SigmaPropConstant, TrueLeaf} -import sigmastate.basics.CryptoConstants.EcPointType -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.ProveDHTuple -import sigmastate.eval.{Colls, _} +import sigmastate.crypto.CryptoConstants.EcPointType +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.ProveDHTuple +import sigmastate.eval._ import sigmastate.eval.Extensions._ import sigmastate.eval.{CAvlTree, CBigInt, CHeader, CPreHeader, CSigmaProp, CostingBox, CostingSigmaDslBuilder, SigmaDsl} import sigmastate.helpers.TestingCommons @@ -22,13 +22,13 @@ import sigmastate.serialization.ErgoTreeSerializer import sigmastate.serialization.generators.ObjectGenerators import sigmastate.utils.Helpers import sigmastate._ -import special.collection.Coll +import sigma.Coll import java.math.BigInteger import scala.reflect.ClassTag trait SigmaTestingData extends TestingCommons with ObjectGenerators { - /** Creates a [[special.collection.Coll]] with the given `items`. */ + /** Creates a [[sigma.Coll]] with the given `items`. */ def Coll[T](items: T*)(implicit cT: RType[T]): Coll[T] = CostingSigmaDslBuilder.Colls.fromItems(items: _*) diff --git a/interpreter/src/main/scala/sigmastate/lang/exceptions/Exceptions.scala b/interpreter/src/main/scala/sigmastate/lang/exceptions/Exceptions.scala deleted file mode 100644 index 285baf6c26..0000000000 --- a/interpreter/src/main/scala/sigmastate/lang/exceptions/Exceptions.scala +++ /dev/null @@ -1,55 +0,0 @@ -package sigmastate.lang.exceptions - -import sigmastate.JitCost -import sigmastate.lang.SourceContext - -/** Base class of all exceptions thrown from various Sigma components. */ -class SigmaException(val message: String, val source: Option[SourceContext] = None, val cause: Option[Throwable] = None) - extends Exception(message, cause.orNull) { - - override def getMessage: String = source.map { srcCtx => - val lineNumberStrPrefix = s"line ${srcCtx.line}: " - "\n" + lineNumberStrPrefix + - s"${srcCtx.sourceLine}\n${" " * (lineNumberStrPrefix.length + srcCtx.column - 1)}^\n" + message - }.getOrElse(message) -} - -/** Exception thrown by the [[sigmastate.lang.SigmaBinder]]. */ -class BinderException(message: String, source: Option[SourceContext] = None) - extends SigmaException(message, source) - -/** Exception thrown by the [[sigmastate.lang.SigmaTyper]]. */ -class TyperException(message: String, source: Option[SourceContext] = None) - extends SigmaException(message, source) - -/** Exception thrown by the [[sigmastate.lang.SigmaSpecializer]]. */ -class SpecializerException(message: String, source: Option[SourceContext] = None) - extends SigmaException(message, source) - -/** Exception thrown by the [[sigmastate.serialization.SigmaSerializer]]. */ -case class SerializerException( - override val message: String, - override val source: Option[SourceContext] = None, - override val cause: Option[Throwable] = None) - extends SigmaException(message, source, cause) - -/** Exception thrown by the [[sigmastate.lang.SigmaBuilder]]. */ -class BuilderException(message: String, source: Option[SourceContext] = None) - extends SigmaException(message, source) - -/** Exception thrown by interpreter during cost estimation. */ -class CosterException(message: String, source: Option[SourceContext], cause: Option[Throwable] = None) - extends SigmaException(message, source, cause) - -/** Exception thrown by [[sigmastate.interpreter.Interpreter]]. */ -class InterpreterException(message: String, source: Option[SourceContext] = None, cause: Option[Throwable] = None) - extends SigmaException(message, source, cause) - -/** Exception thrown by [[sigmastate.interpreter.Interpreter]] when cost limit is exceeded. */ -class CostLimitException(val estimatedCost: Long, message: String, cause: Option[Throwable] = None) - extends SigmaException(message, None, cause) - -object CostLimitException { - /** Formats the error message with the given parameters. */ - def msgCostLimitError(cost: JitCost, limit: JitCost) = s"Estimated execution cost $cost exceeds the limit $limit" -} diff --git a/parsers/shared/src/main/scala/sigmastate/lang/SigmaParser.scala b/parsers/shared/src/main/scala/sigmastate/lang/SigmaParser.scala index 0ef4651cf5..155e4ab879 100644 --- a/parsers/shared/src/main/scala/sigmastate/lang/SigmaParser.scala +++ b/parsers/shared/src/main/scala/sigmastate/lang/SigmaParser.scala @@ -3,7 +3,7 @@ package sigmastate.lang import fastparse.internal.Logger import sigmastate._ import Values._ -import scalan.Nullable +import sigma.data.Nullable import sigmastate.lang.Terms._ import sigmastate.lang.syntax.Basic._ import sigmastate.lang.syntax.{Core, Exprs} diff --git a/parsers/shared/src/main/scala/sigmastate/lang/syntax/Basic.scala b/parsers/shared/src/main/scala/sigmastate/lang/syntax/Basic.scala index e9e91c8197..55bdd4e399 100644 --- a/parsers/shared/src/main/scala/sigmastate/lang/syntax/Basic.scala +++ b/parsers/shared/src/main/scala/sigmastate/lang/syntax/Basic.scala @@ -3,7 +3,7 @@ package sigmastate.lang.syntax import fastparse._ import NoWhitespace._ import fastparse.CharPredicates._ -import scalan.Nullable +import sigma.data.Nullable import sigmastate.lang.SourceContext import sigmastate.exceptions.CompilerException diff --git a/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala b/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala index 80ef976e1e..a1da3d0766 100644 --- a/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala +++ b/parsers/shared/src/test/scala/sigmastate/lang/LangTests.scala @@ -6,14 +6,14 @@ import sigmastate.Values.{ConcreteCollection, LongConstant, SValue, SigmaBoolean import sigmastate._ import java.math.BigInteger -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.SCollection.SByteArray -import sigmastate.basics.{ProveDHTuple, CryptoConstants} +import sigmastate.crypto.{ProveDHTuple, CryptoConstants} import sigmastate.interpreter.Interpreter.ScriptEnv -import special.sigma._ +import sigma._ import sigmastate.eval._ import sigmastate.helpers.NegativeTesting -import special.collection.Coll +import sigma.Coll trait LangTests extends Matchers with NegativeTesting { @@ -74,7 +74,7 @@ trait LangTests extends Matchers with NegativeTesting { def ty(s: String): SType = SigmaParser.parseType(s) def assertSrcCtxForAllNodes(tree: SValue): Unit = { - import sigmastate.kiama.rewriting.Rewriter._ + import sigma.kiama.rewriting.Rewriter._ rewrite(everywherebu(rule[Any] { case node: SValue => withClue(s"Missing sourceContext for $node") { node.sourceContext.isDefined shouldBe true } diff --git a/graph-ir/js/src/test/scala/scalan/Platform.scala b/sc/js/src/test/scala/scalan/Platform.scala similarity index 100% rename from graph-ir/js/src/test/scala/scalan/Platform.scala rename to sc/js/src/test/scala/scalan/Platform.scala diff --git a/graph-ir/jvm/src/test/scala/scalan/Platform.scala b/sc/jvm/src/test/scala/scalan/Platform.scala similarity index 97% rename from graph-ir/jvm/src/test/scala/scalan/Platform.scala rename to sc/jvm/src/test/scala/scalan/Platform.scala index fe49a80368..43041a92c6 100644 --- a/graph-ir/jvm/src/test/scala/scalan/Platform.scala +++ b/sc/jvm/src/test/scala/scalan/Platform.scala @@ -1,7 +1,7 @@ package scalan import scalan.compilation.GraphVizExport -import scalan.util.FileUtil +import sigma.util.FileUtil import org.scalatest.Assertions object Platform { diff --git a/graph-ir/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala b/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala similarity index 98% rename from graph-ir/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala rename to sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala index 11cc2de629..8568e6c1db 100644 --- a/graph-ir/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala +++ b/sc/jvm/src/test/scala/scalan/compilation/GraphVizExport.scala @@ -3,8 +3,10 @@ package scalan.compilation import java.awt.Desktop import java.io.{File, PrintWriter} import scalan.Scalan -import scalan.util.{StringUtil, ScalaNameUtil, FileUtil, ProcessUtil} +import scalan.core.ScalaNameUtil +import sigma.util.{FileUtil, ProcessUtil, StringUtil} +import scala.annotation.unused import scala.collection.immutable.StringOps // TODO implement this outside of the cake @@ -20,7 +22,7 @@ class GraphVizExport[Ctx <: Scalan](val scalan: Ctx) { // TODO it would be better to have nodeColor(elem: Elem[_], optDef: Option[Def[_]]) to // avoid looking up definition, but this leads to ClassFormatError (likely Scala bug) - protected def nodeColor(td: TypeDesc, d: Def[_])(implicit config: GraphVizConfig): String = d match { + protected def nodeColor(td: TypeDesc, d: Def[_])(implicit @unused config: GraphVizConfig): String = d match { case _ => nodeColor(td) } @@ -136,7 +138,7 @@ class GraphVizExport[Ctx <: Scalan](val scalan: Ctx) { case _ => x.toString } - private def emitDepEdges(sym: Sym, rhs: Def[_])(implicit stream: PrintWriter, config: GraphVizConfig) = { + private def emitDepEdges(sym: Sym, rhs: Def[_])(implicit stream: PrintWriter, @unused config: GraphVizConfig) = { val (deps, lambdaVars) = rhs match { case l: Lambda[_, _] => lambdaDeps(l) case _ => (rhs.deps.toList, Nil) diff --git a/sc/jvm/src/test/scala/sigmastate/ErgoTreeBenchmarks.scala b/sc/jvm/src/test/scala/sigmastate/ErgoTreeBenchmarks.scala index da86cbe297..f5741dcb42 100644 --- a/sc/jvm/src/test/scala/sigmastate/ErgoTreeBenchmarks.scala +++ b/sc/jvm/src/test/scala/sigmastate/ErgoTreeBenchmarks.scala @@ -2,9 +2,9 @@ package sigmastate import debox.cfor import org.scalameter.api.Bench +import sigma.BenchmarkGens import sigmastate.Values.{IntConstant, SValue} import sigmastate.serialization.OpCodes.PlusCode -import special.collections.BenchmarkGens object ErgoTreeBenchmarks extends Bench.LocalTime with BenchmarkGens { suite: Bench[Double] => diff --git a/sc/jvm/src/test/scala/sigmastate/InterpreterReflectionGeneratorTests.scala b/sc/jvm/src/test/scala/sigmastate/InterpreterReflectionGeneratorTests.scala index 45d8888e14..aaa1d6c424 100644 --- a/sc/jvm/src/test/scala/sigmastate/InterpreterReflectionGeneratorTests.scala +++ b/sc/jvm/src/test/scala/sigmastate/InterpreterReflectionGeneratorTests.scala @@ -3,8 +3,8 @@ package sigmastate import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import scalan.TypeDescs -import scalan.reflection.CommonReflection.registerClassEntry -import scalan.reflection.SRConstructor +import sigma.reflection.ReflectionData.registerClassEntry +import sigma.reflection.SRConstructor object ObjA { class A diff --git a/sc/jvm/src/test/scala/sigmastate/ReflectionGenerator.scala b/sc/jvm/src/test/scala/sigmastate/ReflectionGenerator.scala index 2d71462966..28b2733c31 100644 --- a/sc/jvm/src/test/scala/sigmastate/ReflectionGenerator.scala +++ b/sc/jvm/src/test/scala/sigmastate/ReflectionGenerator.scala @@ -1,8 +1,7 @@ package sigmastate -import scalan.reflection._ import scalan.{Base, TypeDescs} - +import sigma.reflection._ import scala.annotation.unused import scala.collection.mutable @@ -32,8 +31,8 @@ object ReflectionGenerator { val knownPackages = Array( "scalan.primitives.", - "special.collection.", - "special.sigma.", + "sigma.", + "sigma.", "special.wrappers.", "sigmastate.Values.", "sigmastate.lang.Terms.", @@ -177,14 +176,14 @@ object ReflectionGenerator { } private def collectEmptyClasses = { - scalan.reflection.Platform.unknownClasses.toSeq.filter(e => + sigma.reflection.Platform.unknownClasses.toSeq.filter(e => isEmpty(e._2) && // don't contain constructors, fields or methods - !CommonReflection.classes.contains(e._1)) // not already registered + !ReflectionData.classes.contains(e._1)) // not already registered } private def collectNonEmptyClasses = { - scalan.reflection.Platform.unknownClasses.toSeq.filter(e => + sigma.reflection.Platform.unknownClasses.toSeq.filter(e => !isEmpty(e._2) && - !CommonReflection.classes.contains(e._1)) + !ReflectionData.classes.contains(e._1)) } } diff --git a/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala b/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala index 59e08c918f..5a2c65d565 100644 --- a/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala +++ b/sc/jvm/src/test/scala/sigmastate/helpers/SigmaPPrintSpec.scala @@ -2,7 +2,7 @@ package sigmastate.helpers import org.ergoplatform.settings.ErgoAlgos import org.ergoplatform.{ErgoBox, Outputs} -import scalan.RType +import sigma.data.{CollType, RType} import scorex.util.ModifierId import sigmastate.Values._ import sigmastate._ @@ -12,8 +12,7 @@ import sigmastate.lang.Terms.MethodCall import sigmastate.serialization.OpCodes import sigmastate.utils.Helpers import sigmastate.utxo.SelectField -import special.collection.CollType -import special.sigma.SigmaDslTesting +import sigma.SigmaDslTesting import java.math.BigInteger import scala.collection.mutable.ArrayBuffer @@ -43,8 +42,8 @@ class SigmaPPrintSpec extends SigmaDslTesting { test(SCollectionType(SBoolean), "SBooleanArray") test(STuple(Vector(SBoolean, SInt)), "SPair(SBoolean, SInt)") - test(RType.BooleanType, "RType.BooleanType") - test(CollType(RType.ByteType), "CollType(RType.ByteType)") + test(sigma.BooleanType, "RType.BooleanType") + test(CollType(sigma.ByteType), "CollType(RType.ByteType)") // exception handlers test(new ArithmeticException("msg"), "new ArithmeticException(\"msg\")") diff --git a/sc/jvm/src/test/scala/sigmastate/utils/GenPredefFuncsApp.scala b/sc/jvm/src/test/scala/sigmastate/utils/GenPredefFuncsApp.scala index 3fffe59784..796b036a08 100644 --- a/sc/jvm/src/test/scala/sigmastate/utils/GenPredefFuncsApp.scala +++ b/sc/jvm/src/test/scala/sigmastate/utils/GenPredefFuncsApp.scala @@ -1,7 +1,7 @@ package sigmastate.utils -import scalan.util.FileUtil -import scalan.util.PrintExtensions._ +import sigma.util.FileUtil +import sigma.util.PrintExtensions.IterableExtensions object GenPredefFuncsApp extends SpecGen { diff --git a/sc/jvm/src/test/scala/sigmastate/utils/GenPredefTypesApp.scala b/sc/jvm/src/test/scala/sigmastate/utils/GenPredefTypesApp.scala index b889abff2b..bf11f8bf51 100644 --- a/sc/jvm/src/test/scala/sigmastate/utils/GenPredefTypesApp.scala +++ b/sc/jvm/src/test/scala/sigmastate/utils/GenPredefTypesApp.scala @@ -1,6 +1,6 @@ package sigmastate.utils -import scalan.util.FileUtil +import sigma.util.FileUtil object GenPredefTypesApp extends SpecGen { import SpecGenUtils._ diff --git a/sc/jvm/src/test/scala/sigmastate/utils/GenSerializers.scala b/sc/jvm/src/test/scala/sigmastate/utils/GenSerializers.scala index 470baf27e8..75e39111ab 100644 --- a/sc/jvm/src/test/scala/sigmastate/utils/GenSerializers.scala +++ b/sc/jvm/src/test/scala/sigmastate/utils/GenSerializers.scala @@ -1,8 +1,8 @@ package sigmastate.utils -import scalan.util.Extensions.ByteOps -import scalan.util.FileUtil -import scalan.util.PrintExtensions._ +import sigma.util.Extensions.ByteOps +import sigma.util.FileUtil +import sigma.util.PrintExtensions._ import sigmastate.lang.Terms.{MethodCall, PropertyCall} import sigmastate.serialization.ValueSerializer._ diff --git a/graph-ir/jvm/src/test/scala/special/collections/BasicBenchmarks.scala b/sc/jvm/src/test/scala/special/collections/BasicBenchmarks.scala similarity index 98% rename from graph-ir/jvm/src/test/scala/special/collections/BasicBenchmarks.scala rename to sc/jvm/src/test/scala/special/collections/BasicBenchmarks.scala index 31ecd890b1..dcb7ff54b3 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/BasicBenchmarks.scala +++ b/sc/jvm/src/test/scala/special/collections/BasicBenchmarks.scala @@ -1,4 +1,4 @@ -package special.collections +package sigma import org.scalameter.api._ import debox.cfor diff --git a/graph-ir/jvm/src/test/scala/special/collections/BenchmarkGens.scala b/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala similarity index 58% rename from graph-ir/jvm/src/test/scala/special/collections/BenchmarkGens.scala rename to sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala index 7047207a55..aced1cc381 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/BenchmarkGens.scala +++ b/sc/jvm/src/test/scala/special/collections/BenchmarkGens.scala @@ -1,7 +1,6 @@ -package special.collections +package sigma -import org.scalameter.KeyValue -import org.scalameter.api.{Gen, Bench, _} +import org.scalameter.api._ trait BenchmarkGens extends CollGens { suite: Bench[Double] => def maxSize = 100000 @@ -13,11 +12,4 @@ trait BenchmarkGens extends CollGens { suite: Bench[Double] => val arrays = ranges.map { case (r, i) => (r.toArray, i) } val colls = arrays.map { case (arr, i) => (builder.fromArray(arr), i) } - - private val config = Seq[KeyValue]( - exec.minWarmupRuns -> 5, - exec.maxWarmupRuns -> 10, - exec.benchRuns -> 30, - exec.requireGC -> true - ) } diff --git a/graph-ir/jvm/src/test/scala/special/collections/BufferBenchmark.scala b/sc/jvm/src/test/scala/special/collections/BufferBenchmark.scala similarity index 98% rename from graph-ir/jvm/src/test/scala/special/collections/BufferBenchmark.scala rename to sc/jvm/src/test/scala/special/collections/BufferBenchmark.scala index c2327c7a98..0654b12690 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/BufferBenchmark.scala +++ b/sc/jvm/src/test/scala/special/collections/BufferBenchmark.scala @@ -1,4 +1,4 @@ -package special.collections +package sigma import debox.Buffer import debox.cfor diff --git a/graph-ir/jvm/src/test/scala/special/collections/CollBenchmark.scala b/sc/jvm/src/test/scala/special/collections/CollBenchmark.scala similarity index 97% rename from graph-ir/jvm/src/test/scala/special/collections/CollBenchmark.scala rename to sc/jvm/src/test/scala/special/collections/CollBenchmark.scala index c123778137..cb2614871b 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/CollBenchmark.scala +++ b/sc/jvm/src/test/scala/special/collections/CollBenchmark.scala @@ -1,10 +1,8 @@ -package special.collections +package sigma import org.scalameter.{execution, Executor} import org.scalameter.api._ import org.scalameter.picklers.Implicits._ -import special.collection.Coll -import special.collection.Extensions._ import debox.cfor diff --git a/graph-ir/jvm/src/test/scala/special/collections/MapBenchmark.scala b/sc/jvm/src/test/scala/special/collections/MapBenchmark.scala similarity index 97% rename from graph-ir/jvm/src/test/scala/special/collections/MapBenchmark.scala rename to sc/jvm/src/test/scala/special/collections/MapBenchmark.scala index 3a5c78c8e1..1b737729ad 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/MapBenchmark.scala +++ b/sc/jvm/src/test/scala/special/collections/MapBenchmark.scala @@ -1,7 +1,7 @@ -package special.collections +package sigma import org.scalameter.api.Bench -import scalan.{AVHashMap, Nullable} +import sigma.data.{AVHashMap, Nullable} import debox.cfor trait MapBenchmarkCases extends BenchmarkGens { suite: Bench[Double] => diff --git a/graph-ir/jvm/src/test/scala/special/collections/SymBenchmark.scala b/sc/jvm/src/test/scala/special/collections/SymBenchmark.scala similarity index 98% rename from graph-ir/jvm/src/test/scala/special/collections/SymBenchmark.scala rename to sc/jvm/src/test/scala/special/collections/SymBenchmark.scala index 354177afbc..ff46aafa2b 100644 --- a/graph-ir/jvm/src/test/scala/special/collections/SymBenchmark.scala +++ b/sc/jvm/src/test/scala/special/collections/SymBenchmark.scala @@ -1,4 +1,4 @@ -package special.collections +package sigma import debox.{Set => DSet, Map => DMap} import scalan.TestLibrary diff --git a/graph-ir/shared/src/main/resources/reference.conf b/sc/shared/src/main/resources/reference.conf similarity index 100% rename from graph-ir/shared/src/main/resources/reference.conf rename to sc/shared/src/main/resources/reference.conf diff --git a/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSpec.scala b/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSpec.scala index bba4d81b3e..5950b8fcdb 100644 --- a/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSpec.scala +++ b/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSpec.scala @@ -2,11 +2,11 @@ package org.ergoplatform.dsl import org.ergoplatform.ErgoBox.{BoxId, NonMandatoryRegisterId, TokenId} import sigmastate.interpreter.{CostedProverResult, ProverResult} -import scalan.RType -import org.ergoplatform.{ErgoLikeContext, ErgoBox} -import special.sigma.{SigmaDslBuilder, AnyValue, SigmaProp} +import sigma.data.RType +import org.ergoplatform.{ErgoBox, ErgoLikeContext} +import sigma.{AnyValue, Coll, SigmaDslBuilder, SigmaProp} import sigmastate.Values.ErgoTree -import sigmastate.eval.{IRContext, CostingSigmaDslBuilder} +import sigmastate.eval.{CostingSigmaDslBuilder, IRContext} import scala.util.Try import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token} @@ -17,7 +17,7 @@ trait ContractSpec { val dsl: SigmaDslBuilder = CostingSigmaDslBuilder val Colls = dsl.Colls - implicit def Coll[T](items: Array[T])(implicit cT: RType[T]) = Colls.fromArray(items) + implicit def Coll[T](items: Array[T])(implicit cT: RType[T]): Coll[T] = Colls.fromArray(items) val IR: IRContext diff --git a/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSyntax.scala b/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSyntax.scala index d792663669..de3012ff8f 100644 --- a/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSyntax.scala +++ b/sc/shared/src/main/scala/org/ergoplatform/dsl/ContractSyntax.scala @@ -1,14 +1,13 @@ package org.ergoplatform.dsl import org.ergoplatform.ErgoBox.TokenId -import scalan.RType +import sigma.data.RType import sigmastate.SType import sigmastate.SType.AnyOps import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition} import sigmastate.eval.{CostingSigmaDslBuilder, Evaluation} import sigmastate.interpreter.Interpreter.ScriptEnv -import special.sigma.{SigmaProp, SigmaContract, Context, SigmaDslBuilder} -import scala.language.implicitConversions +import sigma.{SigmaProp, SigmaContract, Context, SigmaDslBuilder} /** Defines methods to be used in contract implementations based on [[SigmaContract]]. */ trait ContractSyntax { contract: SigmaContract => diff --git a/sc/shared/src/main/scala/org/ergoplatform/dsl/ErgoContractSpec.scala b/sc/shared/src/main/scala/org/ergoplatform/dsl/ErgoContractSpec.scala index abc025acf9..c1b0b40381 100644 --- a/sc/shared/src/main/scala/org/ergoplatform/dsl/ErgoContractSpec.scala +++ b/sc/shared/src/main/scala/org/ergoplatform/dsl/ErgoContractSpec.scala @@ -1,6 +1,6 @@ package org.ergoplatform.dsl -import special.collection.Coll +import sigma.Coll import sigmastate.interpreter.CostedProverResult import sigmastate.eval.IRContext import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token} diff --git a/graph-ir/shared/src/main/scala/scalan/Base.scala b/sc/shared/src/main/scala/scalan/Base.scala similarity index 99% rename from graph-ir/shared/src/main/scala/scalan/Base.scala rename to sc/shared/src/main/scala/scalan/Base.scala index 22e01da17f..cc29af45b9 100644 --- a/graph-ir/shared/src/main/scala/scalan/Base.scala +++ b/sc/shared/src/main/scala/scalan/Base.scala @@ -1,17 +1,17 @@ package scalan -import java.util.Arrays -import scalan.OverloadHack.Overloaded1 - -import scala.language.implicitConversions -import scala.annotation.implicitNotFound -import scala.annotation.unchecked.uncheckedVariance -import scalan.util.StringUtil import debox.{cfor, Buffer => DBuffer} -import scalan.reflection.{RClass, RConstructor} +import sigma.data.{AVHashMap, Nullable, RType} +import sigma.data.OverloadHack.Overloaded1 +import sigma.util.StringUtil +import sigma.reflection.RConstructor +import java.util.Arrays +import scala.annotation.{implicitNotFound, unused} +import scala.annotation.unchecked.uncheckedVariance import scala.collection.compat.immutable.ArraySeq import scala.collection.mutable +import scala.language.implicitConversions /** * The Base trait houses common AST nodes. It also manages a list of encountered definitions which @@ -453,7 +453,7 @@ abstract class Base { scalan: Scalan => } /** Apply this transformer to the nodes present in the sequence, * and leave non-Ref items unchanged. */ - final def apply(xs: Seq[Any])(implicit o: Overloaded1): Seq[Any] = { + final def apply(xs: Seq[Any])(implicit @unused o: Overloaded1): Seq[Any] = { val len = xs.length if (len == 0) ArraySeq.empty else { diff --git a/graph-ir/shared/src/main/scala/scalan/DefRewriting.scala b/sc/shared/src/main/scala/scalan/DefRewriting.scala similarity index 96% rename from graph-ir/shared/src/main/scala/scalan/DefRewriting.scala rename to sc/shared/src/main/scala/scalan/DefRewriting.scala index f915239d46..114fb1b0e6 100644 --- a/graph-ir/shared/src/main/scala/scalan/DefRewriting.scala +++ b/sc/shared/src/main/scala/scalan/DefRewriting.scala @@ -1,5 +1,7 @@ package scalan +import sigma.data.ExactNumeric + trait DefRewriting { scalan: Scalan => /** Rewrites given node to another equivalent node and returns its reference. @@ -12,18 +14,19 @@ trait DefRewriting { scalan: Scalan => case Tup(Def(First(a)), Def(Second(b))) if a == b => a // Rule: convert(eFrom, eTo, x, conv) if x.elem <:< eFrom ==> conv(x) - case Convert(eFrom: Elem[from], eTo: Elem[to], x, conv) if x.elem <:< eFrom => + case Convert(eFrom: Elem[from], _: Elem[to], x, conv) if x.elem <:< eFrom => mkApply(conv, x) case Apply(f @ Def(l: Lambda[a,b]), x, mayInline) if mayInline && l.mayInline => mkApply(f, x) - case call @ MethodCall(receiver, m, args, neverInvoke) => + case call @ MethodCall(receiver, m, args, _) => call.tryInvoke match { // Rule: receiver.m(args) ==> body(m).subst{xs -> args} case InvokeSuccess(res) => res case InvokeFailure(e) if !e.isInstanceOf[DelayInvokeException] => throwInvocationException("Method invocation in rewriteDef", e, receiver, m, args) + case InvokeFailure(ex) => throw ex case InvokeImpossible => val res = rewriteNonInvokableMethodCall(call) if (res != null) res diff --git a/graph-ir/shared/src/main/scala/scalan/Entities.scala b/sc/shared/src/main/scala/scalan/Entities.scala similarity index 94% rename from graph-ir/shared/src/main/scala/scalan/Entities.scala rename to sc/shared/src/main/scala/scalan/Entities.scala index db830be224..8a32dcde10 100644 --- a/graph-ir/shared/src/main/scala/scalan/Entities.scala +++ b/sc/shared/src/main/scala/scalan/Entities.scala @@ -1,7 +1,5 @@ package scalan -import scala.language.higherKinds - /** A slice in the Scalan cake with base classes for various descriptors. */ trait Entities extends TypeDescs { self: Scalan => @@ -13,7 +11,7 @@ trait Entities extends TypeDescs { self: Scalan => def parent: Option[Elem[_]] = None /** Name of the entity type without `Elem` suffix. */ def entityName: String = { - val n = scalan.reflection.Platform.safeSimpleName(this.getClass).stripSuffix("Elem") + val n = sigma.reflection.Platform.safeSimpleName(this.getClass).stripSuffix("Elem") n } def convert(x: Ref[Def[_]]): Ref[A] = !!!("should not be called") diff --git a/graph-ir/shared/src/main/scala/scalan/Exceptions.scala b/sc/shared/src/main/scala/scalan/Exceptions.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/Exceptions.scala rename to sc/shared/src/main/scala/scalan/Exceptions.scala diff --git a/graph-ir/shared/src/main/scala/scalan/GraphIRReflection.scala b/sc/shared/src/main/scala/scalan/GraphIRReflection.scala similarity index 93% rename from graph-ir/shared/src/main/scala/scalan/GraphIRReflection.scala rename to sc/shared/src/main/scala/scalan/GraphIRReflection.scala index 4be98bdf10..f7218afc92 100644 --- a/graph-ir/shared/src/main/scala/scalan/GraphIRReflection.scala +++ b/sc/shared/src/main/scala/scalan/GraphIRReflection.scala @@ -1,11 +1,13 @@ package scalan import scalan.primitives.Thunks -import scalan.reflection.CommonReflection.registerClassEntry -import scalan.reflection.{mkConstructor, mkMethod, CommonReflection} -import special.CoreLibReflection -import special.collection.Colls -import special.sigma.SigmaDsl +import sigma.reflection.ReflectionData.registerClassEntry +import sigma.reflection.{ReflectionData, mkConstructor, mkMethod} +import sigmastate.eval.SigmaLibrary +import sigma.Colls +import sigma.SigmaDsl +import sigma.data.RType +import special.wrappers.{OptionWrapSpec, RTypeWrapSpec} import wrappers.scalan.WRTypes /** Registrations of reflection metadata for graph-ir module (see README.md). @@ -15,7 +17,7 @@ import wrappers.scalan.WRTypes */ object GraphIRReflection { /** Forces initialization of reflection data. */ - val reflection = (CommonReflection, CoreLibReflection) + val reflection = ReflectionData { val clazz = classOf[wrappers.scala.WOptions#WOption[_]] val ctx = null.asInstanceOf[scalan.Library] // ok! type level only @@ -67,7 +69,7 @@ object GraphIRReflection { ) ) - { val clazz = classOf[special.sigma.SigmaDsl#SigmaProp] + { val clazz = classOf[sigma.SigmaDsl#SigmaProp] val ctx = null.asInstanceOf[SigmaDsl] // ok! type level only registerClassEntry(clazz, methods = Map( @@ -563,4 +565,40 @@ object GraphIRReflection { ) ) } + { + val clazz = classOf[OptionWrapSpec] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "getOrElse", Array[Class[_]](classOf[Option[_]], classOf[Function0[_]])) { (obj, args) => + val opt = args(0).asInstanceOf[Option[Any]] + val defaultFunc = args(1).asInstanceOf[Function0[Any]] + obj.asInstanceOf[OptionWrapSpec].getOrElse(opt, defaultFunc()) + }, + mkMethod(clazz, "isDefined", Array[Class[_]](classOf[Option[_]])) { (obj, args) => + obj.asInstanceOf[OptionWrapSpec].isDefined(args(0).asInstanceOf[Option[_]]) + }, + mkMethod(clazz, "filter", Array[Class[_]](classOf[Option[_]], classOf[Function1[_, _]])) { (obj, args) => + obj.asInstanceOf[OptionWrapSpec].filter( + args(0).asInstanceOf[Option[Any]], args(1).asInstanceOf[Any => Boolean]) + }, + mkMethod(clazz, "map", Array[Class[_]](classOf[Option[_]], classOf[Function1[_, _]])) { (obj, args) => + obj.asInstanceOf[OptionWrapSpec].map( + args(0).asInstanceOf[Option[Any]], args(1).asInstanceOf[Any => Any]) + }, + mkMethod(clazz, "get", Array[Class[_]](classOf[Option[_]])) { (obj, args) => + obj.asInstanceOf[OptionWrapSpec].get(args(0).asInstanceOf[Option[_]]) + } + ) + ) + } + { + val clazz = classOf[RTypeWrapSpec] + registerClassEntry(clazz, + methods = Map( + mkMethod(clazz, "name", Array[Class[_]](classOf[RType[_]])) { (obj, args) => + obj.asInstanceOf[RTypeWrapSpec].name(args(0).asInstanceOf[RType[_]]) + } + ) + ) + } } diff --git a/graph-ir/shared/src/main/scala/scalan/Library.scala b/sc/shared/src/main/scala/scalan/Library.scala similarity index 97% rename from graph-ir/shared/src/main/scala/scalan/Library.scala rename to sc/shared/src/main/scala/scalan/Library.scala index ac8c5564a6..ee1ff80ad3 100644 --- a/graph-ir/shared/src/main/scala/scalan/Library.scala +++ b/sc/shared/src/main/scala/scalan/Library.scala @@ -1,10 +1,10 @@ package scalan import scala.language.implicitConversions -import special.collection._ +import sigma._ +import sigma.data.{Nullable, RType} import special.wrappers.WrappersModule -import scalan.util.MemoizedFunc -import scalan.ExactIntegral._ +import sigma.util.MemoizedFunc trait Library extends Scalan with WrappersModule diff --git a/graph-ir/shared/src/main/scala/scalan/MethodCalls.scala b/sc/shared/src/main/scala/scalan/MethodCalls.scala similarity index 97% rename from graph-ir/shared/src/main/scala/scalan/MethodCalls.scala rename to sc/shared/src/main/scala/scalan/MethodCalls.scala index d300d0765a..af3c3201ef 100644 --- a/graph-ir/shared/src/main/scala/scalan/MethodCalls.scala +++ b/sc/shared/src/main/scala/scalan/MethodCalls.scala @@ -4,7 +4,8 @@ import scala.annotation.{tailrec, unused} import scala.reflect.ClassTag import debox.{Buffer => DBuffer} import debox.cfor -import scalan.reflection.RMethod +import sigma.reflection.RMethod +import sigma.util.CollectionUtil.TraversableOps trait MethodCalls extends Base { self: Scalan => @@ -12,7 +13,7 @@ trait MethodCalls extends Base { self: Scalan => /** Graph node to represent invocation of the method of some class. * @param receiver node ref representing instance on which the method is called - * @param method method which is called (descriptor from `scalan.reflection`) + * @param method method which is called (descriptor from `sigma.reflection`) * @param args node refs representing arguments passed to the method * @param neverInvoke it true this method cannot be performed, even if the * receiver node allow this @@ -43,7 +44,7 @@ trait MethodCalls extends Base { self: Scalan => /** Try invoke `method` on the node instance refered by `receiver`. * Each MC node contains enough information to perform invocation using - * `scalan.reflection.RMethod.invoke` method. However, this is not possible + * `sigma.reflection.RMethod.invoke` method. However, this is not possible * if the node pointed to by `receiver` don't implement this method, * for example when receiver is Lambda variable pointing to Variable node * instance (in which case this MC was created by adapter) @@ -62,7 +63,6 @@ trait MethodCalls extends Base { self: Scalan => ) } - import scalan.util.CollectionUtil.TraversableOps override def equals(other: Any): Boolean = (this eq other.asInstanceOf[AnyRef]) || { other match { case other: MethodCall => diff --git a/graph-ir/shared/src/main/scala/scalan/ModuleInfo.scala b/sc/shared/src/main/scala/scalan/ModuleInfo.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/ModuleInfo.scala rename to sc/shared/src/main/scala/scalan/ModuleInfo.scala diff --git a/graph-ir/shared/src/main/scala/scalan/Modules.scala b/sc/shared/src/main/scala/scalan/Modules.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/Modules.scala rename to sc/shared/src/main/scala/scalan/Modules.scala diff --git a/graph-ir/shared/src/main/scala/scalan/MutableLazy.scala b/sc/shared/src/main/scala/scalan/MutableLazy.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/MutableLazy.scala rename to sc/shared/src/main/scala/scalan/MutableLazy.scala diff --git a/graph-ir/shared/src/main/scala/scalan/Scalan.scala b/sc/shared/src/main/scala/scalan/Scalan.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/Scalan.scala rename to sc/shared/src/main/scala/scalan/Scalan.scala diff --git a/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala b/sc/shared/src/main/scala/scalan/TypeDescs.scala similarity index 94% rename from graph-ir/shared/src/main/scala/scalan/TypeDescs.scala rename to sc/shared/src/main/scala/scalan/TypeDescs.scala index 57fc2a1a52..cb5f954109 100644 --- a/graph-ir/shared/src/main/scala/scalan/TypeDescs.scala +++ b/sc/shared/src/main/scala/scalan/TypeDescs.scala @@ -1,13 +1,17 @@ package scalan -import scala.language.{implicitConversions} +import scala.language.implicitConversions import scala.annotation.implicitNotFound import scala.collection.immutable.ListMap -import scalan.util._ -import scalan.RType._ +import sigma.data.RType._ + import scala.collection.mutable import debox.cfor -import scalan.reflection.{RClass, RMethod, RConstructor} +import scalan.core.{Contravariant, Covariant, Variance} +import sigma.data.{AVHashMap, Lazy, Nullable, RType} +import sigma.reflection.{RClass, RConstructor, RMethod} +import sigma.util.CollectionUtil +import special.wrappers.WrapSpec abstract class TypeDescs extends Base { self: Scalan => @@ -66,7 +70,7 @@ abstract class TypeDescs extends Base { self: Scalan => // TODO optimize performance hot spot (45% of invokeUnlifted time), reduce allocation of Some final def getSourceValues(dataEnv: DataEnv, forWrapper: Boolean, stagedValues: AnyRef*): Seq[AnyRef] = { - import OverloadHack._ + import sigma.data.OverloadHack._ val limit = stagedValues.length val res = mutable.ArrayBuilder.make[AnyRef] res.sizeHint(limit) @@ -93,7 +97,7 @@ abstract class TypeDescs extends Base { self: Scalan => lazy val name: String = getName(_.name) // <> to delimit because: [] is used inside name; {} looks bad with structs. - override def toString = s"${scalan.reflection.Platform.safeSimpleName(getClass)}<$name>" + override def toString = s"${sigma.reflection.Platform.safeSimpleName(getClass)}<$name>" } /** Type descriptor of staged types, which correspond to source (unstaged) RTypes @@ -119,7 +123,7 @@ abstract class TypeDescs extends Base { self: Scalan => be.sourceType.name case e => val cl = e.getClass - val name = scalan.reflection.Platform.safeSimpleName(cl).stripSuffix("Elem") + val name = sigma.reflection.Platform.safeSimpleName(cl).stripSuffix("Elem") name } if (typeArgs.isEmpty) @@ -357,18 +361,18 @@ abstract class TypeDescs extends Base { self: Scalan => } /** Type descriptor for `Any`, cannot be used implicitly. */ - val AnyElement: Elem[Any] = new BaseElemLiftable[Any](null, AnyType) + val AnyElement: Elem[Any] = new BaseElemLiftable[Any](null, sigma.AnyType) /** Predefined Lazy value saved here to be used in hotspot code. */ val LazyAnyElement = Lazy(AnyElement) - implicit val BooleanElement: Elem[Boolean] = new BaseElemLiftable(false, BooleanType) - implicit val ByteElement: Elem[Byte] = new BaseElemLiftable(0.toByte, ByteType) - 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 UnitElement: Elem[Unit] = new BaseElemLiftable((), UnitType) - implicit val StringElement: Elem[String] = new BaseElemLiftable("", StringType) + implicit val BooleanElement: Elem[Boolean] = new BaseElemLiftable(false, sigma.BooleanType) + implicit val ByteElement : Elem[Byte] = new BaseElemLiftable(0.toByte, sigma.ByteType) + implicit val ShortElement : Elem[Short] = new BaseElemLiftable(0.toShort, sigma.ShortType) + implicit val IntElement : Elem[Int] = new BaseElemLiftable(0, sigma.IntType) + implicit val LongElement : Elem[Long] = new BaseElemLiftable(0L, sigma.LongType) + implicit val UnitElement : Elem[Unit] = new BaseElemLiftable((), sigma.UnitType) + implicit val StringElement : Elem[String] = new BaseElemLiftable("", sigma.StringType) /** 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/graph-ir/shared/src/main/scala/scalan/util/Variance.scala b/sc/shared/src/main/scala/scalan/core/Variance.scala similarity index 89% rename from graph-ir/shared/src/main/scala/scalan/util/Variance.scala rename to sc/shared/src/main/scala/scalan/core/Variance.scala index 2e0ea84841..279a8118d6 100644 --- a/graph-ir/shared/src/main/scala/scalan/util/Variance.scala +++ b/sc/shared/src/main/scala/scalan/core/Variance.scala @@ -1,4 +1,4 @@ -package scalan.util +package scalan.core sealed trait Variance extends Product with Serializable case object Invariant extends Variance diff --git a/graph-ir/shared/src/main/scala/scalan/meta/SSymName.scala b/sc/shared/src/main/scala/scalan/meta/SSymName.scala similarity index 93% rename from graph-ir/shared/src/main/scala/scalan/meta/SSymName.scala rename to sc/shared/src/main/scala/scalan/meta/SSymName.scala index 7574f8d8e2..ea9b1546ba 100644 --- a/graph-ir/shared/src/main/scala/scalan/meta/SSymName.scala +++ b/sc/shared/src/main/scala/scalan/meta/SSymName.scala @@ -1,6 +1,6 @@ package scalan.meta -import scalan.util.StringUtil._ +import sigma.util.StringUtil.StringUtilExtensions case class ImportItem(packageName: String, importedNames: List[String]) diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/Equal.scala b/sc/shared/src/main/scala/scalan/primitives/Equal.scala similarity index 85% rename from graph-ir/shared/src/main/scala/scalan/primitives/Equal.scala rename to sc/shared/src/main/scala/scalan/primitives/Equal.scala index e2a35acf15..4d64e94383 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/Equal.scala +++ b/sc/shared/src/main/scala/scalan/primitives/Equal.scala @@ -2,6 +2,8 @@ package scalan.primitives import scalan.{Base, Scalan} +import scala.annotation.unused + trait Equal extends Base { self: Scalan => /** Binary operation representing structural equality between arguments. */ case class Equals[A: Elem]() extends BinOp[A, Boolean]("==") { @@ -13,11 +15,11 @@ trait Equal extends Base { self: Scalan => override def applySeq(x: A, y: A): Boolean = !equalValues[A](x, y) } - protected def equalValues[A](x: Any, y: Any)(implicit eA: Elem[A]) = x == y + protected def equalValues[A](x: Any, y: Any)(implicit @unused eA: Elem[A]) = x == y /** Extension methods to construct ApplyBinOp nodes */ implicit class EqualOps[A](x: Ref[A]) { - implicit private val eA = x.elem + implicit private val eA: Elem[A] = x.elem /** Apply Equals binary operation and return Ref to ApplyBinOp node. */ def ===(y: Ref[A]): Ref[Boolean] = Equals[A].apply(x, y) diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/Functions.scala b/sc/shared/src/main/scala/scalan/primitives/Functions.scala similarity index 99% rename from graph-ir/shared/src/main/scala/scalan/primitives/Functions.scala rename to sc/shared/src/main/scala/scalan/primitives/Functions.scala index 76ec2c6d4a..e5cd6f345e 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/Functions.scala +++ b/sc/shared/src/main/scala/scalan/primitives/Functions.scala @@ -1,14 +1,14 @@ package scalan.primitives import java.util - import scalan.staged.ProgramGraphs -import scalan.util.GraphUtil -import scalan.{Nullable, emptyDBufferOfInt, Base, Lazy, Scalan} +import scalan.{Base, Scalan} import debox.{Buffer => DBuffer} import scala.language.implicitConversions import debox.cfor +import sigma.data.{Lazy, Nullable, emptyDBufferOfInt} +import sigma.util.GraphUtil trait Functions extends Base with ProgramGraphs { self: Scalan => diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/IfThenElse.scala b/sc/shared/src/main/scala/scalan/primitives/IfThenElse.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/primitives/IfThenElse.scala rename to sc/shared/src/main/scala/scalan/primitives/IfThenElse.scala diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/LogicalOps.scala b/sc/shared/src/main/scala/scalan/primitives/LogicalOps.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/primitives/LogicalOps.scala rename to sc/shared/src/main/scala/scalan/primitives/LogicalOps.scala diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/NumericOps.scala b/sc/shared/src/main/scala/scalan/primitives/NumericOps.scala similarity index 97% rename from graph-ir/shared/src/main/scala/scalan/primitives/NumericOps.scala rename to sc/shared/src/main/scala/scalan/primitives/NumericOps.scala index 39c93b49ae..3c3d80e94d 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/NumericOps.scala +++ b/sc/shared/src/main/scala/scalan/primitives/NumericOps.scala @@ -1,6 +1,7 @@ package scalan.primitives -import scalan.{ExactNumeric, Base, Scalan, ExactIntegral} +import scalan.{Base, Scalan} +import sigma.data.{ExactIntegral, ExactNumeric} /** Slice in Scala cake with definitions of numeric operations. */ trait NumericOps extends Base { self: Scalan => diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/OrderingOps.scala b/sc/shared/src/main/scala/scalan/primitives/OrderingOps.scala similarity index 97% rename from graph-ir/shared/src/main/scala/scalan/primitives/OrderingOps.scala rename to sc/shared/src/main/scala/scalan/primitives/OrderingOps.scala index 479c502795..8e6f5e0134 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/OrderingOps.scala +++ b/sc/shared/src/main/scala/scalan/primitives/OrderingOps.scala @@ -1,6 +1,8 @@ package scalan.primitives -import scalan.{Base, Scalan, ExactOrdering} +import scalan.{Base, Scalan} +import sigma.data.ExactOrdering + import scala.language.implicitConversions /** Slice in Scala cake with definitions of comparison operations. */ diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/Thunks.scala b/sc/shared/src/main/scala/scalan/primitives/Thunks.scala similarity index 98% rename from graph-ir/shared/src/main/scala/scalan/primitives/Thunks.scala rename to sc/shared/src/main/scala/scalan/primitives/Thunks.scala index 030b9b5736..ce51dc5638 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/Thunks.scala +++ b/sc/shared/src/main/scala/scalan/primitives/Thunks.scala @@ -4,9 +4,10 @@ import scala.language.{existentials, implicitConversions} import scalan._ import debox.{Buffer => DBuffer, Set => DSet} import debox.cfor -import scalan.reflection.RClass - -import scalan.util.{Covariant, GraphUtil} +import scalan.core.Covariant +import sigma.data.{AVHashMap, DFunc, Lazy, Nullable, RType} +import sigma.reflection.RClass +import sigma.util.GraphUtil import scala.collection.Seq @@ -81,7 +82,7 @@ trait Thunks extends Functions { self: Scalan => /** Implementation of Liftable type class for `Thunk[T]` given liftable for `T`. */ case class LiftableThunk[ST, T](lT: Liftable[ST, T]) extends Liftable[SThunk[ST], Thunk[T]] { - import RType._ + import sigma.data.RType._ override def eW: Elem[Thunk[T]] = thunkElement(lT.eW) override def sourceType: RType[SThunk[ST]] = { implicit val tST = lT.sourceType diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/Tuples.scala b/sc/shared/src/main/scala/scalan/primitives/Tuples.scala similarity index 98% rename from graph-ir/shared/src/main/scala/scalan/primitives/Tuples.scala rename to sc/shared/src/main/scala/scalan/primitives/Tuples.scala index 1fa5fbe5ad..c22b8a31f4 100644 --- a/graph-ir/shared/src/main/scala/scalan/primitives/Tuples.scala +++ b/sc/shared/src/main/scala/scalan/primitives/Tuples.scala @@ -4,8 +4,9 @@ */ package scalan.primitives +import scalan.{Base, Scalan} import scala.language.implicitConversions -import scalan.{Base, Scalan, AVHashMap} +import sigma.data.{AVHashMap} trait Tuples extends Base { self: Scalan => object Pair { diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/UnBinOps.scala b/sc/shared/src/main/scala/scalan/primitives/UnBinOps.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/primitives/UnBinOps.scala rename to sc/shared/src/main/scala/scalan/primitives/UnBinOps.scala diff --git a/graph-ir/shared/src/main/scala/scalan/primitives/UniversalOps.scala b/sc/shared/src/main/scala/scalan/primitives/UniversalOps.scala similarity index 100% rename from graph-ir/shared/src/main/scala/scalan/primitives/UniversalOps.scala rename to sc/shared/src/main/scala/scalan/primitives/UniversalOps.scala diff --git a/graph-ir/shared/src/main/scala/scalan/staged/AstGraphs.scala b/sc/shared/src/main/scala/scalan/staged/AstGraphs.scala similarity index 98% rename from graph-ir/shared/src/main/scala/scalan/staged/AstGraphs.scala rename to sc/shared/src/main/scala/scalan/staged/AstGraphs.scala index bec0c36eed..7ad5c24f17 100644 --- a/graph-ir/shared/src/main/scala/scalan/staged/AstGraphs.scala +++ b/sc/shared/src/main/scala/scalan/staged/AstGraphs.scala @@ -1,9 +1,10 @@ package scalan.staged import scala.collection._ -import scalan.{Base, Scalan, emptyDBufferOfInt} +import scalan.Scalan import debox.cfor -import debox.{Set => DSet, Buffer => DBuffer, Map => DMap} +import debox.{Buffer => DBuffer, Map => DMap, Set => DSet} +import sigma.data.emptyDBufferOfInt trait AstGraphs extends Transforming { self: Scalan => diff --git a/graph-ir/shared/src/main/scala/scalan/staged/ProgramGraphs.scala b/sc/shared/src/main/scala/scalan/staged/ProgramGraphs.scala similarity index 97% rename from graph-ir/shared/src/main/scala/scalan/staged/ProgramGraphs.scala rename to sc/shared/src/main/scala/scalan/staged/ProgramGraphs.scala index 28b79b3530..19d762c5bb 100644 --- a/graph-ir/shared/src/main/scala/scalan/staged/ProgramGraphs.scala +++ b/sc/shared/src/main/scala/scalan/staged/ProgramGraphs.scala @@ -1,10 +1,10 @@ package scalan.staged -import scalan.{DFunc, Scalan, Nullable} +import scalan.Scalan import debox.{Buffer => DBuffer} -import scalan.util.GraphUtil +import sigma.util.GraphUtil import debox.cfor - +import sigma.data.{DFunc, Nullable} import scala.collection.compat.immutable.ArraySeq trait ProgramGraphs extends AstGraphs { self: Scalan => diff --git a/graph-ir/shared/src/main/scala/scalan/staged/Transforming.scala b/sc/shared/src/main/scala/scalan/staged/Transforming.scala similarity index 98% rename from graph-ir/shared/src/main/scala/scalan/staged/Transforming.scala rename to sc/shared/src/main/scala/scalan/staged/Transforming.scala index 9dd714d049..045340e503 100644 --- a/graph-ir/shared/src/main/scala/scalan/staged/Transforming.scala +++ b/sc/shared/src/main/scala/scalan/staged/Transforming.scala @@ -2,10 +2,11 @@ package scalan.staged import java.util import scala.language.existentials -import scalan.{AVHashMap, DelayInvokeException, Lazy, Nullable, Scalan} +import scalan.Scalan import debox.{Buffer => DBuffer} import debox.cfor -import scalan.reflection.RMethod +import sigma.data.{Lazy, Nullable} +import sigma.reflection.RMethod trait Transforming { self: Scalan => diff --git a/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala b/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala index a992dbf0d7..99467289f2 100644 --- a/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala +++ b/sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala @@ -1,10 +1,11 @@ package sigmastate.eval import org.ergoplatform._ -import scalan.ExactIntegral.{ByteIsExactIntegral, IntIsExactIntegral, LongIsExactIntegral, ShortIsExactIntegral} -import scalan.ExactOrdering.{ByteIsExactOrdering, IntIsExactOrdering, LongIsExactOrdering, ShortIsExactOrdering} -import scalan.util.Extensions.ByteOps -import scalan.{ExactIntegral, ExactNumeric, ExactOrdering, Lazy, MutableLazy, Nullable, SigmaLibrary} +import scalan.MutableLazy +import sigma.data.ExactIntegral.{ByteIsExactIntegral, IntIsExactIntegral, LongIsExactIntegral, ShortIsExactIntegral} +import sigma.data.ExactOrdering.{ByteIsExactOrdering, IntIsExactOrdering, LongIsExactOrdering, ShortIsExactOrdering} +import sigma.util.Extensions.ByteOps +import sigma.data.{ExactIntegral, ExactNumeric, ExactOrdering, Lazy, Nullable} import sigmastate.Values.Value.Typed import sigmastate.Values._ import sigmastate.interpreter.Interpreter.ScriptEnv @@ -13,8 +14,9 @@ import sigmastate.lang.Terms.{Ident, Select, Val, ValueOps} import sigmastate.serialization.OpCodes import sigmastate.utxo._ import sigmastate._ -import sigmastate.basics.CryptoConstants.EcPointType -import sigmastate.exceptions.{SigmaException, GraphBuildingException} +import sigmastate.crypto.CryptoConstants.EcPointType +import sigmastate.exceptions.{GraphBuildingException, SigmaException} + import scala.collection.mutable.ArrayBuffer /** Perform translation of typed expression given by [[Value]] to a graph in IRContext. @@ -393,7 +395,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext => import sigmastate._ - protected implicit def groupElementToECPoint(g: special.sigma.GroupElement): EcPointType = CostingSigmaDslBuilder.toECPoint(g).asInstanceOf[EcPointType] + protected implicit def groupElementToECPoint(g: sigma.GroupElement): EcPointType = CostingSigmaDslBuilder.toECPoint(g).asInstanceOf[EcPointType] def error(msg: String) = throw new GraphBuildingException(msg, None) def error(msg: String, srcCtx: Option[SourceContext]) = throw new GraphBuildingException(msg, srcCtx) @@ -471,7 +473,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext => case box: SBox => val boxV = liftConst(box) boxV - case tree: special.sigma.AvlTree => + case tree: sigma.AvlTree => val treeV = liftConst(tree) treeV case s: String => diff --git a/graph-ir/shared/src/main/scala/scalan/SigmaLibrary.scala b/sc/shared/src/main/scala/sigmastate/eval/SigmaLibrary.scala similarity index 75% rename from graph-ir/shared/src/main/scala/scalan/SigmaLibrary.scala rename to sc/shared/src/main/scala/sigmastate/eval/SigmaLibrary.scala index 46c235758b..be17179cbf 100644 --- a/graph-ir/shared/src/main/scala/scalan/SigmaLibrary.scala +++ b/sc/shared/src/main/scala/sigmastate/eval/SigmaLibrary.scala @@ -1,10 +1,11 @@ -package scalan +package sigmastate.eval -import special.sigma.SigmaDslModule +import scalan.Library +import sigma.SigmaDslModule /** Main trait which represents sigma operations in graph IR cake. */ trait SigmaLibrary extends Library - with special.sigma.wrappers.WrappersModule + with sigma.wrappers.WrappersModule with SigmaDslModule { import WRType._ diff --git a/sc/shared/src/main/scala/sigmastate/eval/TreeBuilding.scala b/sc/shared/src/main/scala/sigmastate/eval/TreeBuilding.scala index f6e77f12e0..13fc8c7bd1 100644 --- a/sc/shared/src/main/scala/sigmastate/eval/TreeBuilding.scala +++ b/sc/shared/src/main/scala/sigmastate/eval/TreeBuilding.scala @@ -10,9 +10,8 @@ import sigmastate.serialization.ConstantStore import scala.collection.mutable.ArrayBuffer import SType._ -import scalan.SigmaLibrary -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.ProveDHTuple import sigmastate.lang.Terms /** Implementation of IR-graph to ErgoTree expression translation. diff --git a/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala b/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala index f30b25b44c..3295429ffe 100644 --- a/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala +++ b/sc/shared/src/main/scala/sigmastate/lang/SigmaBinder.scala @@ -1,9 +1,9 @@ package sigmastate.lang -import sigmastate.kiama.rewriting.CallbackRewriter import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix import org.ergoplatform._ -import scalan.Nullable +import sigma.data.Nullable +import sigma.kiama.rewriting.CallbackRewriter import sigmastate.Values._ import sigmastate._ import sigmastate.interpreter.Interpreter.ScriptEnv diff --git a/sc/shared/src/main/scala/sigmastate/lang/SigmaCompiler.scala b/sc/shared/src/main/scala/sigmastate/lang/SigmaCompiler.scala index b3575bcd8c..d37a037a58 100644 --- a/sc/shared/src/main/scala/sigmastate/lang/SigmaCompiler.scala +++ b/sc/shared/src/main/scala/sigmastate/lang/SigmaCompiler.scala @@ -2,7 +2,7 @@ package sigmastate.lang import fastparse.Parsed import fastparse.Parsed.Success -import sigmastate.kiama.rewriting.Rewriter.{everywherebu, rewrite, rule} +import sigma.kiama.rewriting.Rewriter.{everywherebu, rewrite, rule} import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix import org.ergoplatform.Global import sigmastate.Values.{SValue, Value} diff --git a/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala b/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala index ccc0784abe..beb17a98b0 100644 --- a/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala +++ b/sc/shared/src/main/scala/sigmastate/lang/SigmaTyper.scala @@ -5,8 +5,8 @@ import sigmastate.SCollection._ import sigmastate.Values._ import sigmastate._ import SCollection.SBooleanArray -import scalan.Nullable -import scalan.util.Extensions.Ensuring +import sigma.data.Nullable +import sigma.util.Extensions.Ensuring import sigmastate.lang.Terms._ import sigmastate.exceptions._ import sigmastate.lang.SigmaPredef._ diff --git a/graph-ir/shared/src/main/scala/special/collection/CollsUnit.scala b/sc/shared/src/main/scala/special/collection/CollsUnit.scala similarity index 94% rename from graph-ir/shared/src/main/scala/special/collection/CollsUnit.scala rename to sc/shared/src/main/scala/special/collection/CollsUnit.scala index 217341830d..02e62aeb4d 100644 --- a/graph-ir/shared/src/main/scala/special/collection/CollsUnit.scala +++ b/sc/shared/src/main/scala/special/collection/CollsUnit.scala @@ -1,10 +1,10 @@ -package special.collection { +package sigma { import scalan._ /** Staged version of collection interfaces which is used in graph-based IR to represent * methods of Coll and CollBuilder. * Each method of Coll and CollBuilder in Colls corresponds to a method of the original - * non-staged class [[special.collection.Coll]] and [[special.collection.CollBuilder]]. + * non-staged class [[sigma.Coll]] and [[sigma.CollBuilder]]. * The semantics of each method is the same as in the original class, please look there * for details. */ diff --git a/graph-ir/shared/src/main/scala/special/collection/impl/CollsImpl.scala b/sc/shared/src/main/scala/special/collection/impl/CollsImpl.scala similarity index 97% rename from graph-ir/shared/src/main/scala/special/collection/impl/CollsImpl.scala rename to sc/shared/src/main/scala/special/collection/impl/CollsImpl.scala index 0437f6c97f..239bfff4e5 100644 --- a/graph-ir/shared/src/main/scala/special/collection/impl/CollsImpl.scala +++ b/sc/shared/src/main/scala/special/collection/impl/CollsImpl.scala @@ -1,11 +1,12 @@ -package special.collection +package sigma import scala.language.{existentials,implicitConversions} import scalan._ import scala.collection.compat.immutable.ArraySeq package impl { - import scalan.reflection.{RClass, RMethod} + import sigma.data.{Nullable, RType} + import sigma.reflection.{RClass, RMethod} // Abs ----------------------------------- trait CollsDefs extends scalan.Scalan with Colls { @@ -20,8 +21,7 @@ import WOption._ class CollCls extends EntityObject("Coll") { // entityConst: single const for each entity import Liftables._ - import scala.reflect.{ClassTag, classTag} - type SColl[A] = special.collection.Coll[A] + type SColl[A] = sigma.Coll[A] case class CollConst[SA, A]( constValue: SColl[SA], lA: Liftable[SA, A] @@ -332,8 +332,6 @@ class CollCls extends EntityObject("Coll") { def map[A,B](xs: Ref[Coll[A]])(f: Ref[A] => Ref[B]) = { implicit val eA = unlift(xs.elem); xs.map(fun(f))} } - // manual fix: CollIso, collIso - // familyElem class CollElem[A, To <: Coll[A]](implicit _eA: Elem[A]) extends EntityElem1[A, To, Coll](_eA, container[Coll]) { @@ -348,14 +346,12 @@ class CollCls extends EntityObject("Coll") { )) } - override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.util.Invariant)) + override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.core.Invariant)) } implicit final def collElement[A](implicit eA: Elem[A]): Elem[Coll[A]] = cachedElemByClass(eA)(RClass(classOf[CollElem[A, Coll[A]]])) - // manual fix: ViewColl - object CollMethods { object length { def unapply(d: Def[_]): Nullable[Ref[Coll[A]] forSome {type A}] = d match { @@ -496,8 +492,7 @@ object Coll extends CollCls object CollBuilder extends EntityObject("CollBuilder") { // entityConst: single const for each entity import Liftables._ - import scala.reflect.{ClassTag, classTag} - type SCollBuilder = special.collection.CollBuilder + type SCollBuilder = sigma.CollBuilder case class CollBuilderConst( constValue: SCollBuilder ) extends LiftedConst[SCollBuilder, CollBuilder] with CollBuilder @@ -639,9 +634,9 @@ object CollBuilder extends EntityObject("CollBuilder") { } -object CollsModule extends scalan.ModuleInfo("special.collection", "Colls") { +object CollsModule extends scalan.ModuleInfo("sigma", "Colls") { val reflection = GraphIRReflection } } -trait CollsModule extends special.collection.impl.CollsDefs {self: Library =>} +trait CollsModule extends sigma.impl.CollsDefs {self: Library =>} diff --git a/graph-ir/shared/src/main/scala/special/sigma/SigmaDslUnit.scala b/sc/shared/src/main/scala/special/sigma/SigmaDslUnit.scala similarity index 99% rename from graph-ir/shared/src/main/scala/special/sigma/SigmaDslUnit.scala rename to sc/shared/src/main/scala/special/sigma/SigmaDslUnit.scala index 43ba7f5db2..48548226a5 100644 --- a/graph-ir/shared/src/main/scala/special/sigma/SigmaDslUnit.scala +++ b/sc/shared/src/main/scala/special/sigma/SigmaDslUnit.scala @@ -1,5 +1,6 @@ -package special.sigma { +package sigma { import scalan._ + import sigmastate.eval.SigmaLibrary trait SigmaDsl extends Base { self: SigmaLibrary => trait BigInt extends Def[BigInt] { diff --git a/graph-ir/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala b/sc/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala similarity index 98% rename from graph-ir/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala rename to sc/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala index 0642168d68..8da36ce6cf 100644 --- a/graph-ir/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala +++ b/sc/shared/src/main/scala/special/sigma/impl/SigmaDslImpl.scala @@ -1,13 +1,15 @@ -package special.sigma +package sigma -import scala.language.{existentials,implicitConversions} +import scala.language.{existentials, implicitConversions} import scalan._ +import sigmastate.eval.SigmaLibrary + import scala.collection.compat.immutable.ArraySeq package impl { - import scalan.OverloadHack.Overloaded1 - import scalan.reflection.CommonReflection.registerClassEntry - import scalan.reflection.{RClass, RMethod, SRMethod} // manual fix + import sigma.data.{Nullable, RType} + import sigma.reflection.{RClass, RMethod} + import sigmastate.eval.SigmaLibrary // Abs ----------------------------------- trait SigmaDslDefs extends scalan.Scalan with SigmaDsl { @@ -33,7 +35,7 @@ object BigInt extends EntityObject("BigInt") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SBigInt = special.sigma.BigInt + type SBigInt = sigma.BigInt case class BigIntConst( constValue: SBigInt ) extends LiftedConst[SBigInt, BigInt] with BigInt @@ -268,7 +270,7 @@ object GroupElement extends EntityObject("GroupElement") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SGroupElement = special.sigma.GroupElement + type SGroupElement = sigma.GroupElement case class GroupElementConst( constValue: SGroupElement ) extends LiftedConst[SGroupElement, GroupElement] with GroupElement @@ -408,7 +410,7 @@ object SigmaProp extends EntityObject("SigmaProp") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SSigmaProp = special.sigma.SigmaProp + type SSigmaProp = sigma.SigmaProp case class SigmaPropConst( constValue: SSigmaProp ) extends LiftedConst[SSigmaProp, SigmaProp] with SigmaProp @@ -435,7 +437,6 @@ object SigmaProp extends EntityObject("SigmaProp") { true, false, element[Coll[Byte]])) } - // manual fix && override def &&(other: Ref[SigmaProp]): Ref[SigmaProp] = { asRep[SigmaProp](mkMethodCall(self, SigmaPropClass.getMethod("$amp$amp", classOf[Sym]), @@ -443,7 +444,6 @@ object SigmaProp extends EntityObject("SigmaProp") { true, false, element[SigmaProp])) } - // manual fix || override def ||(other: Ref[SigmaProp]): Ref[SigmaProp] = { asRep[SigmaProp](mkMethodCall(self, SigmaPropClass.getMethod("$bar$bar", classOf[Sym]), @@ -484,7 +484,6 @@ object SigmaProp extends EntityObject("SigmaProp") { true, true, element[Coll[Byte]])) } - // manual fix && def &&(other: Ref[SigmaProp]): Ref[SigmaProp] = { asRep[SigmaProp](mkMethodCall(source, SigmaPropClass.getMethod("$amp$amp", classOf[Sym]), @@ -492,7 +491,6 @@ object SigmaProp extends EntityObject("SigmaProp") { true, true, element[SigmaProp])) } - // manual fix || def ||(other: Ref[SigmaProp]): Ref[SigmaProp] = { asRep[SigmaProp](mkMethodCall(source, SigmaPropClass.getMethod("$bar$bar", classOf[Sym]), @@ -572,7 +570,7 @@ object Box extends EntityObject("Box") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SBox = special.sigma.Box + type SBox = sigma.Box case class BoxConst( constValue: SBox ) extends LiftedConst[SBox, Box] with Box @@ -818,7 +816,7 @@ object AvlTree extends EntityObject("AvlTree") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SAvlTree = special.sigma.AvlTree + type SAvlTree = sigma.AvlTree case class AvlTreeConst( constValue: SAvlTree ) extends LiftedConst[SAvlTree, AvlTree] with AvlTree @@ -1091,7 +1089,7 @@ object PreHeader extends EntityObject("PreHeader") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SPreHeader = special.sigma.PreHeader + type SPreHeader = sigma.PreHeader case class PreHeaderConst( constValue: SPreHeader ) extends LiftedConst[SPreHeader, PreHeader] with PreHeader @@ -1252,7 +1250,7 @@ object Header extends EntityObject("Header") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SHeader = special.sigma.Header + type SHeader = sigma.Header case class HeaderConst( constValue: SHeader ) extends LiftedConst[SHeader, Header] with Header @@ -1525,7 +1523,7 @@ object Context extends EntityObject("Context") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SContext = special.sigma.Context + type SContext = sigma.Context case class ContextConst( constValue: SContext ) extends LiftedConst[SContext, Context] with Context @@ -1794,7 +1792,7 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { // entityConst: single const for each entity import Liftables._ import scala.reflect.{ClassTag, classTag} - type SSigmaDslBuilder = special.sigma.SigmaDslBuilder + type SSigmaDslBuilder = sigma.SigmaDslBuilder case class SigmaDslBuilderConst( constValue: SSigmaDslBuilder ) extends LiftedConst[SSigmaDslBuilder, SigmaDslBuilder] with SigmaDslBuilder @@ -2338,9 +2336,9 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { registerEntityObject("SigmaDslBuilder", SigmaDslBuilder) } -object SigmaDslModule extends scalan.ModuleInfo("special.sigma", "SigmaDsl") { +object SigmaDslModule extends scalan.ModuleInfo("sigma", "SigmaDsl") { val reflection = GraphIRReflection } } -trait SigmaDslModule extends special.sigma.impl.SigmaDslDefs {self: SigmaLibrary =>} +trait SigmaDslModule extends sigma.impl.SigmaDslDefs {self: SigmaLibrary =>} diff --git a/graph-ir/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala b/sc/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala similarity index 67% rename from graph-ir/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala rename to sc/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala index 84fc0abdd3..6696788621 100644 --- a/graph-ir/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala +++ b/sc/shared/src/main/scala/special/sigma/wrappers/WrappersModule.scala @@ -1,4 +1,4 @@ -package special.sigma.wrappers +package sigma.wrappers trait WrappersModule extends special.wrappers.WrappersModule diff --git a/common/shared/src/main/scala/scalan/WrapSpec.scala b/sc/shared/src/main/scala/special/wrappers/WrapSpec.scala similarity index 82% rename from common/shared/src/main/scala/scalan/WrapSpec.scala rename to sc/shared/src/main/scala/special/wrappers/WrapSpec.scala index 5eda48bc88..dd07f1144c 100644 --- a/common/shared/src/main/scala/scalan/WrapSpec.scala +++ b/sc/shared/src/main/scala/special/wrappers/WrapSpec.scala @@ -1,4 +1,4 @@ -package scalan +package special.wrappers /** Base type for all wrapper specification classes. * @see OptionWrapSpec as an example */ diff --git a/graph-ir/shared/src/main/scala/special/wrappers/WrappersModule.scala b/sc/shared/src/main/scala/special/wrappers/WrappersModule.scala similarity index 100% rename from graph-ir/shared/src/main/scala/special/wrappers/WrappersModule.scala rename to sc/shared/src/main/scala/special/wrappers/WrappersModule.scala diff --git a/core-lib/shared/src/main/scala/special/wrappers/WrappersSpec.scala b/sc/shared/src/main/scala/special/wrappers/WrappersSpec.scala similarity index 95% rename from core-lib/shared/src/main/scala/special/wrappers/WrappersSpec.scala rename to sc/shared/src/main/scala/special/wrappers/WrappersSpec.scala index e539d299d4..d520ce9006 100644 --- a/core-lib/shared/src/main/scala/special/wrappers/WrappersSpec.scala +++ b/sc/shared/src/main/scala/special/wrappers/WrappersSpec.scala @@ -1,6 +1,6 @@ package special.wrappers -import scalan.{WrapSpec, RType} +import sigma.data.RType /** Base class for wrappers of such types as WOption, WRType etc. * Used in graph IR to implement method invocation. diff --git a/graph-ir/shared/src/main/scala/wrappers/scala/WOptions.scala b/sc/shared/src/main/scala/wrappers/scala/WOptions.scala similarity index 100% rename from graph-ir/shared/src/main/scala/wrappers/scala/WOptions.scala rename to sc/shared/src/main/scala/wrappers/scala/WOptions.scala diff --git a/graph-ir/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala b/sc/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala similarity index 98% rename from graph-ir/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala rename to sc/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala index e5e7f333e6..45d0a91ad6 100644 --- a/graph-ir/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala +++ b/sc/shared/src/main/scala/wrappers/scala/impl/WOptionsImpl.scala @@ -7,7 +7,8 @@ import special.wrappers.OptionWrapSpec import scala.collection.compat.immutable.ArraySeq package impl { - import scalan.reflection.{RClass, RMethod} + import sigma.data.{Nullable, RType} + import sigma.reflection.{RClass, RMethod} // Abs ----------------------------------- trait WOptionsDefs extends scalan.Scalan with WOptions { @@ -168,7 +169,7 @@ class WOptionCls extends EntityObject("WOption") { )) } - override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.util.Invariant)) + override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.core.Invariant)) } implicit final def wOptionElement[A](implicit eA: Elem[A]): Elem[WOption[A]] = diff --git a/graph-ir/shared/src/main/scala/wrappers/scalan/WRTypes.scala b/sc/shared/src/main/scala/wrappers/scalan/WRTypes.scala similarity index 94% rename from graph-ir/shared/src/main/scala/wrappers/scalan/WRTypes.scala rename to sc/shared/src/main/scala/wrappers/scalan/WRTypes.scala index 07795cdada..0d55f5dd9e 100644 --- a/graph-ir/shared/src/main/scala/wrappers/scalan/WRTypes.scala +++ b/sc/shared/src/main/scala/wrappers/scalan/WRTypes.scala @@ -3,7 +3,7 @@ package wrappers.scalan { import impl._ - import scalan.RType + import sigma.data.RType import special.wrappers.WrappersModule diff --git a/graph-ir/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala b/sc/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala similarity index 97% rename from graph-ir/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala rename to sc/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala index 66bbf9ed81..9b2676f70d 100644 --- a/graph-ir/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala +++ b/sc/shared/src/main/scala/wrappers/scalan/impl/WRTypesImpl.scala @@ -1,14 +1,14 @@ package wrappers.scalan import scala.language.{existentials,implicitConversions} -import scalan.RType +import sigma.data.RType import special.wrappers.WrappersModule import special.wrappers.RTypeWrapSpec import scala.collection.compat.immutable.ArraySeq package impl { import scalan.GraphIRReflection - import scalan.reflection.{RClass, RMethod} + import sigma.reflection.{RClass, RMethod} // Abs ----------------------------------- trait WRTypesDefs extends scalan.Scalan with WRTypes { @@ -99,7 +99,7 @@ class WRTypeCls extends EntityObject("WRType") { Elem.declaredWrapperMethods(_RTypeWrapSpec, RClass(classOf[WRType[A]]), Set("name")) } - override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.util.Invariant)) + override def buildTypeArgs = super.buildTypeArgs ++ TypeArgs("A" -> (eA -> scalan.core.Invariant)) } implicit final def wRTypeElement[A](implicit eA: Elem[A]): Elem[WRType[A]] = diff --git a/graph-ir/shared/src/main/scala/wrappers/special/WSpecialPredefs.scala b/sc/shared/src/main/scala/wrappers/special/WSpecialPredefs.scala similarity index 100% rename from graph-ir/shared/src/main/scala/wrappers/special/WSpecialPredefs.scala rename to sc/shared/src/main/scala/wrappers/special/WSpecialPredefs.scala diff --git a/graph-ir/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala b/sc/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala similarity index 97% rename from graph-ir/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala rename to sc/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala index 72b673553f..1f80e71676 100644 --- a/graph-ir/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala +++ b/sc/shared/src/main/scala/wrappers/special/impl/WSpecialPredefsImpl.scala @@ -5,7 +5,8 @@ import scalan._ import special.wrappers.WrappersModule package impl { - import scalan.reflection.RClass + import sigma.data.Nullable + import sigma.reflection.RClass // Abs ----------------------------------- trait WSpecialPredefsDefs extends scalan.Scalan with WSpecialPredefs { diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala index 22359c1606..73156ca1b8 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoAddressSpecification.scala @@ -6,13 +6,13 @@ import org.scalatest.{Assertion, TryValues} import scorex.crypto.hash.Blake2b256 import scorex.util.encode.Base58 import sigmastate.Values.{ByteArrayConstant, Constant, ErgoTree, IntConstant, UnparsedErgoTree} -import sigmastate.basics.DLogProtocol -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.DLogProtocol +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} import sigmastate.eval.InvalidType import sigmastate.helpers.TestingHelpers._ import sigmastate.helpers._ import sigmastate.interpreter.ContextExtension.VarBinding -import sigmastate.basics.CryptoConstants.dlogGroup +import sigmastate.crypto.CryptoConstants.dlogGroup import sigmastate.exceptions.CostLimitException import sigmastate.interpreter.Interpreter.{ScriptEnv, ScriptNameProp} import sigmastate.interpreter.{ContextExtension, CostedProverResult} @@ -21,7 +21,7 @@ import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer import sigmastate.serialization.{GroupElementSerializer, ValueSerializer} import sigmastate.utils.Helpers._ import sigmastate.{CompilerCrossVersionProps, SType, SigmaAnd} -import special.sigma.SigmaDslTesting +import sigma.SigmaDslTesting import java.math.BigInteger @@ -170,7 +170,7 @@ class ErgoAddressSpecification extends SigmaDslTesting assertExceptionThrown( ergoAddressEncoder.fromString(addrStr).getOrThrow, - t => t.getMessage.contains("Improper content in P2SH script: 41fKjb7zWNw") + t => t.getMessage.contains("Invalid length of the hash bytes in P2SH address: 41fKjb7zWNw") ) } @@ -228,7 +228,7 @@ class ErgoAddressSpecification extends SigmaDslTesting } def testPay2SHAddress(address: Pay2SHAddress, scriptBytes: Array[Byte]) = { - val scriptId = 1.toByte + val scriptId = Pay2SHAddress.scriptId val boxToSpend = testBox(10, address.script, creationHeight = 5) val ctx = ErgoLikeContextTesting.dummy(boxToSpend, activatedVersionInTests) .withExtension(ContextExtension(Seq( @@ -271,7 +271,7 @@ class ErgoAddressSpecification extends SigmaDslTesting res } - val scriptVarId = 1.toByte + val scriptVarId = Pay2SHAddress.scriptId val script = "{ 1 < 2 }" val prop = compile(Map.empty, script).asBoolValue.toSigmaProp val scriptBytes = ValueSerializer.serialize(prop) diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala index 25c01af43d..b8579ddedf 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala @@ -11,11 +11,12 @@ import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.serialization.SigmaSerializer import sigmastate.eval._ import sigmastate.eval.Extensions._ +import sigmastate._ import sigmastate.SType._ import sigmastate.helpers.TestingHelpers.copyTransaction import sigmastate.utils.Helpers -import special.sigma.SigmaDslTesting -import special.collection.Extensions._ +import sigma.SigmaDslTesting +import sigma.Extensions._ class ErgoLikeTransactionSpec extends SigmaDslTesting { diff --git a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala index 89247a968a..d017b6ca35 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala @@ -7,18 +7,19 @@ import org.ergoplatform.settings.MonetarySettings import org.scalacheck.Gen import scorex.crypto.hash.Blake2b256 import scorex.util.Random -import sigmastate.Values.{SigmaPropConstant, CollectionConstant, ByteArrayConstant, IntConstant, ErgoTree} +import sigma.Colls +import sigma.util.BenchmarkUtil.measure +import sigmastate.Values.{ByteArrayConstant, CollectionConstant, ErgoTree, IntConstant, SigmaPropConstant} import sigmastate._ -import sigmastate.basics.DLogProtocol.{ProveDlog, DLogProverInput} -import sigmastate.helpers.{ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons, ContextEnrichingTestProvingInterpreter} +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.{ScriptNameProp, emptyEnv} -import sigmastate.interpreter.{ProverResult, ContextExtension} +import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.lang.Terms.ValueOps import sigmastate.serialization.ValueSerializer -import sigmastate.utxo.{ExtractCreationInfo, ByIndex, SelectField} -import scalan.util.BenchmarkUtil._ -import sigmastate.eval.{Colls, Digest32Coll} +import sigmastate.utxo.{ByIndex, ExtractCreationInfo, SelectField} +import sigmastate.eval.Digest32Coll import sigmastate.utils.Helpers._ import scala.util.Try diff --git a/sc/shared/src/test/scala/org/ergoplatform/dsl/TestContractSpec.scala b/sc/shared/src/test/scala/org/ergoplatform/dsl/TestContractSpec.scala index 996db0e184..46668c3b1a 100644 --- a/sc/shared/src/test/scala/org/ergoplatform/dsl/TestContractSpec.scala +++ b/sc/shared/src/test/scala/org/ergoplatform/dsl/TestContractSpec.scala @@ -7,7 +7,7 @@ import sigmastate.interpreter.{CostedProverResult, ProverResult} import scala.collection.mutable.ArrayBuffer import org.ergoplatform.ErgoBox.{NonMandatoryRegisterId, TokenId} -import scalan.Nullable +import sigma.data.Nullable import scala.util.Try import org.ergoplatform.{ErgoBox, ErgoLikeContext} @@ -18,7 +18,7 @@ import sigmastate.eval.{CSigmaProp, Evaluation, IRContext, CAnyValue} import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} import sigmastate.helpers.TestingHelpers._ import sigmastate.lang.Terms.ValueOps -import special.sigma.{AnyValue, SigmaProp} +import sigma.{AnyValue, SigmaProp} case class TestContractSpec(testSuite: CompilerTestingCommons)(implicit val IR: IRContext) extends ContractSpec { diff --git a/graph-ir/shared/src/test/scala/scalan/BaseLiftableTests.scala b/sc/shared/src/test/scala/scalan/BaseLiftableTests.scala similarity index 100% rename from graph-ir/shared/src/test/scala/scalan/BaseLiftableTests.scala rename to sc/shared/src/test/scala/scalan/BaseLiftableTests.scala diff --git a/graph-ir/shared/src/test/scala/scalan/LibraryTests.scala b/sc/shared/src/test/scala/scalan/LibraryTests.scala similarity index 92% rename from graph-ir/shared/src/test/scala/scalan/LibraryTests.scala rename to sc/shared/src/test/scala/scalan/LibraryTests.scala index 299a1961cc..e082e9154d 100644 --- a/graph-ir/shared/src/test/scala/scalan/LibraryTests.scala +++ b/sc/shared/src/test/scala/scalan/LibraryTests.scala @@ -1,6 +1,6 @@ package scalan -import scalan.util.BenchmarkUtil._ +import sigma.util.BenchmarkUtil.{measure, measureTime} class Benchmark[T <: Scalan](createContext: => T) { val printDebugInfo: Boolean = false diff --git a/graph-ir/shared/src/test/scala/scalan/TestContexts.scala b/sc/shared/src/test/scala/scalan/TestContexts.scala similarity index 90% rename from graph-ir/shared/src/test/scala/scalan/TestContexts.scala rename to sc/shared/src/test/scala/scalan/TestContexts.scala index 2b01269672..a86bf42276 100644 --- a/graph-ir/shared/src/test/scala/scalan/TestContexts.scala +++ b/sc/shared/src/test/scala/scalan/TestContexts.scala @@ -1,7 +1,7 @@ package scalan -import scalan.reflection.RMethod -import special.CoreLibReflection +import sigma.reflection.RMethod +import sigma.{BaseNestedTests, BaseShouldTests, BaseTests, TestUtils} trait TestContexts extends TestUtils { @@ -35,7 +35,7 @@ trait TestContexts extends TestUtils { } abstract class BaseCtxTests extends BaseTests with TestContexts { - val reflection = (CoreLibReflection, GraphIRReflection) + val reflection = GraphIRReflection } abstract class BaseNestedCtxTests extends BaseNestedTests with TestContexts diff --git a/graph-ir/shared/src/test/scala/scalan/TestLibrary.scala b/sc/shared/src/test/scala/scalan/TestLibrary.scala similarity index 100% rename from graph-ir/shared/src/test/scala/scalan/TestLibrary.scala rename to sc/shared/src/test/scala/scalan/TestLibrary.scala diff --git a/graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtil.scala b/sc/shared/src/test/scala/scalan/core/ScalaNameUtil.scala similarity index 90% rename from graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtil.scala rename to sc/shared/src/test/scala/scalan/core/ScalaNameUtil.scala index 0f54e958c7..ac018b62a5 100644 --- a/graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtil.scala +++ b/sc/shared/src/test/scala/scalan/core/ScalaNameUtil.scala @@ -1,7 +1,7 @@ -package scalan.util +package scalan.core object ScalaNameUtil { - val opChars = Set('+', '-', '*', '/', ':', '>', '<', '=', '!', '@', '#', '%', + val opChars: Set[Char] = Set('+', '-', '*', '/', ':', '>', '<', '=', '!', '@', '#', '%', '&', '~', '?', '|', '\\', '^') def cleanNestedClassName(className: String): String = diff --git a/graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtilSuite.scala b/sc/shared/src/test/scala/scalan/core/ScalaNameUtilSuite.scala similarity index 85% rename from graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtilSuite.scala rename to sc/shared/src/test/scala/scalan/core/ScalaNameUtilSuite.scala index 5c597a216c..15fad91b54 100644 --- a/graph-ir/shared/src/test/scala/scalan/util/ScalaNameUtilSuite.scala +++ b/sc/shared/src/test/scala/scalan/core/ScalaNameUtilSuite.scala @@ -1,8 +1,8 @@ -package scalan.util +package scalan.core -import scalan.BaseTests -import scalan.reflection.CommonReflection.registerClassEntry -import scalan.reflection.{RClass, mkMethod} +import sigma.BaseTests +import sigma.reflection.ReflectionData.registerClassEntry +import sigma.reflection.{RClass, mkMethod} class ScalaNameUtilSuite extends BaseTests { def +\() = ??? diff --git a/graph-ir/shared/src/test/scala/special/collections/CollsStagingTests.scala b/sc/shared/src/test/scala/sigma/CollsStagingTests.scala similarity index 92% rename from graph-ir/shared/src/test/scala/special/collections/CollsStagingTests.scala rename to sc/shared/src/test/scala/sigma/CollsStagingTests.scala index 7abe786b04..3b56920c8d 100644 --- a/graph-ir/shared/src/test/scala/special/collections/CollsStagingTests.scala +++ b/sc/shared/src/test/scala/sigma/CollsStagingTests.scala @@ -1,8 +1,9 @@ -package special.collections +package sigma import scala.language.reflectiveCalls import special.wrappers.WrappersTests import scalan._ +import sigma.data.CollOverArrayBuilder class CollsStagingTests extends WrappersTests { val printDebugInfo: Boolean = false @@ -47,7 +48,7 @@ class CollsStagingTests extends WrappersTests { import EnvRep._ import Liftables._ - val Cols: SCollBuilder = new special.collection.CollOverArrayBuilder + val Cols: SCollBuilder = new CollOverArrayBuilder val arr = Array(1, 2, 3) val col = Cols.fromArray(arr) @@ -63,7 +64,7 @@ class CollsStagingTests extends WrappersTests { import Coll._ import CollBuilder._ - val Cols: SCollBuilder = new special.collection.CollOverArrayBuilder + val Cols: SCollBuilder = new CollOverArrayBuilder val colData = Cols.replicate(10, 10) val colSym = colBuilder.replicate(10, 10) val resSym = colSym.append(colSym) diff --git a/sc/shared/src/test/scala/special/sigma/DataValueComparerSpecification.scala b/sc/shared/src/test/scala/sigma/DataValueComparerSpecification.scala similarity index 98% rename from sc/shared/src/test/scala/special/sigma/DataValueComparerSpecification.scala rename to sc/shared/src/test/scala/sigma/DataValueComparerSpecification.scala index eaca756182..df3c5dc7ed 100644 --- a/sc/shared/src/test/scala/special/sigma/DataValueComparerSpecification.scala +++ b/sc/shared/src/test/scala/sigma/DataValueComparerSpecification.scala @@ -1,14 +1,14 @@ -package special.sigma +package sigma import org.scalatest.BeforeAndAfterAll -import scalan.RType -import scalan.util.BenchmarkUtil +import sigma.data.RType +import sigma.util.BenchmarkUtil import sigmastate.{DataValueComparer, JitCost, TrivialProp} import sigmastate.Values.ErgoTree import sigmastate.eval.{CSigmaProp, Profiler, SigmaDsl} import sigmastate.helpers.SigmaPPrint import sigmastate.interpreter.{CostAccumulator, ErgoTreeEvaluator, EvalSettings, TracedCost} -import special.collection.Coll +import sigma.Coll import scala.util.{Success, Try} diff --git a/sc/shared/src/test/scala/special/sigma/LoopTests.scala b/sc/shared/src/test/scala/sigma/LoopTests.scala similarity index 98% rename from sc/shared/src/test/scala/special/sigma/LoopTests.scala rename to sc/shared/src/test/scala/sigma/LoopTests.scala index 37ff177c8e..ae1b2438f0 100644 --- a/sc/shared/src/test/scala/special/sigma/LoopTests.scala +++ b/sc/shared/src/test/scala/sigma/LoopTests.scala @@ -1,4 +1,4 @@ -package special.sigma +package sigma import sigmastate.helpers.CompilerTestingCommons diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala b/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala similarity index 99% rename from sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala rename to sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala index ead1af1873..f5c47a055f 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslSpecification.scala +++ b/sc/shared/src/test/scala/sigma/SigmaDslSpecification.scala @@ -3,43 +3,45 @@ package special.sigma import java.math.BigInteger import org.ergoplatform._ import org.ergoplatform.settings.ErgoAlgos -import org.scalacheck.{Gen, Arbitrary} -import scalan.{ExactOrdering, RType, ExactIntegral, ExactNumeric} +import org.scalacheck.{Arbitrary, Gen} +import sigma.data.{ExactIntegral, ExactNumeric, ExactOrdering, RType} import scorex.crypto.authds.avltree.batch._ -import scorex.crypto.authds.{ADDigest, ADValue, ADKey} +import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash.{Blake2b256, Digest32} -import scalan.util.Extensions._ +import sigma.util.Extensions._ import sigmastate.utils.Extensions._ import sigmastate.SCollection._ import sigmastate.Values.IntConstant import sigmastate._ -import sigmastate.basics.DLogProtocol._ +import sigmastate.crypto.DLogProtocol._ import sigmastate.Values._ import sigmastate.lang.Terms.Apply import sigmastate.eval.Extensions._ import sigmastate.eval._ import sigmastate.lang.Terms.{MethodCall, PropertyCall} import sigmastate.utxo._ -import special.collection._ -import special.collection.Extensions._ +import sigma._ +import sigma.Extensions._ import sigmastate.serialization.OpCodes.OpCode import sigmastate.utils.Helpers import sigmastate.utils.Helpers._ import sigmastate.helpers.TestingHelpers._ -import scala.util.{Try, Success, Failure} +import scala.util.{Failure, Success, Try} import OrderingOps._ import org.ergoplatform.ErgoBox.AdditionalRegisters import org.scalacheck.Arbitrary._ import org.scalacheck.Gen.frequency import org.scalatest.{BeforeAndAfterAll, Tag} -import scalan.RType._ +import sigma.data.RType._ import scorex.util.ModifierId -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.ProveDHTuple import sigmastate.interpreter._ import org.scalactic.source.Position +import sigma.VersionContext import sigmastate.helpers.SigmaPPrint import sigmastate.exceptions.GraphBuildingException + import scala.collection.compat.immutable.ArraySeq /** This suite tests every method of every SigmaDsl type to be equivalent to @@ -6889,7 +6891,7 @@ class SigmaDslSpecification extends SigmaDslTesting )), preGeneratedSamples = Some(samples)) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.forall_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.forall_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq((Coll[Box](), Expected(error))), existingFeature[Coll[Box], Boolean]({ (x: Coll[Box]) => throw error }, @@ -6965,7 +6967,7 @@ class SigmaDslSpecification extends SigmaDslTesting )), preGeneratedSamples = Some(samples)) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq((Coll[Box](), Expected(error))), existingFeature[Coll[Box], Boolean]({ (x: Coll[Box]) => throw error }, @@ -7070,7 +7072,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) ))) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( (Coll[BigInt](), Expected(error)) ), existingFeature[Coll[BigInt], Boolean]( @@ -7185,7 +7187,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) ))) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.exist_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( (Coll[BigInt](), Expected(error)) ), existingFeature[Coll[BigInt], Boolean]( @@ -7793,7 +7795,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) ))) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,java.lang.Object,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,java.lang.Object,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( ((Coll[Byte](), 0), Expected(error)) ), existingFeature[(Coll[Byte], Int), Int]( @@ -8071,7 +8073,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) ) )) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,int,int,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,int,int,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( ((Coll[Byte](), 0), Expected(error)) ), existingFeature( @@ -8737,7 +8739,7 @@ class SigmaDslSpecification extends SigmaDslTesting )), preGeneratedSamples = Some(samples)) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.slice_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,int,int,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.slice_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,int,int,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( (Coll[Int](), (-1, 0)) -> Expected(error) ), existingFeature({ (x: (Coll[Int], (Int, Int))) => throw error; x._1.slice(x._2._1, x._2._2) }, @@ -8816,7 +8818,7 @@ class SigmaDslSpecification extends SigmaDslTesting ) ))) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.append_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,special.collection.Coll,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.append_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,sigma.Coll,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( (Coll[Int](), Coll[Int]()) -> Expected(error) ), existingFeature( @@ -9714,10 +9716,10 @@ class SigmaDslSpecification extends SigmaDslTesting }, changedFeature( { (x: (Coll[Byte], Int)) => - SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(RType.AnyType)) + SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(sigma.AnyType)) }, { (x: (Coll[Byte], Int)) => - SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(RType.AnyType)) + SigmaDsl.substConstants(x._1, Coll[Int](x._2), Coll[Any](SigmaDsl.sigmaProp(false))(sigma.AnyType)) }, "{ (x: (Coll[Byte], Int)) => substConstants[Any](x._1, Coll[Int](x._2), Coll[Any](sigmaProp(false))) }", FuncValue( @@ -9946,7 +9948,7 @@ class SigmaDslSpecification extends SigmaDslTesting preGeneratedSamples = Some(Seq.empty) ) } else { - def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,special.collection.Coll,java.lang.Object,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") + def error = new java.lang.NoSuchMethodException("sigmastate.SCollection$.fold_eval(sigmastate.lang.Terms$MethodCall,sigma.Coll,java.lang.Object,scala.Function1,sigmastate.interpreter.ErgoTreeEvaluator))") verifyCases( Seq( (keys, initial) -> Expected(error) ), existingFeature[(Coll[Coll[Byte]], Coll[Byte]), Coll[Byte]]( diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslStaginTests.scala b/sc/shared/src/test/scala/sigma/SigmaDslStaginTests.scala similarity index 91% rename from sc/shared/src/test/scala/special/sigma/SigmaDslStaginTests.scala rename to sc/shared/src/test/scala/sigma/SigmaDslStaginTests.scala index 40e53bd860..ea29c47745 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslStaginTests.scala +++ b/sc/shared/src/test/scala/sigma/SigmaDslStaginTests.scala @@ -1,13 +1,12 @@ -package special.sigma +package sigma -import org.scalatest.{BeforeAndAfterAll} -import special.collection._ - -import scala.language.reflectiveCalls +import org.scalatest.BeforeAndAfterAll import scalan.{BaseCtxTests, BaseLiftableTests} -import sigmastate.{VersionContext, eval, TrivialProp} import sigmastate.eval.Extensions._ import sigmastate.eval._ +import sigmastate.{TrivialProp, eval} + +import scala.language.reflectiveCalls class SigmaDslStaginTests extends BaseCtxTests with ErgoScriptTestkit with BaseLiftableTests with BeforeAndAfterAll { class Ctx extends TestContext with IRContext with LiftableTestKit { @@ -16,13 +15,13 @@ class SigmaDslStaginTests extends BaseCtxTests with ErgoScriptTestkit with BaseL test("invokeUnlifted") { val cake = new Ctx import cake._ - import Liftables._ - import Context._ - import Coll._ import Box._ - import SigmaProp._ - import SigmaDslBuilder._ + import Coll._ + import Context._ import EnvRep._ + import Liftables._ + import SigmaDslBuilder._ + import SigmaProp._ val dsl: SSigmaDslBuilder = eval.SigmaDsl type RSigmaDslBuilder = cake.SigmaDslBuilder @@ -46,7 +45,7 @@ class SigmaDslStaginTests extends BaseCtxTests with ErgoScriptTestkit with BaseL cake.check(boxA1, { env: EnvRep[RBox] => for { obj <- env } yield obj.value }, boxA1.value) cake.check(boxA1, { env: EnvRep[RBox] => for { obj <- env } yield obj.creationInfo }, boxA1.creationInfo) - cake.check(boxA1, { env: EnvRep[RBox] => for { obj <- env; arg <- lifted(1) } yield obj.getReg[Coll[Byte]](arg) }, boxA1.getReg[special.collection.Coll[Byte]](1)) + cake.check(boxA1, { env: EnvRep[RBox] => for { obj <- env; arg <- lifted(1) } yield obj.getReg[Coll[Byte]](arg) }, boxA1.getReg[sigma.Coll[Byte]](1)) } diff --git a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala b/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala similarity index 98% rename from sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala rename to sc/shared/src/test/scala/sigma/SigmaDslTesting.scala index 1630e7f8a9..4aff49761e 100644 --- a/sc/shared/src/test/scala/special/sigma/SigmaDslTesting.scala +++ b/sc/shared/src/test/scala/sigma/SigmaDslTesting.scala @@ -1,4 +1,4 @@ -package special.sigma +package sigma import debox.cfor import org.ergoplatform._ @@ -13,16 +13,15 @@ import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import scalan.Platform.threadSleepOrNoOp -import scalan.RType -import scalan.RType._ -import scalan.util.BenchmarkUtil -import scalan.util.CollectionUtil._ -import scalan.util.Extensions._ -import scalan.util.StringUtil.StringUtilExtensions +import sigma.data.{CollType, OptionType, PairType, RType} +import sigma.util.BenchmarkUtil +import sigma.util.CollectionUtil._ +import sigma.util.Extensions._ +import sigma.util.StringUtil.StringUtilExtensions import sigmastate.SType.AnyOps import sigmastate.Values.{ByteArrayConstant, Constant, ConstantNode, ErgoTree, IntConstant, SValue} -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} -import sigmastate.basics.SigmaProtocolPrivateInput +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.SigmaProtocolPrivateInput import sigmastate.eval.Extensions._ import sigmastate.eval.{CompiletimeIRContext, CostingBox, CostingDataContext, Evaluation, IRContext, SigmaDsl} import sigmastate.helpers.TestingHelpers._ @@ -34,10 +33,8 @@ import sigmastate.serialization.ValueSerializer import sigmastate.serialization.generators.ObjectGenerators import sigmastate.utils.Helpers._ import sigmastate.utxo.{DeserializeContext, DeserializeRegister, GetVar, OptionGet} -import sigmastate.{SOption, SSigmaProp, SType, SigmaLeaf, VersionContext, eval} -import special.collection.{Coll, CollType} +import sigmastate.{SOption, SSigmaProp, SType, SigmaLeaf, eval} -import java.util import scala.collection.mutable import scala.reflect.ClassTag import scala.util.{Failure, Success, Try} @@ -274,7 +271,7 @@ class SigmaDslTesting extends AnyPropSpec val txOutputCandidates = ctx.outputs.toArray.map(SigmaDsl.toErgoBox) val tx = new ErgoLikeTransaction( txInputs, txDataInputs, txOutputCandidates.toIndexedSeq) - val selfIndex = boxesToSpend.indexWhere(b => util.Arrays.equals(b.id, ctx.selfBox.id.toArray)) + val selfIndex = boxesToSpend.indexWhere(b => java.util.Arrays.equals(b.id, ctx.selfBox.id.toArray)) val extension = ContextExtension( values = ctx.vars.toArray.zipWithIndex.collect { @@ -351,7 +348,7 @@ class SigmaDslTesting extends AnyPropSpec ) // We add ctx as it's own variable with id = 1 - val ctxVar = eval.Extensions.toAnyValue[special.sigma.Context](ctx)(special.sigma.ContextRType) + val ctxVar = eval.Extensions.toAnyValue[sigma.Context](ctx)(sigma.ContextRType) val carolVar = eval.Extensions.toAnyValue[Coll[Byte]](pkCarolBytes.toColl)(RType[Coll[Byte]]) val newCtx = ctx .withUpdatedVars(1 -> ctxVar, 2 -> carolVar) diff --git a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala index 7bffa895f8..23406d9cb4 100644 --- a/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala @@ -3,11 +3,12 @@ package sigmastate import org.ergoplatform.settings.ErgoAlgos import org.ergoplatform.validation.{ValidationException, ValidationRules} import org.ergoplatform.{ErgoAddressEncoder, ErgoBox, ErgoLikeContext, Self} -import scalan.RType.asType -import scalan.{Nullable, RType} +import sigma.data.RType.asType +import sigma.data.{Nullable, RType} +import sigma.VersionContext import sigmastate.SCollection.{SByteArray, checkValidFlatmap} import sigmastate.Values._ -import sigmastate.VersionContext._ +import sigma.VersionContext._ import sigmastate.eval.{CostingBox, Evaluation, Profiler} import sigmastate.exceptions.{CostLimitException, InterpreterException} import sigmastate.helpers.{ErgoLikeContextTesting, SigmaPPrint} @@ -18,8 +19,8 @@ import sigmastate.lang.Terms._ import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer import sigmastate.utils.Helpers.TryOps import sigmastate.utxo._ -import special.collection._ -import special.sigma.{ContractsTestkit, SigmaDslTesting} +import sigma._ +import sigma.{ContractsTestkit, SigmaDslTesting} /** Regression tests with ErgoTree related test vectors. diff --git a/sc/shared/src/test/scala/sigmastate/ScriptVersionSwitchSpecification.scala b/sc/shared/src/test/scala/sigmastate/ScriptVersionSwitchSpecification.scala index d73e81f56a..ad5af68649 100644 --- a/sc/shared/src/test/scala/sigmastate/ScriptVersionSwitchSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/ScriptVersionSwitchSpecification.scala @@ -5,7 +5,7 @@ import org.ergoplatform._ import scorex.util.ModifierId import sigmastate.Values.ErgoTree.{DefaultHeader, updateVersionBits} import sigmastate.Values._ -import sigmastate.VersionContext.MaxSupportedScriptVersion +import sigma.VersionContext.MaxSupportedScriptVersion import sigmastate.eval._ import sigmastate.exceptions.InterpreterException import sigmastate.helpers.{ErgoLikeContextTesting, ErgoLikeTestInterpreter} @@ -15,7 +15,7 @@ import sigmastate.interpreter.EvalSettings.EvaluationMode import sigmastate.interpreter.{CostedProverResult, ErgoTreeEvaluator, EvalSettings, Interpreter, ProverResult} import sigmastate.lang.Terms.ValueOps import sigmastate.utils.Helpers._ -import special.sigma.{Box, SigmaDslTesting} +import sigma.{Box, SigmaDslTesting} /** Specification to verify that the interpreter behaves according to docs/aot-jit-switch.md. * diff --git a/sc/shared/src/test/scala/sigmastate/SoftForkabilitySpecification.scala b/sc/shared/src/test/scala/sigmastate/SoftForkabilitySpecification.scala index e671f503b0..c46b5a3119 100644 --- a/sc/shared/src/test/scala/sigmastate/SoftForkabilitySpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/SoftForkabilitySpecification.scala @@ -7,7 +7,6 @@ import org.scalatest.BeforeAndAfterAll import sigmastate.SPrimType.MaxPrimTypeCode import sigmastate.Values.ErgoTree.EmptyConstants import sigmastate.Values.{ByteArrayConstant, ErgoTree, IntConstant, NotReadyValueInt, UnparsedErgoTree, ValueCompanion} -import sigmastate.eval.Colls import sigmastate.exceptions.{InterpreterException, SerializerException} import sigmastate.helpers.TestingHelpers._ import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter} @@ -20,7 +19,7 @@ import sigmastate.serialization.SigmaSerializer.startReader import sigmastate.serialization._ import sigmastate.utils.Helpers._ import sigmastate.utxo.DeserializeContext -import special.sigma.SigmaTestingData +import sigma.{Colls, SigmaTestingData} class SoftForkabilitySpecification extends SigmaTestingData with CompilerTestingCommons diff --git a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala index 51e6fd9556..2398a48535 100644 --- a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala @@ -1,17 +1,17 @@ package sigmastate -import sigmastate.basics.DLogProtocol.{ProveDlog, DLogProverInput} +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} import scorex.crypto.hash.Blake2b256 import sigmastate.Values._ import sigmastate.interpreter._ -import scalan.util.Extensions._ import Interpreter._ import sigmastate.lang.Terms._ import org.ergoplatform._ import org.scalatest.BeforeAndAfterAll import scorex.util.encode.Base58 -import sigmastate.basics.CryptoConstants -import sigmastate.helpers.{ErgoLikeTestInterpreter, CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestProvingInterpreter} +import sigma.util.Extensions.IntOps +import sigmastate.crypto.CryptoConstants +import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.serialization.ValueSerializer import sigmastate.utils.Helpers._ diff --git a/sc/shared/src/test/scala/sigmastate/TypesSpecification.scala b/sc/shared/src/test/scala/sigmastate/TypesSpecification.scala index 6ae4bd2a21..3d5edf22f2 100644 --- a/sc/shared/src/test/scala/sigmastate/TypesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/TypesSpecification.scala @@ -1,8 +1,9 @@ package sigmastate +import sigma.Environment import sigmastate.SType.isValueOfType import sigmastate.eval.{CSigmaProp, CostingSigmaDslBuilder} -import special.sigma.SigmaTestingData +import sigma.SigmaTestingData class TypesSpecification extends SigmaTestingData { diff --git a/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala b/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala index 04230fdef9..5d949d65fc 100644 --- a/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala +++ b/sc/shared/src/test/scala/sigmastate/eval/ErgoScriptTestkit.scala @@ -4,6 +4,7 @@ import org.ergoplatform.ErgoAddressEncoder.TestnetNetworkPrefix import org.ergoplatform.validation.ValidationSpecification import org.ergoplatform.{Context => _, _} import scalan.BaseCtxTests +import sigma.VersionContext import sigmastate.Values.{BigIntArrayConstant, EvaluatedValue, SValue, SigmaPropConstant, Value} import sigmastate.helpers.TestingHelpers._ import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting} @@ -12,8 +13,8 @@ import sigmastate.interpreter.{ContextExtension, ErgoTreeEvaluator} import sigmastate.lang.Terms.ValueOps import sigmastate.lang.{CompilerResult, CompilerSettings, LangTests, SigmaCompiler} import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer -import sigmastate.{AvlTreeData, CompilerTestsBase, SType, VersionContext} -import special.sigma.{ContractsTestkit, Context => DContext} +import sigmastate.{AvlTreeData, CompilerTestsBase, SType} +import sigma.{ContractsTestkit, Context => DContext} import scala.annotation.unused import scala.util.Success diff --git a/sc/shared/src/test/scala/sigmastate/eval/EvaluationTest.scala b/sc/shared/src/test/scala/sigmastate/eval/EvaluationTest.scala index 4ef470d172..9aefb272b6 100644 --- a/sc/shared/src/test/scala/sigmastate/eval/EvaluationTest.scala +++ b/sc/shared/src/test/scala/sigmastate/eval/EvaluationTest.scala @@ -7,9 +7,9 @@ import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ import scalan.BaseCtxTests import sigmastate.lang.LangTests -import scalan.util.BenchmarkUtil._ +import sigma.util.BenchmarkUtil._ import sigmastate._ -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer class EvaluationTest extends BaseCtxTests diff --git a/sc/shared/src/test/scala/sigmastate/eval/MeasureIRContext.scala b/sc/shared/src/test/scala/sigmastate/eval/MeasureIRContext.scala index 267fee8eff..9f88588cc9 100644 --- a/sc/shared/src/test/scala/sigmastate/eval/MeasureIRContext.scala +++ b/sc/shared/src/test/scala/sigmastate/eval/MeasureIRContext.scala @@ -1,7 +1,7 @@ package sigmastate.eval import scalan.{BaseCtxTests, Benchmark} -import scalan.util.BenchmarkUtil.measure +import sigma.util.BenchmarkUtil.measure object MeasureIRContext extends App { var ctx: RuntimeIRContext = null diff --git a/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala b/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala index 588dfe4f96..ed86bb86ed 100644 --- a/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala +++ b/sc/shared/src/test/scala/sigmastate/helpers/CompilerTestingCommons.scala @@ -6,8 +6,10 @@ import org.ergoplatform.validation.{ValidationException, ValidationSpecification import org.scalacheck.Arbitrary.arbByte import org.scalacheck.Gen import org.scalatest.Assertion -import scalan.util.BenchmarkUtil -import scalan.{RType, TestContexts, TestUtils} +import sigma.util.BenchmarkUtil +import scalan.TestContexts +import sigma.{Colls, TestUtils} +import sigma.data.RType import sigmastate.Values.{Constant, ErgoTree, SValue, SigmaBoolean, SigmaPropValue} import sigmastate.eval._ import sigmastate.helpers.TestingHelpers._ @@ -55,13 +57,13 @@ trait CompilerTestingCommons extends TestingCommons // (ctx.HEIGHT method call compiled to Height IR node) // ------- // We add ctx as it's own variable with id = 1 - val ctxVar = Extensions.toAnyValue[special.sigma.Context](ctx)(special.sigma.ContextRType) + val ctxVar = Extensions.toAnyValue[sigma.Context](ctx)(sigma.ContextRType) val newVars = if (ctx.vars.length < 2) { val vars = ctx.vars.toArray - val buf = new Array[special.sigma.AnyValue](2) + val buf = new Array[sigma.AnyValue](2) Array.copy(vars, 0, buf, 0, vars.length) buf(1) = ctxVar - CostingSigmaDslBuilder.Colls.fromArray(buf) + Colls.fromArray(buf) } else { ctx.vars.updated(1, ctxVar) } diff --git a/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala b/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala index 38ae6c6740..690630d327 100644 --- a/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala +++ b/sc/shared/src/test/scala/sigmastate/helpers/SigmaPPrint.scala @@ -1,25 +1,23 @@ package sigmastate.helpers -import java.math.BigInteger import org.ergoplatform.ErgoBox import org.ergoplatform.ErgoBox.RegisterId import org.ergoplatform.settings.ErgoAlgos import pprint.{PPrinter, Tree} -import scalan.RType -import scalan.RType.PrimitiveType +import sigma.data.{CollType, PrimitiveType} +import sigma.{Coll, GroupElement} import sigmastate.SCollection._ import sigmastate.Values.{ConstantNode, ErgoTree, FuncValue, ValueCompanion} import sigmastate._ +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.crypto.GF2_192_Poly -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.interpreter.{CompanionDesc, FixedCostItem, MethodDesc} import sigmastate.lang.Terms import sigmastate.lang.Terms.MethodCall import sigmastate.serialization.GroupElementSerializer import sigmastate.utxo.SelectField -import sigmastate.interpreter.{CompanionDesc, ErgoTreeEvaluator, FixedCostItem, MethodDesc} -import special.collection.{Coll, CollType} -import special.sigma.GroupElement +import java.math.BigInteger import scala.collection.compat.immutable.ArraySeq import scala.collection.mutable import scala.collection.mutable.ArrayBuffer @@ -147,7 +145,7 @@ object SigmaPPrint extends PPrinter { case Some(v) => Tree.Apply("Some", treeifyMany(v)) - case coll: Coll[Byte @unchecked] if coll.tItem == RType.ByteType => + case coll: Coll[Byte @unchecked] if coll.tItem == sigma.ByteType => val hexString = ErgoAlgos.encode(coll) Tree.Apply("Helpers.decodeBytes", treeifyMany(hexString)) diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala index f6266cf285..129f096d85 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaCompilerTest.scala @@ -5,13 +5,15 @@ import org.ergoplatform._ import scorex.util.encode.Base58 import sigmastate.Values._ import sigmastate._ +import sigmastate.exceptions.{GraphBuildingException, InvalidArguments, TyperException} import sigmastate.helpers.CompilerTestingCommons import sigmastate.interpreter.Interpreter.ScriptEnv -import sigmastate.lang.Terms.{Apply, Ident, Lambda, MethodCall, ZKProofBlock} -import sigmastate.exceptions.{GraphBuildingException, InvalidArguments, TyperException} +import sigmastate.lang.Terms.{Apply, MethodCall, ZKProofBlock} import sigmastate.serialization.ValueSerializer import sigmastate.serialization.generators.ObjectGenerators -import sigmastate.utxo.{ByIndex, ExtractAmount, GetVar, SelectField} +import sigmastate.utxo.{ByIndex, ExtractAmount, GetVar} + +import scala.annotation.unused class SigmaCompilerTest extends CompilerTestingCommons with LangTests with ObjectGenerators { import CheckingSigmaBuilder._ @@ -22,11 +24,11 @@ class SigmaCompilerTest extends CompilerTestingCommons with LangTests with Objec private def comp(env: ScriptEnv, x: String): Value[SType] = compile(env, x) private def comp(x: String): Value[SType] = compile(env, x) - private def testMissingCosting(script: String, expected: SValue): Unit = { + private def testMissingCosting(script: String, @unused expected: SValue): Unit = { an [GraphBuildingException] should be thrownBy comp(env, script) } - private def testMissingCostingWOSerialization(script: String, expected: SValue): Unit = { + private def testMissingCostingWOSerialization(script: String, @unused expected: SValue): Unit = { an [GraphBuildingException] should be thrownBy comp(env, script) } diff --git a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala index 85476c3c6d..b12938db03 100644 --- a/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala +++ b/sc/shared/src/test/scala/sigmastate/lang/SigmaTyperTest.scala @@ -5,12 +5,12 @@ import org.ergoplatform._ import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks +import sigma.Colls import sigmastate.SCollection._ import sigmastate.Values._ import sigmastate._ -import sigmastate.basics.CryptoConstants -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} -import sigmastate.eval.Colls +import sigmastate.crypto.CryptoConstants +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} import sigmastate.exceptions.TyperException import sigmastate.interpreter.Interpreter.ScriptEnv import sigmastate.lang.SigmaPredef._ @@ -59,7 +59,7 @@ class SigmaTyperTest extends AnyPropSpec sourceContext.line shouldBe expectedLine sourceContext.column shouldBe expectedCol true - case pe: ParserException => true + case _: ParserException => true case t => throw t }) } diff --git a/sc/shared/src/test/scala/sigmastate/serialization/DeserializationResilience.scala b/sc/shared/src/test/scala/sigmastate/serialization/DeserializationResilience.scala index 3a04397881..52ef46c642 100644 --- a/sc/shared/src/test/scala/sigmastate/serialization/DeserializationResilience.scala +++ b/sc/shared/src/test/scala/sigmastate/serialization/DeserializationResilience.scala @@ -4,21 +4,22 @@ import org.ergoplatform.validation.ValidationException import org.ergoplatform.validation.ValidationRules.CheckPositionLimit import org.ergoplatform.{ErgoBoxCandidate, Outputs} import org.scalacheck.Gen -import scalan.util.BenchmarkUtil +import sigma.util.BenchmarkUtil import scorex.crypto.authds.avltree.batch.{BatchAVLProver, Insert} import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash.{Blake2b256, Digest32} import scorex.util.serialization.{Reader, VLQByteBufferReader} +import sigma.{Colls, Environment} import sigmastate.Values.{BlockValue, GetVarInt, IntConstant, SValue, SigmaBoolean, SigmaPropValue, Tuple, ValDef, ValUse} import sigmastate._ -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.eval.Extensions._ import sigmastate.eval._ import sigmastate.exceptions.{DeserializeCallDepthExceeded, InvalidTypePrefix, ReaderPositionLimitExceeded, SerializerException} import sigmastate.helpers.{CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.interpreter.{ContextExtension, CostedProverResult} import sigmastate.serialization.OpCodes._ -import sigmastate.util.safeNewArray +import sigma.util.safeNewArray import sigmastate.utils.Helpers._ import sigmastate.utils.SigmaByteReader import sigmastate.utxo.SizeOf @@ -412,7 +413,7 @@ class DeserializationResilience extends DeserializationResilienceTesting { val v = k avlProver.performOneOperation(Insert(ADKey @@@ k, ADValue @@@ v)) val proof = avlProver.generateProof() - val verifier = tree.createVerifier(Colls.fromArray(proof)) + val verifier = AvlTreeVerifier(tree, Colls.fromArray(proof)) verifier.performOneOperation(Insert(ADKey @@@ k, ADValue @@@ v)).isFailure shouldBe true // NOTE, even though performOneOperation fails, some AvlTree$ methods used in Interpreter // (remove_eval, update_eval, contains_eval) won't throw, while others will. diff --git a/sc/shared/src/test/scala/sigmastate/utils/GenInfoObjects.scala b/sc/shared/src/test/scala/sigmastate/utils/GenInfoObjects.scala index 41579fae61..9ebdce9f31 100644 --- a/sc/shared/src/test/scala/sigmastate/utils/GenInfoObjects.scala +++ b/sc/shared/src/test/scala/sigmastate/utils/GenInfoObjects.scala @@ -1,7 +1,7 @@ package sigmastate.utils import sigmastate.SMethod -import scalan.util.PrintExtensions._ +import sigma.util.PrintExtensions._ import scala.util.Try import Helpers._ // required for Scala 2.11 diff --git a/sc/shared/src/test/scala/sigmastate/utils/SpecGen.scala b/sc/shared/src/test/scala/sigmastate/utils/SpecGen.scala index cd2106e5c0..7eccb1dd00 100644 --- a/sc/shared/src/test/scala/sigmastate/utils/SpecGen.scala +++ b/sc/shared/src/test/scala/sigmastate/utils/SpecGen.scala @@ -1,17 +1,18 @@ package sigmastate.utils +import sigma.util.PrintExtensions.IterableExtensions import sigmastate._ import sigmastate.eval.Evaluation._ -import scalan.util.Extensions.ByteOps -import scalan.util.CollectionUtil -import scalan.util.PrintExtensions._ +import sigma.util.Extensions.ByteOps +import sigma.util.CollectionUtil +import sigma.util.PrintExtensions._ import sigmastate.Values._ -import sigmastate.lang.SigmaPredef.{PredefinedFuncRegistry, PredefinedFunc} +import sigmastate.lang.SigmaPredef.{PredefinedFunc, PredefinedFuncRegistry} import sigmastate.lang.StdSigmaBuilder import sigmastate.lang.Terms.{MethodCall, PropertyCall} import sigmastate.serialization.OpCodes.OpCode -import sigmastate.serialization.{ValueSerializer, OpCodes} -import sigmastate.utxo.{SigmaPropIsProven, SelectField} +import sigmastate.serialization.{OpCodes, ValueSerializer} +import sigmastate.utxo.{SelectField, SigmaPropIsProven} object SpecGenUtils { val types = SType.allPredefTypes.diff(Seq(SString)) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala index 9fd017eeae..5133692685 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/AVLTreeScriptsSpecification.scala @@ -17,8 +17,8 @@ import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp import sigmastate.interpreter.ProverResult import sigmastate.lang.Terms._ -import special.collection.Coll -import special.sigma.{AvlTree, Context} +import sigma.Coll +import sigma.{AvlTree, Context} class AVLTreeScriptsSpecification extends CompilerTestingCommons diff --git a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala index 9372a59e5e..eddd607178 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala @@ -3,7 +3,7 @@ package sigmastate.utxo import java.math.BigInteger import org.ergoplatform.ErgoBox.{AdditionalRegisters, R6, R8} import org.ergoplatform._ -import scalan.RType +import sigma.data.RType import sigmastate.SCollection.SByteArray import sigmastate.Values._ import sigmastate._ @@ -13,13 +13,13 @@ import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ import sigmastate.lang.Terms._ import SType.AnyOps -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.eval.{CAnyValue, InvalidType} import sigmastate.interpreter.ContextExtension.VarBinding import sigmastate.interpreter.ErgoTreeEvaluator.DefaultEvalSettings import sigmastate.interpreter.EvalSettings import sigmastate.utils.Helpers._ -import scalan.util.StringUtil._ +import sigma.util.StringUtil._ class BasicOpsSpecification extends CompilerTestingCommons with CompilerCrossVersionProps { @@ -338,7 +338,7 @@ class BasicOpsSpecification extends CompilerTestingCommons val dataVar = (lastExtVar + 1).toByte val Colls = IR.sigmaDslBuilderValue.Colls - implicit val eAny = RType.AnyType + implicit val eAny = sigma.AnyType val data = Colls.fromItems((Array[Byte](1,2,3).toColl, 10L)) val env1 = env + ("dataVar" -> CAnyValue(dataVar)) val dataType = SCollection(STuple(SByteArray, SLong)) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala index c76606ed96..6c84a5f54f 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ContextEnrichingSpecification.scala @@ -6,7 +6,7 @@ import sigmastate.Values._ import sigmastate._ import sigmastate.lang.Terms._ import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} -import special.collection.Coll +import sigma.Coll class ContextEnrichingSpecification extends CompilerTestingCommons diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala index 7f2cc3ac33..58bbb522c6 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ErgoLikeInterpreterSpecification.scala @@ -12,8 +12,8 @@ import sigmastate._ import sigmastate.eval._ import sigmastate.eval.Extensions._ import sigmastate.interpreter.Interpreter._ -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.ProveDHTuple +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.ProveDHTuple import sigmastate.helpers._ import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.ContextExtension.VarBinding @@ -742,7 +742,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons } property("non-const ProveDHT") { - import sigmastate.basics.CryptoConstants.dlogGroup + import sigmastate.crypto.CryptoConstants.dlogGroup compile(Map("gA" -> dlogGroup.generator.toGroupElement), "proveDHTuple(gA, OUTPUTS(0).R4[GroupElement].get, gA, gA)" ).asInstanceOf[BlockValue].result shouldBe a [CreateProveDHTuple] diff --git a/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala b/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala index bfba524baf..8899b90584 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/SerializationRoundTripSpec.scala @@ -1,7 +1,7 @@ package sigmastate.utxo import org.ergoplatform._ -import scalan.util.BenchmarkUtil +import sigma.util.BenchmarkUtil import sigmastate.helpers.CompilerTestingCommons import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.serialization.generators.ObjectGenerators @@ -9,7 +9,7 @@ import debox.{Buffer => DBuffer} import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks -import sigmastate.util.{MaxArrayLength, safeNewArray} +import sigma.util.{MaxArrayLength, safeNewArray} class SerializationRoundTripSpec extends AnyPropSpec with ScalaCheckDrivenPropertyChecks diff --git a/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala index ce442ecb50..31536a76fd 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/ThresholdSpecification.scala @@ -1,6 +1,6 @@ package sigmastate.utxo -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} import sigmastate.Values.{ConcreteCollection, FalseLeaf, IntConstant, SigmaPropConstant, SigmaPropValue, TrueLeaf} import sigmastate._ import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, ErgoLikeTransactionTesting, CompilerTestingCommons} diff --git a/sc/shared/src/test/scala/sigmastate/utxo/UsingContextPropertiesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/UsingContextPropertiesSpecification.scala index dea73e67b4..e83d9a8569 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/UsingContextPropertiesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/UsingContextPropertiesSpecification.scala @@ -3,7 +3,7 @@ package sigmastate.utxo import sigmastate.{TrivialProp, CompilerCrossVersionProps} import sigmastate.eval.{IRContext, CSigmaProp} import sigmastate.eval.Extensions._ -import special.sigma.Context +import sigma.Context import sigmastate.helpers.CompilerTestingCommons import org.ergoplatform.dsl.{SigmaContractSyntax, ContractSpec, TestContractSpec} import org.ergoplatform.ErgoBox diff --git a/sc/shared/src/test/scala/sigmastate/utxo/blockchain/BlockchainSimulationTestingCommons.scala b/sc/shared/src/test/scala/sigmastate/utxo/blockchain/BlockchainSimulationTestingCommons.scala index d22b706267..e9cf82616b 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/blockchain/BlockchainSimulationTestingCommons.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/blockchain/BlockchainSimulationTestingCommons.scala @@ -8,12 +8,14 @@ import scorex.crypto.hash.{Blake2b256, Digest32} import sigmastate.{AvlTreeData, AvlTreeFlags, Values} import sigmastate.Values.{ErgoTree, LongConstant} import sigmastate.eval._ -import sigmastate.helpers.{BlockchainState, ErgoLikeContextTesting, ErgoLikeTestProvingInterpreter, ErgoTransactionValidator, CompilerTestingCommons} +import sigmastate.helpers.{BlockchainState, CompilerTestingCommons, ErgoLikeContextTesting, ErgoLikeTestProvingInterpreter, ErgoTransactionValidator} import sigmastate.helpers.TestingHelpers._ import sigmastate.utils.Helpers._ + import scala.collection.mutable import scala.util.{Random, Try} import scorex.util._ +import sigma.Colls import sigmastate.interpreter.ContextExtension import sigmastate.interpreter.Interpreter.{ScriptNameProp, emptyEnv} import sigmastate.utxo.blockchain.BlockchainSimulationTestingCommons.{FullBlock, ValidationState} diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchange.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchange.scala index c27dd1356d..c58d7511d1 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchange.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchange.scala @@ -1,9 +1,9 @@ package sigmastate.utxo.examples import org.ergoplatform.dsl.ContractSyntax.Token -import special.sigma.Context +import sigma.Context import org.ergoplatform.ErgoBox.{R4, TokenId} -import special.collection.Coll +import sigma.Coll import org.ergoplatform.dsl.{SigmaContractSyntax, ContractSpec, StdContracts} /** Contract specification for assets atomic exchange transactions. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchangeErgoTests.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchangeErgoTests.scala index 9a84f6cf1d..5eb852265d 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchangeErgoTests.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsAtomicExchangeErgoTests.scala @@ -3,7 +3,7 @@ package sigmastate.utxo.examples import sigmastate.helpers.CompilerTestingCommons import org.ergoplatform.dsl.ContractSyntax.Token import org.ergoplatform.dsl.ErgoContractSpec -import special.collection.Coll +import sigma.Coll import scorex.crypto.hash.Blake2b256 import sigmastate.eval.Digest32Coll diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsPartialFilling.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsPartialFilling.scala index ad5126d626..969439fe59 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsPartialFilling.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/AssetsPartialFilling.scala @@ -2,8 +2,8 @@ package sigmastate.utxo.examples import org.ergoplatform.ErgoBox.TokenId import org.ergoplatform.dsl.ContractSyntax.Token -import special.sigma.Context -import special.collection.Coll +import sigma.Context +import sigma.Coll import org.ergoplatform.dsl.{SigmaContractSyntax, ContractSpec, StdContracts} /** diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/CoinEmissionSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/CoinEmissionSpecification.scala index 382962c8fc..a6c612a037 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/CoinEmissionSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/CoinEmissionSpecification.scala @@ -2,16 +2,17 @@ package sigmastate.utxo.examples import org.ergoplatform._ import org.ergoplatform.settings.ErgoAlgos +import sigma.Colls import sigmastate.Values.{BlockValue, ErgoTree, IntConstant, LongConstant, ValDef, ValUse} -import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, SigmaPPrint, CompilerTestingCommons} +import sigmastate._ +import sigmastate.eval._ import sigmastate.helpers.TestingHelpers._ +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting} import sigmastate.interpreter.ContextExtension import sigmastate.interpreter.Interpreter.{ScriptNameProp, emptyEnv} import sigmastate.lang.Terms._ -import sigmastate.utxo.blockchain.BlockchainSimulationTestingCommons._ import sigmastate.utxo._ -import sigmastate._ -import sigmastate.eval._ +import sigmastate.utxo.blockchain.BlockchainSimulationTestingCommons._ /** * An example of currency emission contract. diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/CoopExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/CoopExampleSpecification.scala index 3a2bf8b0c3..44b69db572 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/CoopExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/CoopExampleSpecification.scala @@ -3,7 +3,7 @@ package sigmastate.utxo.examples import org.ergoplatform.{ErgoLikeContext, ErgoLikeTransaction, ErgoBox} import org.scalatest.Assertion import org.scalatest.TryValues._ -import sigmastate.basics.DLogProtocol.{ProveDlog, DLogProverInput} +import sigmastate.crypto.DLogProtocol.{ProveDlog, DLogProverInput} import scorex.crypto.hash.Blake2b256 import sigmastate.Values.{ByteArrayConstant, ErgoTree, BooleanConstant} import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, CompilerTestingCommons, ErgoLikeTestInterpreter} diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/CrowdFunding.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/CrowdFunding.scala index ebbf021fb8..d73c0721df 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/CrowdFunding.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/CrowdFunding.scala @@ -1,6 +1,6 @@ package sigmastate.utxo.examples -import special.sigma.{Context, Box} +import sigma.{Context, Box} import org.ergoplatform.dsl.{SigmaContractSyntax, ContractSpec, StdContracts} /** @param backer The party, who wants to fund some amount of Ergs to the project. 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 e4984a25c1..92f6e6c4cb 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DHTupleExampleSpecification.scala @@ -6,8 +6,8 @@ import java.math.BigInteger import org.ergoplatform.ErgoBox.{R4, R5} import sigmastate.{AvlTreeData, CompilerCrossVersionProps} import sigmastate.Values.GroupElementConstant -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.{DiffieHellmanTupleProverInput, ProveDHTuple, CryptoConstants} +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{DiffieHellmanTupleProverInput, ProveDHTuple, CryptoConstants} import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, CompilerTestingCommons, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/DummyExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/DummyExamplesSpecification.scala index 9206a6502c..754e3baa73 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/DummyExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/DummyExamplesSpecification.scala @@ -4,8 +4,7 @@ import org.ergoplatform.ErgoBox import org.ergoplatform.dsl.{ContractSpec, SigmaContractSyntax, StdContracts, TestContractSpec} import scorex.crypto.hash import sigmastate.helpers.CompilerTestingCommons -import special.collection.Coll -import special.sigma.{Box, Context} +import sigma.{Box, Context, Coll} import sigmastate.eval.Extensions class DummyExamplesSpecification extends CompilerTestingCommons { suite => diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/ExecuteFromExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/ExecuteFromExamplesSpecification.scala index 34fbc5e356..5ea4ef7a05 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/ExecuteFromExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/ExecuteFromExamplesSpecification.scala @@ -3,7 +3,7 @@ package sigmastate.utxo.examples import org.ergoplatform._ import org.ergoplatform.dsl.{ContractSpec, SigmaContractSyntax, StdContracts, TestContractSpec} import sigmastate.helpers.CompilerTestingCommons -import special.sigma.Context +import sigma.Context import sigmastate.eval.Extensions._ class ExecuteFromExamplesSpecification extends CompilerTestingCommons { suite => diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/FsmExampleSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/FsmExampleSpecification.scala index 99008b9e21..77918e453a 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/FsmExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/FsmExampleSpecification.scala @@ -5,12 +5,13 @@ import scorex.crypto.authds.avltree.batch.{BatchAVLProver, Insert, Lookup} import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash import scorex.crypto.hash.{Blake2b256, Digest32} +import sigma.Colls import sigmastate.SCollection.SByteArray import sigmastate.Values._ import sigmastate._ import sigmastate.eval._ import sigmastate.lang.Terms._ -import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.{ScriptNameProp, emptyEnv} import sigmastate.serialization.ValueSerializer 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 251b9d1329..95899f0aa9 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/IcoExample.scala @@ -8,9 +8,10 @@ import org.scalatest.BeforeAndAfterAll import scorex.crypto.authds.avltree.batch._ import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.hash.{Blake2b256, Digest32} +import sigma.Colls import sigmastate.Values._ import sigmastate._ -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.eval.Extensions.ArrayOps import sigmastate.eval._ import sigmastate.helpers.TestingHelpers._ 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 ef95e480f8..22f7f1c7c9 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/LetsSpecification.scala @@ -5,10 +5,11 @@ import org.ergoplatform.ErgoBox.{R4, R5} import scorex.crypto.authds.{ADKey, ADValue} import scorex.crypto.authds.avltree.batch.{BatchAVLProver, Insert, Lookup} import scorex.crypto.hash.{Blake2b256, Digest32} +import sigma.Colls import sigmastate.{AvlTreeData, AvlTreeFlags, CompilerCrossVersionProps, TrivialProp} import sigmastate.Values.{AvlTreeConstant, ByteArrayConstant, LongConstant, SigmaPropConstant} import sigmastate.eval.Extensions.ArrayOps -import sigmastate.eval.{Colls, Digest32Coll, IRContext, SigmaDsl} +import sigmastate.eval.{Digest32Coll, IRContext, SigmaDsl} import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestProvingInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter.ScriptNameProp 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 c0e9ca1d73..6bbf410dc1 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/MixExampleSpecification.scala @@ -6,8 +6,8 @@ import org.ergoplatform.ErgoBox.{R4, R5} import scorex.crypto.hash.Blake2b256 import sigmastate.{AvlTreeData, CompilerCrossVersionProps} import sigmastate.Values.GroupElementConstant -import sigmastate.basics.DLogProtocol.ProveDlog -import sigmastate.basics.{DiffieHellmanTupleProverInput, ProveDHTuple, CryptoConstants} +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{DiffieHellmanTupleProverInput, ProveDHTuple, CryptoConstants} import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, CompilerTestingCommons, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleDataInputsExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleDataInputsExamplesSpecification.scala index 002d1836c9..564385fd96 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleDataInputsExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleDataInputsExamplesSpecification.scala @@ -6,8 +6,8 @@ import org.ergoplatform.dsl.{ContractSpec, SigmaContractSyntax, StdContracts, Te import scorex.crypto.hash.Blake2b256 import sigmastate.eval.Digest32Coll import sigmastate.helpers.CompilerTestingCommons -import special.collection.Coll -import special.sigma.Context +import sigma.Coll +import sigma.Context class OracleDataInputsExamplesSpecification extends CompilerTestingCommons { suite => implicit lazy val IR: TestingIRContext = new TestingIRContext diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleExamplesSpecification.scala index 384f0d4b63..8566ce437e 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleExamplesSpecification.scala @@ -14,12 +14,12 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn import sigmastate.helpers.TestingHelpers._ import org.ergoplatform._ import org.ergoplatform.dsl.{ContractSpec, SigmaContractSyntax, StdContracts, TestContractSpec} -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.crypto.{BigIntegers, CryptoFacade} import sigmastate.eval.Extensions.ArrayOps import sigmastate.interpreter.Interpreter.{ScriptNameProp, emptyEnv} import sigmastate.utxo._ -import special.sigma.Context +import sigma.Context import sigmastate.utils.Helpers._ class OracleExamplesSpecification extends CompilerTestingCommons diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleTokenExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleTokenExamplesSpecification.scala index 7087854598..5a30cd6689 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleTokenExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/OracleTokenExamplesSpecification.scala @@ -6,8 +6,8 @@ import org.ergoplatform.dsl.{ContractSpec, SigmaContractSyntax, StdContracts, Te import scorex.crypto.hash.Blake2b256 import sigmastate.eval.Digest32Coll import sigmastate.helpers.CompilerTestingCommons -import special.collection.Coll -import special.sigma.Context +import sigma.Coll +import sigma.Context class OracleTokenExamplesSpecification extends CompilerTestingCommons { suite => implicit lazy val IR: TestingIRContext = new TestingIRContext 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 c65e63c95c..1f00dbfc3c 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/RPSGameExampleSpecification.scala @@ -6,7 +6,7 @@ import scorex.crypto.hash.Blake2b256 import scorex.utils.Random import sigmastate.Values.{ByteArrayConstant, ByteConstant, IntConstant, SigmaPropConstant} import sigmastate._ -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/RevenueSharingExamplesSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/RevenueSharingExamplesSpecification.scala index 90cf1871a6..41d3b59039 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/RevenueSharingExamplesSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/RevenueSharingExamplesSpecification.scala @@ -3,7 +3,7 @@ package sigmastate.utxo.examples import org.ergoplatform.dsl.{SigmaContractSyntax, ContractSpec, TestContractSpec, StdContracts} import sigmastate.eval.Extensions import sigmastate.helpers.CompilerTestingCommons -import special.sigma.Context +import sigma.Context class RevenueSharingExamplesSpecification extends CompilerTestingCommons { suite => implicit lazy val IR = new TestingIRContext diff --git a/sc/shared/src/test/scala/sigmastate/utxo/examples/Rule110Specification.scala b/sc/shared/src/test/scala/sigmastate/utxo/examples/Rule110Specification.scala index 62fbaf37a7..00b25ba8e1 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/Rule110Specification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/Rule110Specification.scala @@ -3,10 +3,11 @@ package sigmastate.utxo.examples import org.ergoplatform._ import scorex.crypto.hash.Blake2b256 import scorex.util._ +import sigma.Colls import sigmastate.Values._ import sigmastate._ import sigmastate.eval._ -import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, CompilerTestingCommons, ErgoLikeTestInterpreter} +import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.ContextExtension import sigmastate.lang.Terms._ 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 c462e0396f..436115e9c2 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/examples/XorGameExampleSpecification.scala @@ -6,7 +6,7 @@ import scorex.crypto.hash.Blake2b256 import scorex.utils.Random import sigmastate.Values.{ByteArrayConstant, ByteConstant, IntConstant, SigmaPropConstant} import sigmastate._ -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons} import sigmastate.helpers.TestingHelpers._ import sigmastate.interpreter.Interpreter._ diff --git a/graph-ir/shared/src/test/scala/special/wrappers/WOptionTests.scala b/sc/shared/src/test/scala/special/wrappers/WOptionTests.scala similarity index 100% rename from graph-ir/shared/src/test/scala/special/wrappers/WOptionTests.scala rename to sc/shared/src/test/scala/special/wrappers/WOptionTests.scala diff --git a/graph-ir/shared/src/test/scala/special/wrappers/WRTypeTests.scala b/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala similarity index 89% rename from graph-ir/shared/src/test/scala/special/wrappers/WRTypeTests.scala rename to sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala index 0378e7fbc3..51c7231935 100644 --- a/graph-ir/shared/src/test/scala/special/wrappers/WRTypeTests.scala +++ b/sc/shared/src/test/scala/special/wrappers/WRTypeTests.scala @@ -1,6 +1,6 @@ package special.wrappers -import scalan.RType +import sigma.data.RType import scala.language.reflectiveCalls @@ -19,7 +19,7 @@ class WRTypeTests extends WrappersTests { } test("Implicit conversion from RType to Elem") { - val eInt: Elem[Int] = RType.IntType + val eInt: Elem[Int] = sigma.IntType eInt shouldBe IntElement val ePair: Elem[(Int, Coll[Byte])] = RType[(Int, SColl[Byte])] diff --git a/graph-ir/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala b/sc/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala similarity index 94% rename from graph-ir/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala rename to sc/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala index 2321d32577..e1097ebf6c 100644 --- a/graph-ir/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala +++ b/sc/shared/src/test/scala/special/wrappers/WSpecialPredefTests.scala @@ -2,7 +2,7 @@ package special.wrappers import scala.language.reflectiveCalls -import scalan.RType +import sigma.data.RType class WSpecialPredefTests extends WrappersTests { diff --git a/graph-ir/shared/src/test/scala/special/wrappers/WrappersTests.scala b/sc/shared/src/test/scala/special/wrappers/WrappersTests.scala similarity index 100% rename from graph-ir/shared/src/test/scala/special/wrappers/WrappersTests.scala rename to sc/shared/src/test/scala/special/wrappers/WrappersTests.scala diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/AvlTree.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/AvlTree.scala index 19edc35f40..f1cf64377c 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/AvlTree.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/AvlTree.scala @@ -4,7 +4,7 @@ import scala.scalajs.js import scala.scalajs.js.UndefOr import scala.scalajs.js.annotation.JSExportTopLevel -/** Equivalent of [[special.sigma.AvlTree]] available from JS. */ +/** Equivalent of [[sigma.AvlTree]] available from JS. */ @JSExportTopLevel("AvlTree") class AvlTree( val digest: String, diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala index cc20e704bb..857592d4a2 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/GroupElement.scala @@ -6,7 +6,7 @@ import sigmastate.eval.Extensions.ArrayByteOps import scala.scalajs.js import scala.scalajs.js.annotation.JSExportTopLevel -/** Equivalent of [[special.sigma.GroupElement]] available from JS. */ +/** Equivalent of [[sigma.GroupElement]] available from JS. */ @JSExportTopLevel("GroupElement") class GroupElement(val point: Ecp) extends js.Object { /** Returns the point encoded as hex string (ASN.1 encoding). diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Header.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Header.scala index f95b8eb0e1..4d10c9f3dd 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Header.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Header.scala @@ -3,7 +3,7 @@ package org.ergoplatform.sdk.js import scala.scalajs.js import scala.scalajs.js.annotation.JSExportTopLevel -/** Equivalent of [[special.sigma.Header]] available from JS. +/** Equivalent of [[sigma.Header]] available from JS. * Represents data of the block header available in Sigma propositions. */ @JSExportTopLevel("Header") diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala index a317e3ab29..b2ffd664e8 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Isos.scala @@ -5,13 +5,13 @@ import org.ergoplatform.sdk.JavaHelpers.UniversalConverter import org.ergoplatform.sdk.{Iso, ExtendedInputBox} import org.ergoplatform.sdk.wallet.protocol.context import org.ergoplatform._ -import scalan.RType +import sigma.data.RType import scorex.crypto.authds.ADKey import scorex.util.ModifierId import scorex.util.encode.Base16 import sigmastate.Values.{Constant, GroupElementConstant} import sigmastate.eval.Extensions.ArrayOps -import sigmastate.eval.{CBigInt, Digest32Coll, Evaluation, CAvlTree, Colls, CGroupElement, CPreHeader, CHeader} +import sigmastate.eval.{CBigInt, Digest32Coll, Evaluation, CAvlTree, CGroupElement, CPreHeader, CHeader} import sigmastate.fleetSdkCommon.distEsmTypesBoxesMod.Box import sigmastate.fleetSdkCommon.distEsmTypesCommonMod.HexString import sigmastate.fleetSdkCommon.distEsmTypesRegistersMod.NonMandatoryRegisters @@ -20,10 +20,9 @@ import sigmastate.fleetSdkCommon.distEsmTypesTransactionsMod.{UnsignedTransactio import sigmastate.fleetSdkCommon.{distEsmTypesProverResultMod => proverResultMod, distEsmTypesContextExtensionMod => contextExtensionMod, distEsmTypesInputsMod => inputsMod, distEsmTypesBoxesMod => boxesMod, distEsmTypesCommonMod => commonMod, distEsmTypesRegistersMod => registersMod, distEsmTypesTokenMod => tokenMod} import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.serialization.{ErgoTreeSerializer, ValueSerializer} -import sigmastate.{AvlTreeData, SType, AvlTreeFlags} -import special.collection.Coll -import special.collection.Extensions.CollBytesOps -import special.sigma +import sigmastate.{AvlTreeData, AvlTreeFlags, SType} +import sigma.{Coll, Colls} +import sigma.Extensions.CollBytesOps import java.math.BigInteger import scala.collection.immutable.ListMap @@ -67,7 +66,7 @@ object Isos { } } - val isoGroupElement: Iso[GroupElement, special.sigma.GroupElement] = new Iso[GroupElement, special.sigma.GroupElement] { + val isoGroupElement: Iso[GroupElement, sigma.GroupElement] = new Iso[GroupElement, sigma.GroupElement] { override def to(x: GroupElement): sigma.GroupElement = { CGroupElement(x.point) } @@ -119,7 +118,7 @@ object Isos { } } - implicit val isoHeader: Iso[Header, special.sigma.Header] = new Iso[Header, special.sigma.Header] { + implicit val isoHeader: Iso[Header, sigma.Header] = new Iso[Header, sigma.Header] { override def to(a: Header): sigma.Header = { CHeader( id = isoStringToColl.to(a.id), @@ -161,7 +160,7 @@ object Isos { } } - implicit val isoPreHeader: Iso[PreHeader, special.sigma.PreHeader] = new Iso[PreHeader, special.sigma.PreHeader] { + implicit val isoPreHeader: Iso[PreHeader, sigma.PreHeader] = new Iso[PreHeader, sigma.PreHeader] { override def to(a: PreHeader): sigma.PreHeader = { CPreHeader( version = a.version, @@ -189,7 +188,7 @@ object Isos { val isoBlockchainParameters: Iso[BlockchainParameters, sdk.BlockchainParameters] = new Iso[BlockchainParameters, sdk.BlockchainParameters] { override def to(a: BlockchainParameters): sdk.BlockchainParameters = { - sdk.BlockchainParameters( + sdk.CBlockchainParameters( storageFeeFactor = a.storageFeeFactor, minValuePerByte = a.minValuePerByte, maxBlockSize = a.maxBlockSize, @@ -222,7 +221,7 @@ object Isos { implicit val isoBlockchainStateContext: Iso[BlockchainStateContext, context.BlockchainStateContext] = new Iso[BlockchainStateContext, context.BlockchainStateContext] { override def to(a: BlockchainStateContext): context.BlockchainStateContext = { - context.BlockchainStateContext( + context.CBlockchainStateContext( sigmaLastHeaders = isoArrayToColl(isoHeader).to(a.sigmaLastHeaders), previousStateDigest = isoStringToColl.to(a.previousStateDigest), sigmaPreHeader = isoPreHeader.to(a.sigmaPreHeader) @@ -296,7 +295,7 @@ object Isos { override def from(x: DataInput): inputsMod.DataInput = inputsMod.DataInput(x.boxId.convertTo[boxesMod.BoxId]) } - implicit val isoBigInt: Iso[js.BigInt, special.sigma.BigInt] = new Iso[js.BigInt, special.sigma.BigInt] { + implicit val isoBigInt: Iso[js.BigInt, sigma.BigInt] = new Iso[js.BigInt, sigma.BigInt] { override def to(x: js.BigInt): sigma.BigInt = { CBigInt(new BigInteger(x.toString(10))) } diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/PreHeader.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/PreHeader.scala index ae75b67ece..08a8ace0d9 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/PreHeader.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/PreHeader.scala @@ -3,7 +3,7 @@ package org.ergoplatform.sdk.js import scala.scalajs.js import scala.scalajs.js.annotation.JSExportTopLevel -/** Equivalent of [[special.sigma.PreHeader]] available from JS. +/** Equivalent of [[sigma.PreHeader]] available from JS. * Only header fields that can be predicted by a miner. */ @JSExportTopLevel("PreHeader") diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProp.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProp.scala index bc2da23561..2dc665d918 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProp.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/SigmaProp.scala @@ -1,12 +1,12 @@ package org.ergoplatform.sdk.js import sigmastate.Values.SigmaBoolean -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import scala.scalajs.js import scala.scalajs.js.annotation.JSExportTopLevel -/** Equivalent of [[special.sigma.SigmaProp]] available from JS. */ +/** Equivalent of [[sigma.SigmaProp]] available from JS. */ @JSExportTopLevel("SigmaProp") class SigmaProp(val sigmaBoolean: SigmaBoolean) extends js.Object { } diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala index ba4c7128b9..a0930cc99a 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Type.scala @@ -1,6 +1,6 @@ package org.ergoplatform.sdk.js -import scalan.RType +import sigma.data.RType import scala.scalajs.js import scala.scalajs.js.annotation.JSExportTopLevel @@ -20,45 +20,45 @@ class Type(private[js] final val rtype: RType[_]) extends js.Object { @JSExportTopLevel("TypeObj") object Type extends js.Object { /** Descriptor of ErgoScript type Byte. */ - val Byte = new Type(RType.ByteType) + val Byte = new Type(sigma.ByteType) /** Descriptor of ErgoScript type Short. */ - val Short = new Type(RType.ShortType) + val Short = new Type(sigma.ShortType) /** Descriptor of ErgoScript type Int. */ - val Int = new Type(RType.IntType) + val Int = new Type(sigma.IntType) /** Descriptor of ErgoScript type Long. */ - val Long = new Type(RType.LongType) + val Long = new Type(sigma.LongType) /** Descriptor of ErgoScript type BigInt. */ - val BigInt = new Type(special.sigma.BigIntRType) + val BigInt = new Type(sigma.BigIntRType) /** Descriptor of ErgoScript type GroupElement. */ - val GroupElement = new Type(special.sigma.GroupElementRType) + val GroupElement = new Type(sigma.GroupElementRType) /** Descriptor of ErgoScript type SigmaProp. */ - val SigmaProp = new Type(special.sigma.SigmaPropRType) + val SigmaProp = new Type(sigma.SigmaPropRType) /** Descriptor of ErgoScript type Box. */ - val Box = new Type(special.sigma.BoxRType) + val Box = new Type(sigma.BoxRType) /** Descriptor of ErgoScript type AvlTree. */ - val AvlTree = new Type(special.sigma.AvlTreeRType) + val AvlTree = new Type(sigma.AvlTreeRType) /** Descriptor of ErgoScript type Context. */ - val Context = new Type(special.sigma.ContextRType) + val Context = new Type(sigma.ContextRType) /** Descriptor of ErgoScript type Header. */ - val Header = new Type(special.sigma.HeaderRType) + val Header = new Type(sigma.HeaderRType) /** Descriptor of ErgoScript type PreHeader. */ - val PreHeader = new Type(special.sigma.PreHeaderRType) + val PreHeader = new Type(sigma.PreHeaderRType) /** Descriptor of ErgoScript type Global. * @see SigmaDslBuilder, SGlobal */ - val SigmaDslBuilder = new Type(special.sigma.SigmaDslBuilderRType) + val SigmaDslBuilder = new Type(sigma.SigmaDslBuilderRType) /** Constructs a new descriptor of ErgoScript pair type (l, r). * @param l first component of the pair @@ -73,6 +73,6 @@ object Type extends js.Object { * @param elemType type descriptor of collection elements */ def collType(elemType: Type): Type = { - new Type(special.collection.collRType(elemType.rtype)) + new Type(sigma.collRType(elemType.rtype)) } } \ No newline at end of file diff --git a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala index 0c30216dbc..e3a3d15b9a 100644 --- a/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala +++ b/sdk/js/src/main/scala/org/ergoplatform/sdk/js/Value.scala @@ -1,19 +1,19 @@ package org.ergoplatform.sdk.js import org.ergoplatform.sdk.js.Value.toRuntimeData -import scalan.RType -import scalan.RType.PairType +import sigma.data.{CollType, RType} +import sigma.data.PairType import scorex.util.Extensions.{IntOps, LongOps} import scorex.util.encode.Base16 import sigmastate.SType import sigmastate.crypto.Platform -import sigmastate.eval.{CAvlTree, CGroupElement, CSigmaProp, Colls, CostingBox, Evaluation, SigmaDsl} +import sigmastate.eval.{CAvlTree, CGroupElement, CSigmaProp, CostingBox, Evaluation, SigmaDsl} import sigmastate.fleetSdkCommon.distEsmTypesBoxesMod.Box import sigmastate.fleetSdkCommon.distEsmTypesCommonMod import sigmastate.fleetSdkCommon.distEsmTypesRegistersMod.NonMandatoryRegisters import sigmastate.lang.DeserializationSigmaBuilder import sigmastate.serialization.{ConstantSerializer, DataSerializer, SigmaSerializer} -import special.collection.{Coll, CollType} +import sigma.{Coll, Colls} import java.math.BigInteger import scala.scalajs.js @@ -82,22 +82,22 @@ object Value extends js.Object { * in register and [[sigmastate.Values.Constant]] nodes. */ final private[js] def toRuntimeData(data: Any, rtype: RType[_]): Any = rtype match { - case RType.BooleanType => data - case RType.ByteType | RType.ShortType | RType.IntType => data - case RType.LongType => java.lang.Long.parseLong(data.asInstanceOf[js.BigInt].toString(10)) - case special.sigma.BigIntRType => + case sigma.BooleanType => data + case sigma.ByteType | sigma.ShortType | sigma.IntType => data + case sigma.LongType => java.lang.Long.parseLong(data.asInstanceOf[js.BigInt].toString(10)) + case sigma.BigIntRType => val v = data.asInstanceOf[js.BigInt] SigmaDsl.BigInt(new BigInteger(v.toString(16), 16)) - case special.sigma.GroupElementRType => + case sigma.GroupElementRType => val ge = data.asInstanceOf[GroupElement] SigmaDsl.GroupElement(ge.point) - case special.sigma.SigmaPropRType => + case sigma.SigmaPropRType => val p = data.asInstanceOf[SigmaProp] SigmaDsl.SigmaProp(p.sigmaBoolean) - case special.sigma.AvlTreeRType => + case sigma.AvlTreeRType => val t = data.asInstanceOf[AvlTree] Isos.isoAvlTree.to(t) - case special.sigma.BoxRType => + case sigma.BoxRType => val t = data.asInstanceOf[Box[distEsmTypesCommonMod.Amount, NonMandatoryRegisters]] SigmaDsl.Box(Isos.isoBox.to(t)) case ct: CollType[a] => @@ -110,7 +110,7 @@ object Value extends js.Object { val x = toRuntimeData(p(0), pt.tFst).asInstanceOf[a] val y = toRuntimeData(p(1), pt.tSnd).asInstanceOf[b] (x, y) - case RType.UnitType => data + case sigma.UnitType => data case _ => throw new IllegalArgumentException(s"Unsupported type $rtype") } @@ -122,20 +122,20 @@ object Value extends js.Object { * @param rtype type descriptor of Sigma runtime value */ final private[js] def fromRuntimeData(value: Any, rtype: RType[_]): Any = rtype match { - case RType.BooleanType => value - case RType.ByteType | RType.ShortType | RType.IntType => value - case RType.LongType => js.BigInt(value.asInstanceOf[Long].toString) - case special.sigma.BigIntRType => - val hex = SigmaDsl.toBigInteger(value.asInstanceOf[special.sigma.BigInt]).toString(10) + case sigma.BooleanType => value + case sigma.ByteType | sigma.ShortType | sigma.IntType => value + case sigma.LongType => js.BigInt(value.asInstanceOf[Long].toString) + case sigma.BigIntRType => + val hex = SigmaDsl.toBigInteger(value.asInstanceOf[sigma.BigInt]).toString(10) js.BigInt(hex) - case special.sigma.GroupElementRType => + case sigma.GroupElementRType => val point = value.asInstanceOf[CGroupElement].wrappedValue.asInstanceOf[Platform.Ecp] new GroupElement(point) - case special.sigma.SigmaPropRType => + case sigma.SigmaPropRType => new SigmaProp(value.asInstanceOf[CSigmaProp].wrappedValue) - case special.sigma.AvlTreeRType => + case sigma.AvlTreeRType => Isos.isoAvlTree.from(value.asInstanceOf[CAvlTree]) - case special.sigma.BoxRType => + case sigma.BoxRType => Isos.isoBox.from(value.asInstanceOf[CostingBox].wrappedValue) case ct: CollType[a] => val arr = value.asInstanceOf[Coll[a]].toArray @@ -143,7 +143,7 @@ object Value extends js.Object { case pt: PairType[a, b] => val p = value.asInstanceOf[(a, b)] js.Array(fromRuntimeData(p._1, pt.tFst), fromRuntimeData(p._2, pt.tSnd)) - case RType.UnitType => value + case sigma.UnitType => value case _ => throw new IllegalArgumentException(s"Unsupported type $rtype") } @@ -154,19 +154,19 @@ object Value extends js.Object { * @param rtype type descriptor of Sigma runtime value */ final private def checkJsData[T](data: T, rtype: RType[_]): Any = rtype match { - case RType.ByteType => data.asInstanceOf[Int].toByteExact - case RType.ShortType => data.asInstanceOf[Int].toShortExact - case RType.IntType => data.asInstanceOf[Int].toLong.toIntExact - case RType.LongType => + case sigma.ByteType => data.asInstanceOf[Int].toByteExact + case sigma.ShortType => data.asInstanceOf[Int].toShortExact + case sigma.IntType => data.asInstanceOf[Int].toLong.toIntExact + case sigma.LongType => val n = data.asInstanceOf[js.BigInt] if (n < MinLong || n > MaxLong) throw new ArithmeticException(s"value $n is out of long range") n - case special.sigma.BigIntRType => + case sigma.BigIntRType => data.asInstanceOf[js.BigInt] - case special.sigma.GroupElementRType => + case sigma.GroupElementRType => data.asInstanceOf[GroupElement] - case special.sigma.SigmaPropRType => + case sigma.SigmaPropRType => data.asInstanceOf[SigmaProp] case PairType(l, r) => data match { case arr: js.Array[Any @unchecked] => diff --git a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala index 47eedf2706..2164b9b339 100644 --- a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala +++ b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/IsosSpec.scala @@ -2,7 +2,7 @@ package org.ergoplatform.sdk.js import org.ergoplatform.ErgoBox.{AdditionalRegisters, BoxId, TokenId} import org.ergoplatform._ -import org.ergoplatform.sdk.wallet.protocol.context.BlockchainStateContext +import org.ergoplatform.sdk.wallet.protocol.context.{BlockchainStateContext, CBlockchainStateContext} import org.ergoplatform.sdk.{ExtendedInputBox, Iso} import org.scalacheck.{Arbitrary, Gen} import org.scalatest.matchers.should.Matchers @@ -10,12 +10,9 @@ import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import sigmastate.SType import sigmastate.Values.Constant -import sigmastate.eval.Colls import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.serialization.generators.ObjectGenerators -import special.collection.Coll -import special.sigma -import special.sigma.GroupElement +import sigma.{Coll, Colls, GroupElement} import scala.scalajs.js @@ -30,7 +27,7 @@ class IsosSpec extends AnyPropSpec with Matchers with ObjectGenerators with Sca stateRoot <- avlTreeGen headers <- headersGen(stateRoot) preHeader <- preHeaderGen(headers.headOption.map(_.id).getOrElse(modifierIdBytesGen.sample.get)) - } yield BlockchainStateContext( + } yield CBlockchainStateContext( sigmaLastHeaders = Colls.fromItems(headers:_*), previousStateDigest = stateRoot.digest, sigmaPreHeader = preHeader diff --git a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/ValueSpec.scala b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/ValueSpec.scala index 54ace98db5..be0997fcc6 100644 --- a/sdk/js/src/test/scala/org/ergoplatform/sdk/js/ValueSpec.scala +++ b/sdk/js/src/test/scala/org/ergoplatform/sdk/js/ValueSpec.scala @@ -6,14 +6,14 @@ import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks import scorex.util.encode.Base16 import sigmastate.SType import sigmastate.Values.{AvlTreeConstant, BigIntConstant, BooleanConstant, BoxConstant, ByteConstant, Constant, GroupElementConstant, IntConstant, LongConstant, ShortConstant, SigmaPropConstant, UnitConstant} -import sigmastate.basics.CryptoConstants.dlogGroup -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.CryptoConstants.dlogGroup +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.crypto.CryptoFacade import sigmastate.eval.CSigmaProp import sigmastate.lang.DeserializationSigmaBuilder import sigmastate.serialization.ConstantSerializer import sigmastate.utils.Helpers -import special.sigma.SigmaTestingData +import sigma.SigmaTestingData import java.math.BigInteger diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala index dc289ba4e6..b3b470c604 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/AppkitProvingInterpreter.scala @@ -8,15 +8,16 @@ import org.ergoplatform.sdk.utils.ArithUtils import org.ergoplatform.sdk.wallet.protocol.context.{BlockchainStateContext, TransactionContext} import org.ergoplatform.sdk.wallet.secrets.ExtendedSecretKey import org.ergoplatform.validation.ValidationRules -import scalan.util.Extensions.LongOps +import sigma.util.Extensions.LongOps +import sigma.VersionContext import sigmastate.Values.SigmaBoolean -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} -import sigmastate.basics.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} import sigmastate.interpreter.Interpreter.{ReductionResult, estimateCryptoVerifyCost} import sigmastate.interpreter._ import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} -import sigmastate.{AvlTreeData, VersionContext} +import sigmastate.AvlTreeData import java.util import java.util.{Objects, List => JList} diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainContext.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainContext.scala index d5b6edaf69..1d87f197e8 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainContext.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainContext.scala @@ -1,8 +1,8 @@ package org.ergoplatform.sdk import org.ergoplatform.sdk.wallet.protocol.context.BlockchainStateContext -import special.collection.Coll -import special.sigma.Header +import sigma.Coll +import sigma.Header /** Represents a specific context of blockchain for execution * of transaction building scenario. diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala index 4a1014b112..6f799ff8d8 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/BlockchainParameters.scala @@ -1,21 +1,35 @@ package org.ergoplatform.sdk /** Blockchain parameters re-adjustable via miners voting and voting-related data. - * All these fields are included into extension section of a first block of a voting epoch. - * - * @param storageFeeFactor cost of storing 1 byte in UTXO for four years, in nanoErgs - * @param minValuePerByte cost of a transaction output, in computation unit - * @param maxBlockSize max block size, in bytes - * @param tokenAccessCost cost of a token contained in a transaction, in computation unit - * @param inputCost cost of a transaction input, in computation unit - * @param dataInputCost cost of a transaction data input, in computation unit - * @param outputCost cost of a transaction output, in computation unit - * @param maxBlockCost computation units limit per block - * @param softForkStartingHeight height when voting for a soft-fork had been started - * @param softForkVotesCollected votes for soft-fork collected in previous epochs - * @param blockVersion Protocol version activated on the network + * All these parameters are included into extension section of a first block of a voting epoch. */ -case class BlockchainParameters( +abstract class BlockchainParameters { + /** Cost of storing 1 byte in UTXO for four years, in nanoErgs. */ + def storageFeeFactor: Int + /** Cost of a transaction output, in computation unit. */ + def minValuePerByte: Int + /** Max block size, in bytes. */ + def maxBlockSize: Int + /** Cost of a token contained in a transaction, in computation unit. */ + def tokenAccessCost: Int + /** Cost of a transaction input, in computation unit. */ + def inputCost: Int + /** Cost of a transaction data input, in computation unit. */ + def dataInputCost: Int + /** Cost of a transaction output, in computation unit. */ + def outputCost: Int + /** Computation units limit per block. */ + def maxBlockCost: Int + /** Height when voting for a soft-fork had been started. */ + def softForkStartingHeight: Option[Int] + /** Votes for soft-fork collected in previous epochs. */ + def softForkVotesCollected: Option[Int] + /** Protocol version activated on the network. */ + def blockVersion: Byte +} + +/** Concete implementation of blockchain parameters. */ +case class CBlockchainParameters( storageFeeFactor: Int, minValuePerByte: Int, maxBlockSize: Int, @@ -27,7 +41,7 @@ case class BlockchainParameters( softForkStartingHeight: Option[Int], softForkVotesCollected: Option[Int], blockVersion: Byte -) +) extends BlockchainParameters /** Global parameters used by SDK */ object BlockchainParameters { diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala index c24a9fb4b3..47d2a06d3e 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ContractTemplate.scala @@ -1,19 +1,19 @@ package org.ergoplatform.sdk -import cats.syntax.either._ +import cats.syntax.either._ // required for Scala 2.11 import debox.cfor import io.circe._ -import io.circe.syntax.{EncoderOps, _} +import io.circe.syntax.EncoderOps import org.ergoplatform.sdk.utils.SerializationUtils.{parseString, serializeString} import org.ergoplatform.sdk.utils.Zero +import sigma.util.safeNewArray import sigmastate.Values.ErgoTree.headerWithVersion import sigmastate.Values.{ErgoTree, _} import sigmastate._ -import sigmastate.eval.{Colls, _} +import sigmastate.eval._ import sigmastate.exceptions.SerializerException import sigmastate.lang.{DeserializationSigmaBuilder, StdSigmaBuilder} import sigmastate.serialization._ -import sigmastate.util.safeNewArray import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} import java.util.Objects diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala index d36bd947a3..a92eef9947 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/DataJsonEncoder.scala @@ -6,14 +6,13 @@ import io.circe.syntax._ import org.ergoplatform.ErgoBox import org.ergoplatform.ErgoBox.{NonMandatoryRegisterId, Token} import org.ergoplatform.settings.ErgoAlgos -import scalan.RType +import sigma.data.RType import scorex.util._ import sigmastate.Values.{Constant, EvaluatedValue} import sigmastate._ import sigmastate.lang.SigmaParser import sigmastate.eval._ -import special.collection.Coll -import special.sigma._ +import sigma._ import debox.cfor import sigmastate.exceptions.SerializerException import scala.collection.compat.immutable.ArraySeq @@ -191,7 +190,7 @@ object DataJsonEncoder { cfor(1)(_ <= tArr.length, _ + 1) { i => collSource += decodeData(json.hcursor.downField(s"_${i}").focus.get, tArr(i - 1)) } - val coll = Colls.fromArray(collSource.result())(RType.AnyType) + val coll = Colls.fromArray(collSource.result())(sigma.AnyType) Evaluation.toDslTuple(coll, t) case SGroupElement => val str = decodeBytes(json) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala index 088b16fe77..7d56b05295 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ErgoId.scala @@ -19,14 +19,14 @@ class ErgoId(val _idBytes: Array[Byte]) { override def hashCode = if (_idBytes != null && _idBytes.length >= 4) Ints.fromByteArray(_idBytes) - else util.Arrays.hashCode(_idBytes) + else java.util.Arrays.hashCode(_idBytes) override def equals(obj: Any): Boolean = { if (obj == null) return false if (this eq obj.asInstanceOf[AnyRef]) return true obj match { case that: ErgoId => - util.Arrays.equals(this._idBytes, that._idBytes) + java.util.Arrays.equals(this._idBytes, that._idBytes) case _ => false } } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Extensions.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Extensions.scala index 426090b125..c8fb2e57f8 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Extensions.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Extensions.scala @@ -1,11 +1,11 @@ package org.ergoplatform.sdk import debox.cfor -import scalan.RType -import scalan.rtypeToClassTag // actually used +import sigma.data.RType +import sigma.rtypeToClassTag // actually used import sigmastate.eval.CPreHeader -import special.collection.{Coll, CollBuilder, PairColl} -import special.sigma.{Header, PreHeader} +import sigma.{Coll, CollBuilder, PairColl} +import sigma.{Header, PreHeader} import scala.collection.compat.BuildFrom import scala.collection.{GenIterable, immutable} diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala index 52c653e9db..75825defa3 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JavaHelpers.scala @@ -1,38 +1,34 @@ package org.ergoplatform.sdk -import scalan.RType -import special.collection.Coll - -import scala.collection.{JavaConverters, mutable} -import org.ergoplatform._ +import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix import org.ergoplatform.ErgoBox.{Token, TokenId} -import sigmastate.SType -import sigmastate.Values.{Constant, ErgoTree, EvaluatedValue, SValue, SigmaBoolean, SigmaPropConstant} -import sigmastate.serialization.{ErgoTreeSerializer, GroupElementSerializer, SigmaSerializer, ValueSerializer} -import scorex.crypto.authds.ADKey +import org.ergoplatform._ +import org.ergoplatform.sdk.Extensions.{CollBuilderOps, PairCollOps} +import org.ergoplatform.sdk.JavaHelpers.{TokenColl, TokenIdRType} +import org.ergoplatform.sdk.wallet.secrets.{DerivationPath, ExtendedSecretKey} +import org.ergoplatform.sdk.wallet.{Constants, TokensMap} import org.ergoplatform.settings.ErgoAlgos -import sigmastate.eval.{CPreHeader, Colls, CostingSigmaDslBuilder, Digest32Coll, Evaluation} -import special.sigma.{AnyValue, AvlTree, GroupElement, Header} +import scorex.crypto.authds.ADKey import sigmastate.utils.Helpers._ // don't remove, required for Scala 2.11 - -import java.util -import java.lang.{Boolean => JBoolean, Byte => JByte, Integer => JInt, Long => JLong, Short => JShort, String => JString} -import java.util.{List => JList, Map => JMap} -import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix import scorex.util.encode.Base16 -import sigmastate.basics.DLogProtocol.ProveDlog import scorex.util.{ModifierId, bytesToId, idToBytes} -import org.ergoplatform.sdk.JavaHelpers.{TokenColl, TokenIdRType} -import org.ergoplatform.sdk.Extensions.{CollBuilderOps, PairCollOps} -import org.ergoplatform.sdk.wallet.{Constants, TokensMap} -import org.ergoplatform.sdk.wallet.secrets.{DerivationPath, ExtendedSecretKey} -import scalan.ExactIntegral.LongIsExactIntegral -import scalan.util.StringUtil.StringUtilExtensions -import sigmastate.basics.CryptoConstants.EcPointType -import sigmastate.basics.{DiffieHellmanTupleProverInput, ProveDHTuple} -import sigmastate.crypto.CryptoFacade +import sigma.data.ExactIntegral.LongIsExactIntegral +import sigma.data.RType +import sigma.util.StringUtil.StringUtilExtensions +import sigma.{AnyValue, AvlTree, Coll, Colls, GroupElement, Header} +import sigmastate.SType +import sigmastate.Values.{Constant, ErgoTree, EvaluatedValue, SValue, SigmaBoolean, SigmaPropConstant} +import sigmastate.crypto.CryptoConstants.EcPointType +import sigmastate.crypto.DLogProtocol.ProveDlog +import sigmastate.crypto.{CryptoFacade, DiffieHellmanTupleProverInput, ProveDHTuple} +import sigmastate.eval.{CostingSigmaDslBuilder, Digest32Coll, Evaluation} +import sigmastate.serialization.{ErgoTreeSerializer, GroupElementSerializer, SigmaSerializer, ValueSerializer} +import java.lang.{Boolean => JBoolean, Byte => JByte, Integer => JInt, Long => JLong, Short => JShort, String => JString} import java.math.BigInteger +import java.util +import java.util.{List => JList, Map => JMap} +import scala.collection.{JavaConverters, mutable} /** Type-class of isomorphisms between types. * Isomorphism between two types `A` and `B` essentially say that both types @@ -242,15 +238,16 @@ object JavaHelpers { def toErgoTree: ErgoTree = decodeStringToErgoTree(base16) } - implicit val TokenIdRType: RType[TokenId] = collRType(RType.ByteType).asInstanceOf[RType[TokenId]] - implicit val JByteRType: RType[JByte] = RType.ByteType.asInstanceOf[RType[JByte]] - implicit val JShortRType: RType[JShort] = RType.ShortType.asInstanceOf[RType[JShort]] - implicit val JIntRType: RType[JInt] = RType.IntType.asInstanceOf[RType[JInt]] - implicit val JLongRType: RType[JLong] = RType.LongType.asInstanceOf[RType[JLong]] - implicit val JBooleanRType: RType[JBoolean] = RType.BooleanType.asInstanceOf[RType[JBoolean]] + implicit val TokenIdRType: RType[TokenId] = collRType(sigma.ByteType).asInstanceOf[RType[TokenId]] + implicit val JByteRType: RType[JByte] = sigma.ByteType.asInstanceOf[RType[JByte]] + implicit val JShortRType: RType[JShort] = sigma.ShortType.asInstanceOf[RType[JShort]] + implicit val JIntRType: RType[JInt] = sigma.IntType.asInstanceOf[RType[JInt]] + implicit val JLongRType: RType[JLong] = sigma.LongType.asInstanceOf[RType[JLong]] + implicit val JBooleanRType: RType[JBoolean] = sigma.BooleanType.asInstanceOf[RType[JBoolean]] + implicit val JUnitRType: RType[Unit] = sigma.UnitType - val HeaderRType: RType[Header] = special.sigma.HeaderRType - val PreHeaderRType: RType[special.sigma.PreHeader] = special.sigma.PreHeaderRType + val HeaderRType: RType[Header] = sigma.HeaderRType + val PreHeaderRType: RType[sigma.PreHeader] = sigma.PreHeaderRType def Algos: ErgoAlgos = org.ergoplatform.settings.ErgoAlgos @@ -359,17 +356,17 @@ object JavaHelpers { DataInput(ADKey @@ boxIdBytes) } - def collRType[T](tItem: RType[T]): RType[Coll[T]] = special.collection.collRType(tItem) + def collRType[T](tItem: RType[T]): RType[Coll[T]] = sigma.collRType(tItem) - def BigIntRType: RType[special.sigma.BigInt] = special.sigma.BigIntRType + def BigIntRType: RType[sigma.BigInt] = sigma.BigIntRType - def GroupElementRType: RType[special.sigma.GroupElement] = special.sigma.GroupElementRType + def GroupElementRType: RType[sigma.GroupElement] = sigma.GroupElementRType - def SigmaPropRType: RType[special.sigma.SigmaProp] = special.sigma.SigmaPropRType + def SigmaPropRType: RType[sigma.SigmaProp] = sigma.SigmaPropRType - def AvlTreeRType: RType[special.sigma.AvlTree] = special.sigma.AvlTreeRType + def AvlTreeRType: RType[sigma.AvlTree] = sigma.AvlTreeRType - def BoxRType: RType[special.sigma.Box] = special.sigma.BoxRType + def BoxRType: RType[sigma.Box] = sigma.BoxRType def SigmaDsl: CostingSigmaDslBuilder = sigmastate.eval.SigmaDsl @@ -409,7 +406,7 @@ object JavaHelpers { * @return a mapping from asset id to to balance and total assets number */ def extractAssets(boxes: IndexedSeq[ErgoBoxCandidate]): (Map[Digest32Coll, Long], Int) = { - import special.collection.Extensions.CollOps + import sigma.Extensions.CollOps val map = mutable.Map[Digest32Coll, Long]() val assetsNum = boxes.foldLeft(0) { case (acc, box) => require(box.additionalTokens.length <= SigmaConstants.MaxTokens.value, "too many assets in one box") diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala index 52e1565ca3..c03411507e 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/JsonCodecs.scala @@ -16,8 +16,7 @@ import sigmastate.eval.{CPreHeader, WrapperOf, _} import sigmastate.exceptions.SigmaException import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.{AvlTreeData, AvlTreeFlags, SType} -import special.collection.Coll -import special.sigma.{AnyValue, Header, PreHeader} +import sigma.{AnyValue, Coll, Colls, Header, PreHeader} import scala.util.Try import sigmastate.utils.Helpers._ // required for Scala 2.11 @@ -62,11 +61,11 @@ trait JsonCodecs { fromTry(Try.apply(DataJsonEncoder.decodeAnyValue(cursor.value))) }) - implicit val sigmaBigIntEncoder: Encoder[special.sigma.BigInt] = Encoder.instance({ bigInt => + implicit val sigmaBigIntEncoder: Encoder[sigma.BigInt] = Encoder.instance({ bigInt => JsonNumber.fromDecimalStringUnsafe(bigInt.asInstanceOf[WrapperOf[BigInteger]].wrappedValue.toString).asJson }) - implicit val sigmaBigIntDecoder: Decoder[special.sigma.BigInt] = Decoder.instance({ implicit cursor => + implicit val sigmaBigIntDecoder: Decoder[sigma.BigInt] = Decoder.instance({ implicit cursor => for { jsonNumber <- cursor.as[JsonNumber] bigInt <- fromOption(jsonNumber.toBigInt) @@ -153,7 +152,7 @@ trait JsonCodecs { minerPk <- cursor.downField("minerPk").as[Coll[Byte]] powOnetimePk <- cursor.downField("powOnetimePk").as[Coll[Byte]] powNonce <- cursor.downField("powNonce").as[Coll[Byte]] - powDistance <- cursor.downField("powDistance").as[special.sigma.BigInt] + powDistance <- cursor.downField("powDistance").as[sigma.BigInt] votes <- cursor.downField("votes").as[Coll[Byte]] } yield new CHeader(id, version, parentId, adProofsRoot, stateRoot, transactionsRoot, timestamp, nBits, height, extensionRoot, SigmaDsl.decodePoint(minerPk), SigmaDsl.decodePoint(powOnetimePk), powNonce, powDistance, votes) @@ -369,18 +368,16 @@ trait JsonCodecs { implicit val ergoLikeTransactionEncoder: Encoder[ErgoLikeTransaction] = Encoder.instance({ tx => Json.obj( - "type" -> "ELT".asJson, // ErgoLikeTransaction "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, - "outputs" -> tx.outputCandidates.asJson + "outputs" -> tx.outputs.asJson ) }) implicit val ergoLikeTransactionDecoder: Decoder[ErgoLikeTransaction] = Decoder.instance({ implicit cursor => for { - t <- cursor.downField("type").as[String] - inputs <- {require(t == "ELT"); cursor.downField("inputs").as[IndexedSeq[Input]] } + inputs <- cursor.downField("inputs").as[IndexedSeq[Input]] dataInputs <- cursor.downField("dataInputs").as[IndexedSeq[DataInput]] outputs <- cursor.downField("outputs").as[IndexedSeq[ErgoBoxCandidate]] } yield new ErgoLikeTransaction(inputs, dataInputs, outputs) @@ -388,18 +385,16 @@ trait JsonCodecs { implicit val unsignedErgoLikeTransactionEncoder: Encoder[UnsignedErgoLikeTransaction] = Encoder.instance({ tx => Json.obj( - "type" -> "UELT".asJson, // UnsignedErgoLikeTransaction "id" -> tx.id.asJson, "inputs" -> tx.inputs.asJson, "dataInputs" -> tx.dataInputs.asJson, - "outputs" -> tx.outputCandidates.asJson + "outputs" -> tx.outputs.asJson ) }) implicit val unsignedErgoLikeTransactionDecoder: Decoder[UnsignedErgoLikeTransaction] = Decoder.instance({ implicit cursor => for { - t <- cursor.downField("type").as[String] - inputs <- {require(t == "UELT"); cursor.downField("inputs").as[IndexedSeq[UnsignedInput]] } + inputs <- cursor.downField("inputs").as[IndexedSeq[UnsignedInput]] dataInputs <- cursor.downField("dataInputs").as[IndexedSeq[DataInput]] outputs <- cursor.downField("outputs").as[IndexedSeq[ErgoBoxCandidate]] } yield new UnsignedErgoLikeTransaction(inputs, dataInputs, outputs) @@ -411,15 +406,10 @@ trait JsonCodecs { case t => throw new SigmaException(s"Don't know how to encode transaction $t") }) - implicit val ergoLikeTransactionTemplateDecoder: Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]] = Decoder.instance({ implicit cursor => - for { - t <- cursor.downField("type").as[String] - tx <- t match { - case "ELT" => ergoLikeTransactionDecoder(cursor) - case "UELT" => unsignedErgoLikeTransactionDecoder(cursor) - } - } yield tx - }) + implicit val ergoLikeTransactionTemplateDecoder: Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]] = { + ergoLikeTransactionDecoder.asInstanceOf[Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]]] or + unsignedErgoLikeTransactionDecoder.asInstanceOf[Decoder[ErgoLikeTransactionTemplate[_ <: UnsignedInput]]] + } implicit val sigmaValidationSettingsEncoder: Encoder[SigmaValidationSettings] = Encoder.instance({ v => SigmaValidationSettingsSerializer.toBytes(v).asJson diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala index 5c2f531588..61a71fcfa2 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/OutBoxBuilder.scala @@ -3,10 +3,10 @@ package org.ergoplatform.sdk import org.ergoplatform.ErgoBox.TokenId import org.ergoplatform.sdk.JavaHelpers.collRType import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, SigmaConstants} -import scalan.RType +import sigma.Colls +import sigma.data.RType import sigmastate.SType import sigmastate.Values.{Constant, ErgoTree, EvaluatedValue} -import sigmastate.eval.Colls import scala.collection.mutable.ArrayBuffer @@ -68,7 +68,7 @@ object OutBoxBuilder { val nRegs = registers.length require(nRegs <= nonMandatoryRegisters.length, s"Too many additional registers $nRegs. Max allowed ${nonMandatoryRegisters.length}") - implicit val TokenIdRType: RType[TokenId] = collRType(RType.ByteType).asInstanceOf[RType[TokenId]] + implicit val TokenIdRType: RType[TokenId] = collRType(sigma.ByteType).asInstanceOf[RType[TokenId]] val ts = Colls.fromItems(tokens.map(Iso.isoErgoTokenToPair.to(_)): _*) val rs = registers.zipWithIndex.map { case (c, i) => val id = ErgoBox.nonMandatoryRegisters(i) diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ProverBuilder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ProverBuilder.scala index 0704cbe8d6..7422d04ed5 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ProverBuilder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ProverBuilder.scala @@ -2,9 +2,9 @@ package org.ergoplatform.sdk import org.ergoplatform.ErgoAddressEncoder.{MainnetNetworkPrefix, NetworkPrefix} import org.ergoplatform.sdk.wallet.secrets.ExtendedSecretKey -import sigmastate.basics.DLogProtocol.DLogProverInput -import sigmastate.basics.{DLogProtocol, DiffieHellmanTupleProverInput} -import special.sigma.GroupElement +import sigmastate.crypto.DLogProtocol.DLogProverInput +import sigmastate.crypto.{DLogProtocol, DiffieHellmanTupleProverInput} +import sigma.GroupElement import java.math.BigInteger import scala.collection.mutable.ArrayBuffer diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ReducingInterpreter.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ReducingInterpreter.scala index f06c37fd39..1e73c49640 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/ReducingInterpreter.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/ReducingInterpreter.scala @@ -6,8 +6,7 @@ import org.ergoplatform.sdk.utils.ArithUtils import org.ergoplatform.sdk.wallet.protocol.context.{BlockchainStateContext, TransactionContext} import org.ergoplatform.validation.ValidationRules import org.ergoplatform.{ErgoLikeContext, ErgoLikeInterpreter} -import scalan.util.Extensions.LongOps -import scorex.crypto.authds.ADDigest +import sigma.util.Extensions.LongOps import sigmastate.AvlTreeData import sigmastate.Values.ErgoTree import sigmastate.eval.Evaluation.addCostChecked diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala index 4cf8e8b2c3..83ff2e0a10 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SecretString.scala @@ -67,13 +67,13 @@ final class SecretString private[sdk](val _data: Array[Char]) { * Erases secret characters stored in this instance so that they are no longer reside in memory. */ def erase(): Unit = { - util.Arrays.fill(_data, ' ') + java.util.Arrays.fill(_data, ' ') _erased = true } override def hashCode(): Int = { checkErased() - util.Arrays.hashCode(_data) + java.util.Arrays.hashCode(_data) } /** this is adapted version of java.lang.String */ diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SigmaProver.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SigmaProver.scala index 8090627083..aa281f5b10 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/SigmaProver.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/SigmaProver.scala @@ -6,7 +6,7 @@ import org.ergoplatform.sdk.wallet.protocol.context.BlockchainStateContext import sigmastate.eval.{CostingSigmaDslBuilder, SigmaDsl} import sigmastate.interpreter.HintsBag import sigmastate.utils.Helpers.TryOps -import special.sigma.{BigInt, SigmaProp} +import sigma.{BigInt, SigmaProp} /** Represents a prover for signing Ergo transactions and messages. * diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala index 275814a983..8848e73c42 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Transactions.scala @@ -36,7 +36,7 @@ case class UnreducedTransaction( private def checkSameIds( xsName: String, xs: Seq[Array[Byte]], ysName: String, ys: Seq[Array[Byte]], msg: => String) = { - require(xs.zip(ys).forall { case (id1, id2) => util.Arrays.equals(id1, id2) }, { + require(xs.zip(ys).forall { case (id1, id2) => java.util.Arrays.equals(id1, id2) }, { val xsOnly = xs.diff(ys) val ysOnly = ys.diff(xs) s"""$msg: diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/UnsignedTransactionBuilder.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/UnsignedTransactionBuilder.scala index e48f26fd6f..dab4a73efd 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/UnsignedTransactionBuilder.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/UnsignedTransactionBuilder.scala @@ -9,9 +9,9 @@ import org.ergoplatform.sdk.wallet.{AssetUtils, TokensMap} import scorex.util.{ModifierId, bytesToId} import sigmastate.eval.Extensions.ArrayOps import sigmastate.utils.Extensions.ModifierIdOps -import special.collection.Coll -import special.collection.Extensions.CollBytesOps -import special.sigma.PreHeader +import sigma.Coll +import sigma.Extensions.CollBytesOps +import sigma.PreHeader import scala.collection.mutable.ArrayBuffer import scala.util.Try diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Utils.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Utils.scala index f706a09f96..83abf76c72 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/Utils.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/Utils.scala @@ -1,6 +1,6 @@ package org.ergoplatform.sdk -import scalan.ExactIntegral +import sigma.data.ExactIntegral import scala.collection.mutable import scala.reflect.ClassTag diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala index 2115d774a0..6cc7e6718c 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/utils/Zero.scala @@ -1,18 +1,16 @@ package org.ergoplatform.sdk.utils import org.ergoplatform.ErgoBox -import scalan.RType -import scalan.RType._ +import sigma.data.{CollType, FuncType, OptionType, PairType, RType, TupleType} +import sigma.data.RType._ import scorex.crypto.authds.avltree.batch.BatchAVLProver import scorex.crypto.hash.{Blake2b256, Digest32} import scorex.util.ModifierId import sigmastate.Values.ErgoTree -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.CryptoConstants import sigmastate.eval._ import sigmastate.{AvlTreeData, AvlTreeFlags, TrivialProp} -import special.Types.TupleType -import special.collection.{Coll, CollType} -import special.sigma.{AvlTree, AvlTreeRType, BigInt, BigIntRType, Box, BoxRType, GroupElement, GroupElementRType, SigmaProp, SigmaPropRType} +import sigma._ import java.math.BigInteger import scala.language.implicitConversions diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala index 5c8d97df4f..28e79867a5 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/protocol/context/BlockchainStateContext.scala @@ -1,15 +1,20 @@ package org.ergoplatform.sdk.wallet.protocol.context -import special.collection.Coll +import sigma.Coll -/** Blockchain context used in tx signing. - * - * @param sigmaLastHeaders fixed number (10 in Ergo) of last block headers - * @param previousStateDigest UTXO set digest from a last header (of sigmaLastHeaders) - * @param sigmaPreHeader returns pre-header (header without certain fields) of the current block - */ -case class BlockchainStateContext( - sigmaLastHeaders: Coll[special.sigma.Header], +/** Blockchain context used in tx signing. */ +abstract class BlockchainStateContext { + /** Fixed number (10 in Ergo) of last block headers. */ + def sigmaLastHeaders: Coll[sigma.Header] + /** UTXO set digest from a last header (of sigmaLastHeaders). */ + def previousStateDigest: Coll[Byte] + /** Returns pre-header (header without certain fields) of the current block. */ + def sigmaPreHeader: sigma.PreHeader +} + +/** Blockchain context used in tx signing. */ +case class CBlockchainStateContext( + sigmaLastHeaders: Coll[sigma.Header], previousStateDigest: Coll[Byte], - sigmaPreHeader: special.sigma.PreHeader -) + sigmaPreHeader: sigma.PreHeader +) extends BlockchainStateContext diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala index cdc7458b75..2ad287972e 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedPublicKey.scala @@ -1,8 +1,7 @@ package org.ergoplatform.sdk.wallet.secrets -import java.util -import sigmastate.basics.DLogProtocol.{DLogProverInput, ProveDlog} -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.DLogProtocol.{DLogProverInput, ProveDlog} +import sigmastate.crypto.CryptoConstants import sigmastate.crypto.CryptoFacade import sigmastate.crypto.BigIntegers import sigmastate.serialization.SigmaSerializer @@ -29,15 +28,15 @@ final class ExtendedPublicKey(/*private[secrets] */val keyBytes: Array[Byte], override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case that: ExtendedPublicKey => - util.Arrays.equals(that.keyBytes, this.keyBytes) && - util.Arrays.equals(that.chainCode, this.chainCode) && + java.util.Arrays.equals(that.keyBytes, this.keyBytes) && + java.util.Arrays.equals(that.chainCode, this.chainCode) && that.path == this.path case _ => false }) override def hashCode(): Int = { - var h = util.Arrays.hashCode(keyBytes) - h = 31 * h + util.Arrays.hashCode(chainCode) + var h = java.util.Arrays.hashCode(keyBytes) + h = 31 * h + java.util.Arrays.hashCode(chainCode) h = 31 * h + path.hashCode() h } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala index 2842658e66..4b87e31e13 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/ExtendedSecretKey.scala @@ -1,12 +1,10 @@ package org.ergoplatform.sdk.wallet.secrets -import org.ergoplatform.sdk.wallet.Constants import java.math.BigInteger -import java.util import sigmastate.crypto.BigIntegers -import sigmastate.basics.DLogProtocol -import sigmastate.basics.DLogProtocol.DLogProverInput -import sigmastate.basics.CryptoConstants +import sigmastate.crypto.DLogProtocol +import sigmastate.crypto.DLogProtocol.DLogProverInput +import sigmastate.crypto.CryptoConstants import sigmastate.crypto.CryptoFacade import sigmastate.serialization.SigmaSerializer import sigmastate.utils.{SigmaByteReader, SigmaByteWriter} @@ -34,19 +32,19 @@ final class ExtendedSecretKey(/*private[secrets]*/ val keyBytes: Array[Byte], def isErased: Boolean = keyBytes.forall(_ == 0x00) - def zeroSecret(): Unit = util.Arrays.fill(keyBytes, 0: Byte) + def zeroSecret(): Unit = java.util.Arrays.fill(keyBytes, 0: Byte) override def equals(obj: Any): Boolean = (this eq obj.asInstanceOf[AnyRef]) || (obj match { case that: ExtendedSecretKey => - util.Arrays.equals(that.keyBytes, this.keyBytes) && - util.Arrays.equals(that.chainCode, this.chainCode) && + java.util.Arrays.equals(that.keyBytes, this.keyBytes) && + java.util.Arrays.equals(that.chainCode, this.chainCode) && that.path == this.path case _ => false }) override def hashCode(): Int = { - var h = util.Arrays.hashCode(keyBytes) - h = 31 * h + util.Arrays.hashCode(chainCode) + var h = java.util.Arrays.hashCode(keyBytes) + h = 31 * h + java.util.Arrays.hashCode(chainCode) h = 31 * h + path.hashCode() h } diff --git a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/SecretKey.scala b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/SecretKey.scala index 73ce7d39ea..7fb8cc7481 100644 --- a/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/SecretKey.scala +++ b/sdk/shared/src/main/scala/org/ergoplatform/sdk/wallet/secrets/SecretKey.scala @@ -1,7 +1,7 @@ package org.ergoplatform.sdk.wallet.secrets -import sigmastate.basics.DLogProtocol.DLogProverInput -import sigmastate.basics.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} +import sigmastate.crypto.DLogProtocol.DLogProverInput +import sigmastate.crypto.{DiffieHellmanTupleProverInput, SigmaProtocolPrivateInput} /** * Basic trait for secret data, encapsulating a corresponding private inputs for a Sigma protocol. diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/ContractTemplateSpecification.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/ContractTemplateSpecification.scala index c660f44e02..268012ac3c 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/ContractTemplateSpecification.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/ContractTemplateSpecification.scala @@ -8,7 +8,7 @@ import sigmastate._ import sigmastate.eval.CBigInt import sigmastate.helpers.NegativeTesting import sigmastate.serialization.{SerializationSpecification, SigmaSerializer} -import special.sigma.ContractsTestkit +import sigma.ContractsTestkit import java.math.BigInteger diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala index cdcd0906c0..89330bc759 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/DataJsonEncoderSpecification.scala @@ -2,20 +2,23 @@ package org.ergoplatform.sdk import java.math.BigInteger - import org.scalacheck.Arbitrary._ -import scalan.RType +import org.scalacheck.Gen +import sigma.data.RType import sigmastate.SCollection.SByteArray import sigmastate.SType.AnyOps import sigmastate.Values.SigmaBoolean import sigmastate._ import sigmastate.eval.Extensions._ import sigmastate.eval.{Evaluation, _} -import sigmastate.basics.CryptoConstants.EcPointType +import sigmastate.crypto.CryptoConstants.EcPointType import sigmastate.exceptions.SerializerException -import special.sigma.{Box, AvlTree} +import sigma.{AvlTree, Box, Colls} import sigmastate.serialization.SerializationSpecification +import scala.annotation.nowarn +import scala.reflect.ClassTag + class DataJsonEncoderSpecification extends SerializationSpecification { object JsonCodecs extends JsonCodecs @@ -47,9 +50,9 @@ class DataJsonEncoderSpecification extends SerializationSpecification { } def testTuples[T <: SType](tpe: T) = { - implicit val wWrapped = wrappedTypeGen(tpe) - implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny = RType.AnyType + implicit val wWrapped: Gen[T#WrappedType] = wrappedTypeGen(tpe) + implicit val tag : ClassTag[T#WrappedType] = tpe.classTag[T#WrappedType] + implicit val tAny : RType[Any] = sigma.AnyType forAll { in: (T#WrappedType, T#WrappedType) => val (x,y) = (in._1, in._2) roundtrip[SType]((x, y).asWrappedType, STuple(tpe, tpe)) @@ -58,11 +61,11 @@ class DataJsonEncoderSpecification extends SerializationSpecification { } } - def testAnyValue[T <: SType](tpe: T) = { + @nowarn def testAnyValue[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tag = tpe.classTag[T#WrappedType] implicit val tT = Evaluation.stypeToRType(tpe) - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { in: T#WrappedType => val x = CAnyValue(in) val json = JsonCodecs.anyValueEncoder(x) @@ -181,7 +184,7 @@ class DataJsonEncoderSpecification extends SerializationSpecification { def testEncodeError[T <: SType](tpe: T) = { implicit val wWrapped = wrappedTypeGen(tpe) implicit val tag = tpe.classTag[T#WrappedType] - implicit val tAny = RType.AnyType + implicit val tAny = sigma.AnyType forAll { x: T#WrappedType => an[SerializerException] should be thrownBy { DataJsonEncoder.encode(TupleColl(x, x, x).asWrappedType, STuple(tpe, tpe, tpe)) diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/ExtensionsSpec.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/ExtensionsSpec.scala index 72c75ace73..f250b9fce5 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/ExtensionsSpec.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/ExtensionsSpec.scala @@ -3,10 +3,9 @@ package org.ergoplatform.sdk import org.scalatest.matchers.should.Matchers import org.scalatest.propspec.AnyPropSpec import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks -import special.collection.Coll -import special.collections.CollGens +import sigma.{Coll, CollGens} import org.ergoplatform.sdk.Extensions.{CollBuilderOps, CollOps, GenIterableOps, PairCollOps} -import scalan.RType +import sigma.data.RType import sigmastate.eval.CostingSigmaDslBuilder class ExtensionsSpec extends AnyPropSpec with ScalaCheckPropertyChecks with Matchers with CollGens { diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/JsonSerializationSpec.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/JsonSerializationSpec.scala index e85757985e..70615d6796 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/JsonSerializationSpec.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/JsonSerializationSpec.scala @@ -11,14 +11,14 @@ import scorex.util.ModifierId import scorex.util.encode.Base16 import sigmastate.{AvlTreeData, SType} import sigmastate.Values.{ByteArrayConstant, ByteConstant, ErgoTree, EvaluatedValue, IntConstant, LongArrayConstant, SigmaPropConstant} -import sigmastate.basics.CryptoConstants -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.CryptoConstants +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.eval.Digest32Coll import sigmastate.interpreter.{ContextExtension, ProverResult} import sigmastate.serialization.SerializationSpecification import sigmastate.utils.Helpers.DecoderResultOps // required for Scala 2.11 (extension method toTry) -import special.collection.Coll -import special.sigma.{Header, PreHeader} +import sigma.Coll +import sigma.{Header, PreHeader} import org.ergoplatform.{DataInput, ErgoBox, ErgoBoxCandidate, ErgoLikeContext, ErgoLikeTransaction, ErgoLikeTransactionTemplate, Input, UnsignedErgoLikeTransaction, UnsignedInput} import scala.collection.mutable @@ -35,7 +35,7 @@ class JsonSerializationSpec extends SerializationSpecification with JsonCodecs { } property("sigma.BigInt should be encoded into JSON and decoded back correctly") { - forAll { v: special.sigma.BigInt => jsonRoundTrip(v) } + forAll { v: sigma.BigInt => jsonRoundTrip(v) } } property("byte array should be encoded into JSON and decoded back correctly") { diff --git a/sdk/shared/src/test/scala/org/ergoplatform/sdk/wallet/utils/Generators.scala b/sdk/shared/src/test/scala/org/ergoplatform/sdk/wallet/utils/Generators.scala index e4cc09c4a2..80164f5f23 100644 --- a/sdk/shared/src/test/scala/org/ergoplatform/sdk/wallet/utils/Generators.scala +++ b/sdk/shared/src/test/scala/org/ergoplatform/sdk/wallet/utils/Generators.scala @@ -9,7 +9,7 @@ import org.scalacheck.Arbitrary.arbByte import org.scalacheck.{Arbitrary, Gen} import scorex.crypto.authds.ADKey import sigmastate.Values.{ByteArrayConstant, CollectionConstant, ErgoTree, EvaluatedValue, FalseLeaf, TrueLeaf} -import sigmastate.basics.DLogProtocol.ProveDlog +import sigmastate.crypto.DLogProtocol.ProveDlog import sigmastate.{SByte, SType} import scorex.util._ import org.ergoplatform.{ErgoBox, ErgoBoxCandidate, ErgoTreePredef, UnsignedErgoLikeTransaction, UnsignedInput}