Skip to content

Commit

Permalink
Merge pull request #944 from ScorexFoundation/unused-code
Browse files Browse the repository at this point in the history
Removing unused code #1
  • Loading branch information
aslesarenko authored Dec 26, 2023
2 parents 4ad22f0 + 6235b66 commit 112346c
Show file tree
Hide file tree
Showing 26 changed files with 62 additions and 146 deletions.
1 change: 0 additions & 1 deletion core/js/src/main/scala/sigma/crypto/Platform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package sigma.crypto

import sigma.data.RType
import scorex.util.encode.Base16
import sigmastate._
import sigma.Coll
import sigma._
import sigma.ast._
Expand Down
6 changes: 0 additions & 6 deletions core/shared/src/main/scala/sigma/ast/SType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -731,12 +731,6 @@ object SCollection extends STypeCompanion {
case class STuple(items: IndexedSeq[SType]) extends SCollection[SAny.type] {
override val typeCode = STuple.TupleTypeCode

/** Lazily computed value representing true | false | none.
* 0 - none, 1 - false, 2 - true
*/
@volatile
private var _isConstantSizeCode: Byte = 0.toByte

override def elemType: SAny.type = SAny

override val typeParams = Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import sigma.utils.SparseArrayContainer
import scala.collection.mutable

abstract class ValueSerializer[V <: Value[SType]] extends SigmaSerializer[Value[SType], V] {
import scala.language.implicitConversions
private val companion = ValueSerializer

def getComplexity: Int = OpCodeComplexity.getOrElse(opCode, MinimalComplexity)
lazy val complexity: Int = getComplexity
Expand Down Expand Up @@ -251,7 +249,7 @@ object ValueSerializer extends SigmaSerializerCompanion[Value[SType]] {

def printSerInfo(): String = {
serializerInfo.map { case (_, s) =>
val ser = getSerializer(s.opCode)
getSerializer(s.opCode) // sanity check to make sure only resolvable serializers got printed
s.toString
}.mkString("\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class ErgoLikeContext(val lastBlockUtxoRoot: AvlTreeData,
def withTransaction(newSpendingTransaction: ErgoLikeTransactionTemplate[_ <: UnsignedInput]): ErgoLikeContext =
ErgoLikeContext.copy(this)(spendingTransaction = newSpendingTransaction)

override def toSigmaContext(extensions: Map[Byte, AnyValue] = Map()): sigma.Context = {
override def toSigmaContext(): sigma.Context = {
import sigma.Evaluation._

def contextVars(m: Map[Byte, AnyValue]): Coll[AnyValue] = {
Expand All @@ -160,7 +160,7 @@ class ErgoLikeContext(val lastBlockUtxoRoot: AvlTreeData,
val tVal = stypeToRType[SType](v.tpe)
k -> toAnyValue(v.value.asWrappedType)(tVal)
}.toMap
val vars = contextVars(varMap ++ extensions)
val vars = contextVars(varMap)
val avlTree = CAvlTree(lastBlockUtxoRoot)
// so selfBox is never one of the `inputs` instances
// as result selfBoxIndex is always (erroneously) returns -1 in ErgoTree v0, v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ trait Interpreter {
def fullReduction(ergoTree: ErgoTree,
ctx: CTX,
env: ScriptEnv): ReductionResult = {
implicit val vs: SigmaValidationSettings = ctx.validationSettings
val context = ctx.withErgoTreeVersion(ergoTree.version).asInstanceOf[CTX]
VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) {
val prop = propositionFromErgoTree(ergoTree, context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package sigmastate.interpreter

import sigma.AnyValue
import sigma.interpreter.ContextExtension
import sigma.interpreter.ContextExtension.VarBinding
import sigma.validation.SigmaValidationSettings


/** Base class of the context passed to verifier and prover.
* @see [[sigmastate.interpreter.Interpreter]]
*/
Expand Down Expand Up @@ -62,12 +60,8 @@ trait InterpreterContext {
* Thus, this method performs transformation from Ergo to internal Sigma representation
* of all context data.
*
* @param extensions additional context variables which will be merged with those in the
* `extension` of this instance, overriding existing bindings in case
* variable ids overlap.
*
* @see sigmastate.eval.Evaluation
*/
def toSigmaContext(extensions: Map[Byte, AnyValue] = Map()): sigma.Context
def toSigmaContext(): sigma.Context
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ trait Exprs extends Core with Types {
// varies.

// Expressions used as statements, directly within a {block}
object StatCtx extends WsCtx(semiInference=true, arrowTypeAscriptions=false)
object StatCtx extends WsCtx(semiInference=true)
// Expressions nested within other expressions
object ExprCtx extends WsCtx(semiInference=false, arrowTypeAscriptions=true)
object ExprCtx extends WsCtx(semiInference=false)
// Expressions directly within a `val x = ...` or `def x = ...`
object FreeCtx extends WsCtx(semiInference=true, arrowTypeAscriptions=true)
object FreeCtx extends WsCtx(semiInference=true)

override def TypeExpr[_:P]: P[Value[SType]] = ExprCtx.Expr

Expand All @@ -37,7 +37,7 @@ trait Exprs extends Core with Types {

//noinspection TypeAnnotation,ForwardReference
/** Parsing context of expressions (see derived classes). */
class WsCtx(semiInference: Boolean, arrowTypeAscriptions: Boolean) {
class WsCtx(semiInference: Boolean) {

private def OneSemiMax[_:P]: P[Unit] = if (semiInference) OneNLMax else Pass
private def NoSemis[_:P]: P[Unit] = if (semiInference) NotNewline else Pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import org.ergoplatform.ErgoBox.{BoxId, NonMandatoryRegisterId, TokenId}
import sigma.interpreter.{CostedProverResult, ProverResult}
import sigma.data.{CSigmaDslBuilder, RType}
import org.ergoplatform.{ErgoBox, ErgoLikeContext}
import sigma.{AnyValue, Coll, SigmaDslBuilder, SigmaProp}
import sigma.{Coll, SigmaDslBuilder, SigmaProp}
import sigmastate.eval.IRContext

import scala.util.Try
import org.ergoplatform.dsl.ContractSyntax.{ErgoScript, Proposition, Token}
import sigma.ast.ErgoTree
import sigma.ast.{ErgoTree, EvaluatedValue, SType}

import scala.language.implicitConversions

trait ContractSpec {
Expand Down Expand Up @@ -48,7 +49,7 @@ trait ContractSpec {

/** Generate proof for the given `inBox`. The input box has attached guarding proposition,
* which is executed in the Context, specifically created for `inBox`.*/
def prove(inBox: InputBox, extensions: Map[Byte, AnyValue] = Map()): Try[CostedProverResult]
def prove(inBox: InputBox, extensions: Map[Byte, EvaluatedValue[_ <: SType]] = Map()): Try[CostedProverResult]
}
object ProvingParty {
def apply(name: String): ProvingParty = mkProvingParty(name)
Expand All @@ -67,7 +68,7 @@ trait ContractSpec {
trait InputBox {
def tx: TransactionCandidate
def utxoBox: OutBox
def runDsl(extensions: Map[Byte, AnyValue] = Map()): SigmaProp
def runDsl(extensions: Map[Byte, EvaluatedValue[_ <: SType]] = Map()): SigmaProp
private [dsl] def toErgoContext: ErgoLikeContext
}

Expand Down
46 changes: 23 additions & 23 deletions sc/shared/src/main/scala/scalan/GraphIRReflection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ object GraphIRReflection {
mkMethod(clazz, "filter", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.WOption[Any]].filter(args(0).asInstanceOf[ctx.Ref[Any => Boolean]])
},
mkMethod(clazz, "get", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "get", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.WOption[_]].get
},
mkMethod(clazz, "isDefined", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isDefined", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.WOption[_]].isDefined
},
mkMethod(clazz, "getOrElse", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
Expand Down Expand Up @@ -76,10 +76,10 @@ object GraphIRReflection {
mkMethod(clazz, "$bar$bar", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.SigmaProp].$bar$bar(args(0).asInstanceOf[ctx.Ref[ctx.SigmaProp]])
},
mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isValid", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.SigmaProp].isValid
},
mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "propBytes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.SigmaProp].propBytes
},
mkMethod(clazz, "$amp$amp", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
Expand Down Expand Up @@ -221,26 +221,26 @@ object GraphIRReflection {
obj.asInstanceOf[ctx.AvlTree].update(args(0).asInstanceOf[ctx.Ref[ctx.Coll[(ctx.Coll[Byte], ctx.Coll[Byte])]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "keyLength", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].keyLength
},
mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "enabledOperations", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].enabledOperations
},
mkMethod(clazz, "updateDigest", Array[Class[_]](classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.AvlTree].updateDigest(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "digest", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].digest
},
mkMethod(clazz, "insert", Array[Class[_]](classOf[Base#Ref[_]], classOf[Base#Ref[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.AvlTree].insert(args(0).asInstanceOf[ctx.Ref[ctx.Coll[(ctx.Coll[Byte], ctx.Coll[Byte])]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isRemoveAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isRemoveAllowed
},
mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "valueLengthOpt", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].valueLengthOpt
},
mkMethod(clazz, "get", Array[Class[_]](classOf[Base#Ref[_]], classOf[Base#Ref[_]])) { (obj, args) =>
Expand All @@ -254,10 +254,10 @@ object GraphIRReflection {
obj.asInstanceOf[ctx.AvlTree].contains(args(0).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]],
args(1).asInstanceOf[ctx.Ref[ctx.Coll[Byte]]])
},
mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isUpdateAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isUpdateAllowed
},
mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "isInsertAllowed", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.AvlTree].isInsertAllowed
}
)
Expand All @@ -268,22 +268,22 @@ object GraphIRReflection {
val ctx = null.asInstanceOf[SigmaLibrary] // ok! type level only
registerClassEntry(clazz,
methods = Map(
mkMethod(clazz, "value", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "value", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].value
},
mkMethod(clazz, "id", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "id", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].id
},
mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "creationInfo", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].creationInfo
},
mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "bytes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].bytes
},
mkMethod(clazz, "getReg", Array[Class[_]](classOf[Base#Ref[_]], classOf[TypeDescs#Elem[_]])) { (obj, args) =>
obj.asInstanceOf[ctx.Box].getReg(args(0).asInstanceOf[ctx.Ref[Int]])(args(1).asInstanceOf[ctx.Elem[_]])
},
mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "tokens", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.Box].tokens
},
mkMethod(clazz, "bytesWithoutRef", Array[Class[_]]()) { (obj, args) =>
Expand Down Expand Up @@ -415,25 +415,25 @@ object GraphIRReflection {
val ctx = null.asInstanceOf[SigmaLibrary] // ok! type level only
registerClassEntry(clazz,
methods = Map(
mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "minerPk", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].minerPk
},
mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "votes", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].votes
},
mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "nBits", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].nBits
},
mkMethod(clazz, "version", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "version", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].version
},
mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "timestamp", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].timestamp
},
mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "parentId", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].parentId
},
mkMethod(clazz, "height", Array[Class[_]]()) { (obj, args) =>
mkMethod(clazz, "height", Array[Class[_]]()) { (obj, _) =>
obj.asInstanceOf[ctx.PreHeader].height
}
)
Expand Down
1 change: 0 additions & 1 deletion sc/shared/src/main/scala/scalan/TypeDescs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package scalan
import scala.language.implicitConversions
import scala.annotation.implicitNotFound
import scala.collection.immutable.ListMap
import sigma.data.RType._

import scala.collection.mutable
import debox.cfor
Expand Down
4 changes: 0 additions & 4 deletions sc/shared/src/main/scala/scalan/primitives/Tuples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ trait Tuples extends Base { self: Scalan =>
case Tup(a, b) => (a, b)
case _ => p.elem match {
case pe: PairElem[_, _] =>
implicit val eA = pe.eFst
implicit val eB = pe.eSnd
if (cachePairs) {
if (!tuplesCache.containsKey(p)) {
tuplesCache.put(p, (First(p), Second(p)))
Expand All @@ -74,8 +72,6 @@ trait Tuples extends Base { self: Scalan =>
}

implicit def zipPair[A, B](p: (Ref[A], Ref[B])): Ref[(A, B)] = {
implicit val ea = p._1.elem
implicit val eb = p._2.elem
Tup(p._1, p._2)
}

Expand Down
29 changes: 0 additions & 29 deletions sc/shared/src/main/scala/scalan/staged/ProgramGraphs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,40 +63,11 @@ trait ProgramGraphs extends AstGraphs { self: Scalan =>
sch
}

/** Mirror all the nodes of this graph applying transformer and performing rewriting.
* @param m mirror instance to be used for mirroring of nodes
* @param rw rewriter to be tried for each new created mirrored node
* @param t transformer of symbols, to be used for substitution of symbols in the new nodes.
* @return new graph which is not necessary clone of this graph, but should be semantically
* equivalent to this graph (provided all rw rules preserve equivalence).
* If rw is identity, then the resulting graph is alpha-equivalent to this graph
* as long as t is bijection.
*/
def transform(m: Mirror, rw: Rewriter, t: Transformer): ProgramGraph = {
val t0 = mapping match {
case Nullable(mapping) => t merge mapping
case _ => t
}
val t1 = m.mirrorSymbols(t0, rw, this, scheduleIds)
val newRoots = roots map { t1(_) }
new ProgramGraph(newRoots, Nullable(t1), filterNode)
}

/** Remove transformer component of the graph. */
def withoutContext = ProgramGraph(roots, Nullable.None, filterNode)

override def toString: String = {
val mappingStr = if (mapping.isEmpty) "None" else mapping.toString
val filterNodeStr = if (filterNode.isDefined) filterNode.toString else "None"
s"ProgramGraph($roots, $mappingStr, $filterNodeStr)"
}
}

object ProgramGraph {
def transform[A](s: Ref[A], rw: Rewriter = NoRewriting, t: MapTransformer = MapTransformer.empty()): Ref[A] = {
val g = ProgramGraph(List(s), Nullable.None, Nullable.None)
val g1 = g.transform(DefaultMirror, rw, t)
g1.roots(0).asInstanceOf[Ref[A]]
}
}
}
17 changes: 2 additions & 15 deletions sc/shared/src/main/scala/sigmastate/eval/GraphBuilding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
val builder: SigmaBuilder
import builder._


val okMeasureOperationTime: Boolean = false

this.isInlineThunksOnForce = true // this required for splitting of cost graph
Expand All @@ -60,16 +59,6 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
/** Whether to save calcF and costF graphs in the file given by ScriptNameProp environment variable */
var saveGraphsInFile: Boolean = false

// /** Pass configuration which is used by default in IRContext. */
// val calcPass = new DefaultPass("calcPass", Pass.defaultPassConfig.copy(constantPropagation = true))
//
// /** Pass configuration which is used during splitting cost function out of cost graph.
// * @see `RuntimeCosting.split2` */
// val costPass = new DefaultPass("costPass", Pass.defaultPassConfig.copy(constantPropagation = true))

/** To enable specific configuration uncomment one of the lines above and use it in the beginPass below. */
// beginPass(costPass)

/** Check the tuple type is valid.
* In v5.x this code is taken from CheckTupleType validation rule which is no longer
* part of consensus.
Expand Down Expand Up @@ -173,7 +162,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
case ThunkForce(Def(ThunkDef(root, sch))) if sch.isEmpty => root

// Rule: l.isValid op Thunk {... root} => (l op TrivialSigma(root)).isValid
case ApplyBinOpLazy(op, SigmaM.isValid(l), Def(ThunkDef(root, sch))) if root.elem == BooleanElement =>
case ApplyBinOpLazy(op, SigmaM.isValid(l), Def(ThunkDef(root, _))) if root.elem == BooleanElement =>
// don't need new Thunk because sigma logical ops always strict
val r = asRep[SigmaProp](sigmaDslBuilder.sigmaProp(asRep[Boolean](root)))
val res = if (op == And)
Expand Down Expand Up @@ -628,9 +617,7 @@ trait GraphBuilding extends SigmaLibrary { IR: IRContext =>
checkTupleType(IR)(eTuple)
eTuple match {
case pe: PairElem[a,b] =>
assert(fieldIndex == 1 || fieldIndex == 2, s"Invalid field index $fieldIndex of the pair ${tup}: $pe")
implicit val ea = pe.eFst
implicit val eb = pe.eSnd
assert(fieldIndex == 1 || fieldIndex == 2, s"Invalid field index $fieldIndex of the pair $tup: $pe")
val pair = asRep[(a,b)](tup)
val res = if (fieldIndex == 1) pair._1 else pair._2
res
Expand Down
Loading

0 comments on commit 112346c

Please sign in to comment.