-
Notifications
You must be signed in to change notification settings - Fork 41
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
Prohibition for using 6.0 types in register and context extension vars #1047
base: v6.0.0
Are you sure you want to change the base?
Changes from 6 commits
08c7f98
6c87a6b
62d61e8
9270bd3
a61c9d4
53c78a4
2247fea
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 | ||
import sigma.ast.{DeserializeContext, ErgoTree, MethodsContainer, SMethod} | ||
import sigma.ast.{Constant, DeserializeContext, ErgoTree, EvaluatedCollection, EvaluatedValue, GroupGenerator, MethodsContainer, SHeader, SMethod, SType, SUnsignedBigInt} | ||
import sigma.ast.TypeCodes.LastConstantCode | ||
import sigma.serialization.{InvalidOpCode, SerializerException} | ||
import sigma.util.Extensions.toUByte | ||
|
@@ -155,6 +155,39 @@ object ValidationRules { | |
override protected lazy val settings: SigmaValidationSettings = currentSettings | ||
} | ||
|
||
// todo: recheck id after merge | ||
object CheckV6Type extends ValidationRule(1016, | ||
"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( | ||
new SerializerException(s"V6 type used in register or context var extension: $tpe"), | ||
Array[Any](tpe)) | ||
} | ||
} | ||
v match { | ||
case c: Constant[_] => v6TypeCheck(c.tpe) | ||
case c: EvaluatedCollection[_, _] => v6TypeCheck(c.elementType) | ||
case GroupGenerator => | ||
} | ||
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? 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 | ||
} | ||
} | ||
|
||
val ruleSpecs: Seq[ValidationRule] = Seq( | ||
CheckDeserializedScriptType, | ||
CheckDeserializedScriptIsSigmaProp, | ||
|
@@ -171,7 +204,8 @@ object ValidationRules { | |
CheckHeaderSizeBit, | ||
CheckCostFuncOperation, | ||
CheckPositionLimit, | ||
CheckLoopLevelInCostFunction | ||
CheckLoopLevelInCostFunction, | ||
CheckV6Type | ||
) | ||
|
||
/** Validation settings that correspond to the current version of the ErgoScript implementation. | ||
|
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.
It seems it is possible to serialize/parse Tuple with v6 type
doesn't throw exception
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.
@SethDusek fixed, the reason was c.elementType being SAny for Tuple. Made test for UBI as second tuple element, and collection as well