From c27ce06c8b0f402b63f806ad3c1827b506ee8b00 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Fri, 20 Dec 2024 17:10:46 +0300 Subject: [PATCH] merge with #1043 and versioning code updates --- .../main/scala/sigma/serialization/TypeSerializer.scala | 8 ++++---- .../src/main/scala/sigma/validation/ValidationRules.scala | 2 +- .../org/ergoplatform/validation/ValidationRules.scala | 2 +- data/shared/src/main/scala/sigma/ast/methods.scala | 4 ++-- .../src/main/scala/sigmastate/eval/Extensions.scala | 2 +- .../scala/sigmastate/interpreter/CErgoTreeEvaluator.scala | 2 +- .../main/scala/sigmastate/interpreter/Interpreter.scala | 3 +-- .../src/test/scala/sigma/LanguageSpecificationV6.scala | 4 ++-- .../scala/sigmastate/utxo/BasicOpsSpecification.scala | 2 +- 9 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/shared/src/main/scala/sigma/serialization/TypeSerializer.scala b/core/shared/src/main/scala/sigma/serialization/TypeSerializer.scala index 56a3120cf..505507931 100644 --- a/core/shared/src/main/scala/sigma/serialization/TypeSerializer.scala +++ b/core/shared/src/main/scala/sigma/serialization/TypeSerializer.scala @@ -15,7 +15,7 @@ class TypeSerializer { def getEmbeddableType(code: Int): SType = { // todo : add unsigned bit int to embeddable id to type - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { CheckPrimitiveTypeCodeV6(code.toByte) } else { CheckPrimitiveTypeCode(code.toByte) @@ -205,7 +205,7 @@ class TypeSerializer { case SHeader.typeCode => SHeader case SPreHeader.typeCode => SPreHeader case SGlobal.typeCode => SGlobal - case SFunc.FuncTypeCode if VersionContext.current.isV3OrLaterErgoTreeVersion => + case SFunc.FuncTypeCode if VersionContext.current.isV6Activated => val tdLength = r.getUByte() val tDom = (1 to tdLength).map { _ => @@ -222,7 +222,7 @@ class TypeSerializer { case _ => // the #1008 check replaced with one with identical behavior but different opcode (1018), to activate // ReplacedRule(1008 -> 1018) during 6.0 activation - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { CheckTypeCodeV6(c.toByte) } else { CheckTypeCode(c.toByte) @@ -252,7 +252,7 @@ object TypeSerializer extends TypeSerializer { /** The list of embeddable types, i.e. types that can be combined with type constructor for optimized encoding. * For each embeddable type `T`, and type constructor `C`, the type `C[T]` can be represented by single byte. */ def embeddableIdToType = { - if (VersionContext.current.isV3OrLaterErgoTreeVersion) { + if (VersionContext.current.isV6Activated) { embeddableV6 } else { embeddableV5 diff --git a/core/shared/src/main/scala/sigma/validation/ValidationRules.scala b/core/shared/src/main/scala/sigma/validation/ValidationRules.scala index 6321ae6ba..3cae0a3f2 100644 --- a/core/shared/src/main/scala/sigma/validation/ValidationRules.scala +++ b/core/shared/src/main/scala/sigma/validation/ValidationRules.scala @@ -208,7 +208,7 @@ object ValidationRules { ) private def ruleSpecs: Seq[ValidationRule] = { - if(VersionContext.current.isV6SoftForkActivated) { + if(VersionContext.current.isV6Activated) { ruleSpecsV6 } else { ruleSpecsV5 diff --git a/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala b/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala index 4c75de662..4c8e4e58f 100644 --- a/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala +++ b/data/shared/src/main/scala/org/ergoplatform/validation/ValidationRules.scala @@ -183,7 +183,7 @@ object ValidationRules { } def ruleSpecs: Seq[ValidationRule] = { - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { ruleSpecsV6 } else { ruleSpecsV5 diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index 4bcc73e1f..74c6d4277 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -91,7 +91,7 @@ sealed trait MethodsContainer { * @see getMethodById */ def methodById(methodId: Byte): SMethod = { - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { ValidationRules.CheckAndGetMethodV6(this, methodId) } else { ValidationRules.CheckAndGetMethod(this, methodId) @@ -1813,7 +1813,7 @@ case object SAvlTreeMethods extends MonoTypeMethods { lazy val v6Methods = v5Methods ++ Seq(insertOrUpdateMethod) protected override def getMethods(): Seq[SMethod] = { - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV3OrLaterErgoTreeVersion) { v6Methods } else { v5Methods diff --git a/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala b/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala index 98f044af9..2df6fd040 100644 --- a/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala +++ b/interpreter/shared/src/main/scala/sigmastate/eval/Extensions.scala @@ -91,7 +91,7 @@ object Extensions { val bv = CAvlTreeVerifier(tree, proof) entries.forall { case (key, value) => val insertRes = bv.performOneOperation(Insert(ADKey @@ key.toArray, ADValue @@ value.toArray)) - if (insertRes.isFailure && !VersionContext.current.isV6SoftForkActivated) { + if (insertRes.isFailure && !VersionContext.current.isV6Activated) { syntax.error(s"Incorrect insert for $tree (key: $key, value: $value, digest: ${tree.digest}): ${insertRes.failed.get}}") } insertRes.isSuccess diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/CErgoTreeEvaluator.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/CErgoTreeEvaluator.scala index d31e93fb0..7a77fe915 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/CErgoTreeEvaluator.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/CErgoTreeEvaluator.scala @@ -146,7 +146,7 @@ class CErgoTreeEvaluator( val insertRes = bv.performInsert(key.toArray, value.toArray) // TODO v6.0: throwing exception is not consistent with update semantics // however it preserves v4.0 semantics (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/908) - if (insertRes.isFailure && !VersionContext.current.isV6SoftForkActivated) { + if (insertRes.isFailure && !VersionContext.current.isV3OrLaterErgoTreeVersion) { syntax.error(s"Incorrect insert for $tree (key: $key, value: $value, digest: ${tree.digest}): ${insertRes.failed.get}}") } res = insertRes.isSuccess diff --git a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala index fb56f429e..f2b9c82d5 100644 --- a/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala +++ b/interpreter/shared/src/main/scala/sigmastate/interpreter/Interpreter.scala @@ -239,8 +239,7 @@ trait Interpreter { /** Performs reduction of proposition which contains deserialization operations. */ private def reductionWithDeserialize(ergoTree: ErgoTree, prop: SigmaPropValue, - context: CTX, - env: ScriptEnv): ReductionResult = { + context: CTX): ReductionResult = { implicit val vs: SigmaValidationSettings = context.validationSettings val res = VersionContext.withVersions(context.activatedScriptVersion, ergoTree.version) { val deserializeSubstitutionCost = java7.compat.Math.multiplyExact(ergoTree.bytes.length, CostPerTreeByte) diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala index e5b0635b5..dda2c34bb 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala @@ -3040,7 +3040,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => val tree = createTree(preInsertDigest, insertAllowed = true) val invalidKvs = Colls.fromItems((key -> value), (key -> value)) val input = (tree, (invalidKvs, insertProof)) - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { insert.verifyCase(input, new Expected(ExpectedResult(Success(None), Some(2103)))) } else { val res = insert.checkEquality(input) @@ -3053,7 +3053,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => val tree = createTree(preInsertDigest, insertAllowed = true) val invalidProof = insertProof.map(x => (-x).toByte) // any other different from proof val input = (tree, (kvs, invalidProof)) - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { insert.verifyCase(input, new Expected(ExpectedResult(Success(None), Some(2103)))) } else { val res = insert.checkEquality(input) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala index ca46ab4e8..bcc47825c 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala @@ -3242,7 +3242,7 @@ class BasicOpsSpecification extends CompilerTestingCommons true ) - if (VersionContext.current.isV6SoftForkActivated) { + if (VersionContext.current.isV6Activated) { deserTest() } else { an[ValidationException] should be thrownBy deserTest()