Skip to content

Commit

Permalink
merge with #1043 and versioning code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Dec 20, 2024
1 parent 210273f commit c27ce06
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 { _ =>
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ object ValidationRules {
)

private def ruleSpecs: Seq[ValidationRule] = {
if(VersionContext.current.isV6SoftForkActivated) {
if(VersionContext.current.isV6Activated) {
ruleSpecsV6
} else {
ruleSpecsV5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ object ValidationRules {
}

def ruleSpecs: Seq[ValidationRule] = {
if (VersionContext.current.isV6SoftForkActivated) {
if (VersionContext.current.isV6Activated) {
ruleSpecsV6
} else {
ruleSpecsV5
Expand Down
4 changes: 2 additions & 2 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c27ce06

Please sign in to comment.