Skip to content

Commit

Permalink
towards-data-module: trees.scala moved to sigma.ast
Browse files Browse the repository at this point in the history
  • Loading branch information
aslesarenko committed Oct 6, 2023
1 parent cd36fbf commit d99cdc9
Show file tree
Hide file tree
Showing 42 changed files with 68 additions and 93 deletions.
2 changes: 0 additions & 2 deletions interpreter/shared/src/main/scala/sigma/ast/CostKind.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package sigma.ast

import sigmastate.{EQ, NEQ}

import scala.runtime.Statics

/** Cost descriptor of a single operation, usually associated with
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package sigmastate
package sigma.ast

import debox.{cfor, Map => DMap}
import scorex.crypto.hash.{Blake2b256, CryptographicHash32, Sha256}
import sigma.ast.ArithOp.OperationImpl
import sigma.ast.Operations._
import sigma.ast.SCollection.{SByteArray, SIntArray}
import sigma.ast.SOption.SIntOption
import sigma.ast.global._
import sigma.data.ExactIntegral._
import sigma.data.ExactOrdering._
import sigma.data.OverloadHack.Overloaded1
import sigma.data.{CAND, COR, CTHRESHOLD, ExactIntegral, ExactOrdering, SigmaBoolean, SigmaConstants}
import scorex.crypto.hash.{Blake2b256, CryptographicHash32, Sha256}
import sigma.ast.SCollection
import sigma.ast.SCollection.{SByteArray, SIntArray}
import sigma.ast.SOption.SIntOption
import sigma.{Coll, Colls, GroupElement, SigmaProp, VersionContext}
import sigmastate.ArithOp.OperationImpl
import sigma.ast.Operations._
import sigma.ast._
import sigma.serialization.CoreByteWriter.ArgInfo
import sigma.validation.SigmaValidationSettings
import sigma.ast.global._
import sigma.{Coll, Colls, GroupElement, SigmaProp, VersionContext}
import sigmastate.DataValueComparer
import sigmastate.eval.Extensions.EvalCollOps
import sigmastate.eval.NumericOps.{BigIntIsExactIntegral, BigIntIsExactOrdering}
import sigmastate.eval.SigmaDsl
Expand Down Expand Up @@ -676,7 +675,7 @@ object SubstConstants extends ValueCompanion {
/** Transforms serialized bytes of ErgoTree with segregated constants by
* replacing constants at given positions with new values. This operation
* allow to use serialized scripts as pre-defined templates.
* See [[sigmastate.SubstConstants]] for details.
* See [[SubstConstants]] for details.
*
* @param scriptBytes serialized ErgoTree with ConstantSegregationFlag set to 1.
* @param positions zero based indexes in ErgoTree.constants array which
Expand Down Expand Up @@ -865,7 +864,7 @@ object ArithOp {
}
}

private[sigmastate] val operations: DMap[Byte, ArithOpCompanion] =
private[sigma] val operations: DMap[Byte, ArithOpCompanion] =
DMap.fromIterable(Seq(Plus, Minus, Multiply, Division, Modulo, Min, Max).map(o => (o.opCode, o)))

/** Represents implementation of numeric Arith operations for the given type argTpe. */
Expand All @@ -874,7 +873,7 @@ object ArithOp {
val o = _o.asInstanceOf[ExactOrdering[Any]]
}

private[sigmastate] val impls: DMap[SType.TypeCode, OperationImpl] =
private[sigma] val impls: DMap[SType.TypeCode, OperationImpl] =
DMap.fromIterable(Seq(
SByte -> new OperationImpl(ByteIsExactIntegral, ByteIsExactOrdering, SByte),
SShort -> new OperationImpl(ShortIsExactIntegral, ShortIsExactOrdering, SShort),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.ergoplatform.validation.ValidationRules
import scorex.crypto.hash.{Blake2b256, Sha256}
import scorex.utils.Longs
import sigma.Extensions.ArrayOps
import sigma.ast.{AtLeast, SubstConstants}
import sigma.crypto.{EcPointType, Ecp}
import sigma.data._
import sigma.serialization.GroupElementSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sigmastate.interpreter

import sigma.ast.{FixedCost, JitCost, PerItemCost, SMethod, SType, TypeBasedCost}
import sigma.ast.{FixedCostValueCompanion, PerItemCostValueCompanion, ValueCompanion}
import sigma.ast.{FixedCost, FixedCostValueCompanion, GT, JitCost, LE, PerItemCost, PerItemCostValueCompanion, SMethod, SType, TypeBasedCost, ValueCompanion}
import sigmastate.lang.Terms.MethodCall

/** An item in the cost accumulation trace of a [[sigma.ast.ErgoTree]] evaluation. */
Expand Down Expand Up @@ -35,7 +34,7 @@ object FixedCostItem {
* @param opDesc descriptor of the ErgoTree operation
* @param costKind type based cost descriptor added to accumulator
* @param tpe concrete type on this the operation is executed
* @see [[sigmastate.LE]], [[sigmastate.GT]]
* @see [[LE]], [[GT]]
*/
case class TypeBasedCostItem(
opDesc: OperationDesc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ object ErgoTreeEvaluator {
type DataEnv = Map[Int, Any]

/** Size of data block in bytes. Used in JIT cost calculations.
* @see [[sigmastate.NEQ]],
* @see [[NEQ]],
*/
val DataBlockSize: Int = 512

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package sigmastate.serialization

import sigma.ast._
import sigma.ast.{BoolToSigmaProp, _}
import sigma.ast.global._
import sigma.serialization.CoreByteWriter.DataInfo
import sigmastate.BoolToSigmaProp
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package sigmastate.serialization

import sigma.ast.SGroupElement
import sigma.ast.{CreateProveDlog, SGroupElement}
import sigma.serialization.CoreByteWriter._
import sigmastate.CreateProveDlog
import sigma.ast.Value
import sigma.ast.global._
import sigmastate.lang.Terms.ValueOps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sigmastate.serialization

import org.ergoplatform.validation.ValidationRules.{CheckDeserializedScriptIsSigmaProp, CheckHeaderSizeBit}
import sigma.ast.Constant
import sigma.ast.{Constant, SType, SubstConstants}
import sigmastate.lang.DeserializationSigmaBuilder
import sigmastate.lang.Terms.ValueOps
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
Expand All @@ -10,7 +10,6 @@ import sigma.util.safeNewArray
import sigmastate.utxo.ComplexityTable
import debox.cfor
import sigma.VersionContext
import sigma.ast.SType
import sigma.serialization.{ReaderPositionLimitExceeded, SerializerException}
import sigma.validation.{SigmaValidationSettings, ValidationException}
import sigma.validation.ValidationRules.CheckPositionLimit
Expand Down Expand Up @@ -291,7 +290,7 @@ class ErgoTreeSerializer {
/** Transforms serialized bytes of ErgoTree with segregated constants by
* replacing constants at given positions with new values. This operation
* allow to use serialized scripts as pre-defined templates.
* See [[sigmastate.SubstConstants]] for details.
* See [[SubstConstants]] for details.
*
* @param scriptBytes serialized ErgoTree with ConstantSegregationFlag set to 1.
* @param positions zero based indexes in ErgoTree.constants array which
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sigmastate.serialization

import sigma.ast.LogicalNot
import sigma.serialization.CoreByteWriter.DataInfo
import sigmastate.LogicalNot
import sigma.ast.Operations.LogicalNotInfo.inputArg
import sigma.ast.global._
import sigmastate.lang.Terms._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package sigmastate.serialization

import sigma.ast.SType
import sigma.ast.{ModQArithOp, ModQArithOpCompanion, SType}
import sigma.ast.global.{BigIntValue, SValue}
import sigma.serialization.CoreByteWriter.DataInfo
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigmastate.{ModQArithOp, ModQArithOpCompanion}

// TODO v6.0: make sure it is covered with tests (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/327)
case class ModQArithOpSerializer(override val opDesc: ModQArithOpCompanion, cons: (BigIntValue, BigIntValue) => BigIntValue)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sigmastate.serialization

import sigma.ast.SType
import sigmastate.ModQ
import sigma.ast.{ModQ, SType}
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package sigmastate.serialization

import sigma.ast.SType
import sigma.ast.{OneArgumentOperation, OneArgumentOperationCompanion, SType}
import sigma.serialization.CoreByteWriter.DataInfo
import sigma.ast.Value
import sigma.ast.global.SValue
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigmastate.{OneArgumentOperation, OneArgumentOperationCompanion}

case class OneArgumentOperationSerializer[T <: SType](opDesc: OneArgumentOperationCompanion, cons: Value[T] => SValue)
extends ValueSerializer[OneArgumentOperation[T, SType]] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package sigmastate.serialization

import sigma.ast.SCollection.{SByteArray, SIntArray}
import sigma.ast.global.SValue
import sigma.ast.Value
import sigma.ast.{SubstConstants, Value}
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigma.ast.{SCollection, SType}
import sigma.serialization.CoreByteWriter.DataInfo
import sigmastate.SubstConstants

object SubstConstantsSerializer extends ValueSerializer[SubstConstants[SType]] {
import sigma.ast.Operations.SubstConstantsInfo._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package sigmastate.serialization

import sigma.ast.SType
import sigma.ast.{SType, TwoArgumentOperationCompanion, TwoArgumentsOperation}
import sigma.ast.global.SValue
import sigma.serialization.CoreByteWriter.DataInfo
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigmastate.{TwoArgumentOperationCompanion, TwoArgumentsOperation}

case class TwoArgumentsSerializer[LIV <: SType, RIV <: SType, OV <: Value[SType]]
(override val opDesc: TwoArgumentOperationCompanion, constructor: (Value[LIV], Value[RIV]) => Value[SType])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package sigmastate.serialization.transformers

import sigma.ast.global.SigmaPropValue
import sigma.ast.{SCollection, SInt, SSigmaProp}
import sigma.ast.{AtLeast, SCollection, SInt, SSigmaProp, Value}
import sigma.ast.Operations.AtLeastInfo
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate._
import sigmastate.serialization.ValueSerializer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package sigmastate.serialization.transformers

import sigma.ast.SGroupElement
import sigma.ast.{CreateProveDHTuple, SGroupElement}
import sigma.ast.global.SigmaPropValue
import sigmastate.CreateProveDHTuple
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate.serialization._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package sigmastate.serialization.transformers

import sigma.ast.global.SValue
import sigma.ast.{SBoolean, SCollection}
import sigma.ast.{LogicalTransformerCompanion, SBoolean, SCollection}
import sigma.serialization.CoreByteWriter.DataInfo
import sigma.ast.Value
import sigmastate.lang.Terms._
import sigmastate.serialization.ValueSerializer
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import sigmastate.utxo.Transformer
import sigmastate.LogicalTransformerCompanion

case class LogicalTransformerSerializer[I <: SCollection[SBoolean.type], O <: SBoolean.type]
(opDesc: LogicalTransformerCompanion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sigmastate.serialization.transformers

import sigma.ast.global.SValue
import sigma.ast.{SNumericType, SType, Value}
import sigma.ast.{NumericCastCompanion, SNumericType, SType, Value}
import sigma.serialization.CoreByteWriter.{ArgInfo, DataInfo}
import sigmastate._
import sigmastate.lang.Terms._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package sigmastate.serialization.transformers

import sigmastate.{SigmaTransformer, SigmaTransformerCompanion}
import sigma.ast.global.{SValue, SigmaPropValue}
import sigmastate.serialization.ValueSerializer
import sigma.util.safeNewArray
import sigmastate.utils.SigmaByteWriter._
import sigmastate.utils.{SigmaByteReader, SigmaByteWriter}
import debox.cfor
import sigma.ast.{SigmaTransformer, SigmaTransformerCompanion}
import sigma.serialization.CoreByteWriter.DataInfo

case class SigmaTransformerSerializer[I <: SigmaPropValue, O <: SigmaPropValue]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sigmastate

import org.scalatest.prop.TableFor2
import scorex.util.encode.Base16
import sigma.ast.{ByteArrayConstant, SByte}
import sigma.ast.{ByteArrayConstant, CalcSha256, EQ, SByte}
import sigma.ast.global.CollectionConstant
import sigma.data.TrivialProp
import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, TestingCommons}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package sigmastate.crypto

import org.scalacheck.Gen
import scorex.util.encode.Base16
import sigma.ast.AtLeast
import sigma.data.{CAND, COR, ProveDHTuple, SigmaBoolean}
import sigma.serialization.ProveDHTupleSerializer
import sigmastate.{AtLeast, ErgoTree}
import sigmastate.{ErgoTree}
import sigmastate.crypto.DLogProtocol.DLogProverInput
import sigmastate.helpers.{ErgoLikeTestInterpreter, ErgoLikeTestProvingInterpreter, TestingCommons}
import sigmastate.interpreter.{ContextExtension, HintsBag, ProverResult}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package sigmastate.serialization

import sigma.ast.{BooleanConstant, Constant, IntConstant}
import sigma.ast.{AND, BooleanConstant, Constant, EQ, IntConstant, SBoolean, SCollection, SCollectionType, SInt}
import sigmastate._
import sigmastate.serialization.OpCodes._
import scorex.util.encode.ZigZagEncoder.encodeZigZagInt
import sigma.Extensions.ArrayOps
import sigma.ast.global.BooleanConstant
import sigma.ast.{SBoolean, SCollection, SCollectionType, SInt}

class AndSerializerSpecification extends TableSerializationSpecification {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sigmastate.serialization

import sigma.ast.ModQ
import sigma.ast.global.BigIntConstant
import sigmastate._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package sigmastate.serialization

import sigma.ast.{BooleanConstant, Constant, IntConstant}
import sigma.ast.{BooleanConstant, Constant, EQ, IntConstant, OR, SBoolean, SCollection, SCollectionType, SInt}
import sigmastate._
import sigmastate.serialization.OpCodes._
import scorex.util.encode.ZigZagEncoder.encodeZigZagInt
import sigma.Extensions.ArrayOps
import sigma.ast.global.BooleanConstant
import sigma.ast.{SBoolean, SCollection, SCollectionType, SInt}

class OrSerializerSpecification extends TableSerializationSpecification {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package sigmastate.serialization

import sigma.ast.SInt
import sigma.ast.{EQ, SInt, SubstConstants}
import sigma.ast.global.IntValue
import sigma.ast.{ConcreteCollection, IntArrayConstant, IntConstant}
import sigmastate.serialization.ErgoTreeSerializer.DefaultSerializer
import sigmastate.{CrossVersionProps, EQ, SubstConstants}
import sigmastate.CrossVersionProps

class SubstConstantsSerializerSpecification extends SerializationSpecification
with CrossVersionProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigmastate.serialization

import sigma.ast.{SBoolean, SInt}
import sigma.ast.{AtLeast, ByteArrayToBigInt, CalcBlake2b256, CalcSha256, LongToByteArray, SBoolean, SInt, XorOf}
import sigmastate._
import sigmastate.utxo._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package sigmastate.serialization
import scorex.util.encode.ZigZagEncoder.encodeZigZagLong
import sigma.ast.ByteArrayConstant.ByteArrayTypeCode
import sigma.ast.global.{BigIntConstant, GroupElementConstant, LongConstant}
import sigma.ast.{ByteArrayConstant, LongConstant, SLong}
import sigma.ast.{ArithOp, ByteArrayConstant, Exponentiate, LongConstant, MultiplyGroup, SLong, Xor}
import sigmastate._
import sigmastate.serialization.OpCodes._
import sigmastate.serialization.ValueCodes.OpCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package sigmastate.serialization

import org.ergoplatform.Outputs
import sigma.ast.{SInt, SLong}
import sigma.ast.{SInt, SLong, Upcast}
import sigma.ast.{ByteConstant, IntConstant, LongConstant}
import sigmastate.lang.CheckingSigmaBuilder
import sigmastate.utxo.ByIndex
import sigmastate.Upcast

class UpcastOnDeserializationSpecification extends SerializationSpecification {
import CheckingSigmaBuilder._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package sigmastate.serialization.generators

import org.scalacheck.{Arbitrary, Gen}
import sigma.ast.SInt
import sigma.ast.{If, SInt, TreeLookup}
import sigma.ast.{FalseLeaf, TrueLeaf}
import sigmastate.{If, TreeLookup}

trait RelationGenerators {
this: ObjectGenerators with ConcreteCollectionGenerators =>
Expand Down
Loading

0 comments on commit d99cdc9

Please sign in to comment.