-
Notifications
You must be signed in to change notification settings - Fork 41
Prohibition for using 6.0 types in register and context extension vars #1047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
08c7f98
6c87a6b
62d61e8
9270bd3
a61c9d4
53c78a4
2247fea
eb96517
78922a3
cfb54c8
72d041b
55c0582
155225e
845c3e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| package org.ergoplatform.validation | ||
|
|
||
| import sigma.{SigmaException, VersionContext} | ||
| import sigma.ast.{DeserializeContext, ErgoTree, MethodsContainer, SMethod} | ||
| import sigma.ast._ | ||
| import sigma.ast.TypeCodes.LastConstantCode | ||
| import sigma.serialization.{InvalidOpCode, SerializerException} | ||
| import sigma.util.Extensions.toUByte | ||
|
|
@@ -13,6 +13,8 @@ import sigma.exceptions.InterpreterException | |
| import sigma.serialization.ValueCodes.OpCode | ||
| import sigma.serialization.ValueSerializer | ||
|
|
||
| import scala.annotation.tailrec | ||
|
|
||
| /** All validation rules which are used to check soft-forkable conditions. Each validation | ||
| * rule throws a [[org.ergoplatform.validation.ValidationException]]. Each | ||
| * ValidationException can be caught and handled with respect to | ||
|
|
@@ -162,6 +164,48 @@ object ValidationRules { | |
| override protected def settings: SigmaValidationSettings = currentSettings | ||
| } | ||
|
|
||
| object CheckV6Type extends ValidationRule(1019, | ||
| "Check the type has the declared method.") { | ||
| override protected lazy val settings: SigmaValidationSettings = currentSettings | ||
|
|
||
| final def apply[T](v: EvaluatedValue[_]): Unit = { | ||
| checkRule() | ||
|
|
||
| def v6TypeCheck(tpe: SType) = { | ||
| if (tpe.isOption || tpe.typeCode == SHeader.typeCode || tpe.typeCode == SUnsignedBigInt.typeCode) { | ||
| throwValidationException( | ||
| SerializerException(s"V6 type used in register or context var extension: $tpe"), | ||
| Array[Any](tpe)) | ||
| } | ||
| } | ||
|
|
||
| def step(s: SType): Unit = { | ||
| s match { | ||
| case st: STuple => st.items.foreach(step) | ||
| case sc: SCollection[_] => step(sc.elemType) // this case should be after STuple as STuple deriving from SCollection | ||
| case s: SType => v6TypeCheck(s) | ||
| } | ||
| } | ||
|
|
||
| v match { | ||
| case c: Constant[_] => step(c.tpe) | ||
| case t: Tuple => t.items.foreach(i => step(i.tpe)) | ||
| case c: EvaluatedCollection[_, _] => step(c.elementType) | ||
| case GroupGenerator => | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the motivation to add and check this rule?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that deserialization of values in registers and context extension is not versioned, so newly supported serializable types (Header, Option[], UnsignedBigInt) can't be put there (but serialized as Coll[Byte] value can be put there to be used with Global.deserialize ) |
||
| } | ||
|
|
||
| override def isSoftFork(vs: SigmaValidationSettings, | ||
| ruleId: Short, | ||
| status: RuleStatus, | ||
| args: Seq[Any]): Boolean = (status, args) match { | ||
| case (ChangedRule(newValue), Seq(objType: MethodsContainer, methodId: Byte)) => | ||
| val key = Array(objType.ownerType.typeId, methodId) | ||
| newValue.grouped(2).exists(java.util.Arrays.equals(_, key)) | ||
| case _ => false | ||
| } | ||
| } | ||
|
|
||
| private val ruleSpecsV5: Seq[ValidationRule] = Seq( | ||
| CheckDeserializedScriptType, | ||
| CheckDeserializedScriptIsSigmaProp, | ||
|
|
@@ -178,7 +222,8 @@ object ValidationRules { | |
| CheckHeaderSizeBit, | ||
| CheckCostFuncOperation, | ||
| CheckPositionLimit, | ||
| CheckLoopLevelInCostFunction | ||
| CheckLoopLevelInCostFunction, | ||
| CheckV6Type | ||
| ) | ||
|
|
||
| // v6 validation rules below | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to be sufficient for Coll type that's nested in another type like Tuple or Coll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh right, fixed in 845c3e0