Skip to content
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

6.0.0-RC1 candidate for devnets #1027

Closed
wants to merge 199 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
199 commits
Select commit Hold shift + click to select a range
0843902
DecodeNBitsMethod definition
kushti Apr 2, 2024
49dce78
ToNBits def
kushti Apr 2, 2024
1c1049e
merging w. 6.0.0
kushti Apr 3, 2024
37bb86c
toNBits added to SigmaDsl
kushti Apr 4, 2024
6f8981f
NBitsUtils
kushti Apr 4, 2024
d0f1b7d
unused import removed
kushti Apr 5, 2024
fcc7f0f
merging latest 5.0.14 commits
kushti Apr 6, 2024
6e47167
nbits impl
kushti Apr 9, 2024
9e4e098
failing roundtrip test for deserialization roundtrip
kushti Apr 10, 2024
1016323
importing method def from i675
kushti Apr 10, 2024
93748f1
removing decode nbits
kushti Apr 10, 2024
a3cb64d
versioned nbits serialization roundtrip test
kushti Apr 12, 2024
8941a8e
nbits evaluation test
kushti Apr 15, 2024
6abf794
Autolykos2PowValidation
kushti Apr 16, 2024
1d9f80a
powHit impl #1
kushti Apr 16, 2024
a67c6d6
powHit impl #1
kushti Apr 17, 2024
e1dcd4b
powHit impl #3 (Evaluate powHit test successfully executes)
kushti Apr 22, 2024
6d6404e
data for evaluate powhit test
kushti Apr 22, 2024
b4e2cc4
serialization roundtrip test
kushti Apr 23, 2024
9692241
bigint constructor
kushti Apr 23, 2024
af1b384
upcast test (to be moved into another branch)
kushti Apr 23, 2024
8f46b1b
powHit evaluation test
kushti Apr 23, 2024
92e2d77
close #974 : Header.bytes method implementation
kushti May 6, 2024
98e2756
moving failing test from #612 to here
kushti May 6, 2024
2c6bd15
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 6, 2024
624558f
executeFromVar tests are passing
kushti May 7, 2024
690a3e2
Global.deserialize method
kushti May 7, 2024
c526263
merging w. 6.0.0
kushti May 7, 2024
023ad09
deserialize int - test passing
kushti May 8, 2024
7648182
unused code removal
kushti May 9, 2024
79b4d11
executeFromVar is passing for SigmaProp
kushti May 9, 2024
a470406
more executeFromVar and deserialize tests, all passing
kushti May 9, 2024
c1947d4
negative test for DeserializeContext in executeFromVar, new stubs for…
kushti May 9, 2024
cec0add
long roundtrip
kushti May 9, 2024
838a617
box rouundtrip test
kushti May 10, 2024
fd589a8
bigInt test
kushti May 10, 2024
4404741
Short test
kushti May 10, 2024
7d69ebc
group elem impl & test
kushti May 10, 2024
48f112a
sigmaprop test & impl
kushti May 12, 2024
63f8ccc
non evaluated sigmaprop test
kushti May 12, 2024
516f05d
avltree test & impl
kushti May 12, 2024
5f3a1ad
removing executeFromVar from i443 and some code cleaning
kushti May 13, 2024
50f5b87
merging w. i974
kushti May 13, 2024
126bc05
header impl & test
kushti May 13, 2024
5bf4704
renaming to deserializeRaw, LangSpec.md update
kushti May 13, 2024
35c9375
DataSerializer WIP #1
kushti May 16, 2024
48f11e7
coll allowed
kushti May 16, 2024
7fd601b
.propBytes test
kushti May 16, 2024
e1873fe
merging w. i659, header option test
kushti May 17, 2024
a2ffc2d
all types rely on DataSerializer
kushti May 17, 2024
ae271cd
deserializeRaw -> deserializeTo
kushti May 17, 2024
779a9eb
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 17, 2024
60a111b
unused import fix
kushti May 18, 2024
d3e4040
MethodCall deserialization roundtrip for Global.deserializeTo[]
kushti May 20, 2024
3d47f2a
initial raw, buggy & unversioned unsigned bit int impl
kushti May 24, 2024
b13cef6
failing schnorr sig check w. unsigned
kushti May 24, 2024
c8d75cd
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti May 26, 2024
c9d0889
first pow check test
kushti May 26, 2024
299fdd5
merging w. nbits encoding PR
kushti May 26, 2024
a90e7be
pow check test passing
kushti May 26, 2024
37b23cd
hit <= diff
kushti May 29, 2024
69e8d9e
merging w. 6.0.0
kushti May 29, 2024
7ce2446
merging w. 6.0.0
kushti Jun 3, 2024
744d8a5
conversion test stub
kushti Jun 3, 2024
a30e068
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 3, 2024
2acc6db
more todos
kushti Jun 4, 2024
4735aed
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jun 4, 2024
ac0ee15
merging w. 6.0.0
kushti Jun 5, 2024
15f4f67
removing modq methods
kushti Jun 7, 2024
303f969
expUnsigned impl (test still failing)
kushti Jun 8, 2024
982f32f
schnorr sig example passed
kushti Jun 9, 2024
eb47d17
eq test, DataValueComparer
kushti Jun 9, 2024
ea468c9
initial stubs along first todos for bulletproofs contracts
kushti Jun 11, 2024
e9b3253
original code
kushti Jun 12, 2024
e71d7c2
modInverse
kushti Jun 13, 2024
e989665
plusMod
kushti Jun 13, 2024
d776db3
multiplyMod
kushti Jun 13, 2024
72db85b
toUnsigned & toUnsignedMod
kushti Jun 14, 2024
fc6d856
mod, toSigned, subtractMod
kushti Jun 17, 2024
fb3e52e
String fix & test
kushti Jul 17, 2024
ec215df
Array fix & test
kushti Jul 17, 2024
d257b5a
BigInteger and ErgoBox fix and tests
kushti Jul 17, 2024
1644380
AvlTreeData fix & test
kushti Jul 18, 2024
21d4bcf
merging w. 6.0.0, method desc
kushti Jul 29, 2024
27e2f52
powHit costing
kushti Jul 29, 2024
fdb4f6b
test in LSV6
kushti Jul 29, 2024
a8462fb
merging with Header.checkPoW
kushti Jul 29, 2024
a29a684
checks for k and N
kushti Jul 29, 2024
7016b2f
PowHitCostKind
kushti Jul 30, 2024
913cf28
compilation fix
kushti Jul 30, 2024
2352bac
Merge branch 'i958-2' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jul 31, 2024
5efda39
removing comma
kushti Jul 31, 2024
aaa2aa9
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jul 31, 2024
a20c04f
moving to Global, finalizing costing
kushti Jul 31, 2024
2c8df31
updating collectMethods
kushti Jul 31, 2024
6981c34
fixing JS test
kushti Jul 31, 2024
3963ece
Merge branch 'i958-2' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 2, 2024
2bf10bb
merging w. 6.0.0
kushti Aug 5, 2024
fb3c671
merging with i958-2
kushti Aug 7, 2024
0d3f4be
fixing and improving test, powHit version, tree version check
kushti Aug 7, 2024
f347dfd
fixed test in TestingSpecInterpreter
kushti Aug 7, 2024
b4aa573
mmerging w. 6.0.0
kushti Aug 14, 2024
d8cc09d
deserializeCostKind
kushti Aug 14, 2024
57e39be
Header.bytes removed
kushti Aug 18, 2024
9e1498d
deserializeToBytes removed
kushti Aug 18, 2024
cd2eaee
LSV6 test, fixed deserializeTo description, polishing
kushti Aug 19, 2024
6bb7fe7
merging w. 6.0.0
kushti Aug 20, 2024
bcfb24d
removing unused CSigmaDslBuilder.validationSettings
kushti Aug 25, 2024
5f6a0d0
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 26, 2024
dfedb4a
Merge branch 'i958-2' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 30, 2024
9a10d17
merging w. i1006 (numeric methods)
kushti Sep 9, 2024
89d4477
Merge branch 'i1006' of github.com:ScorexFoundation/sigmastate-interp…
kushti Sep 12, 2024
343a385
Merge branch 'i1006' of github.com:ScorexFoundation/sigmastate-interp…
kushti Sep 17, 2024
1c2b99d
more polishing in UnsignedBigInt impl
kushti Sep 17, 2024
cb51ba8
removing access to type before 6.0, more tests
kushti Sep 17, 2024
2bd556e
merging w. 6.0.0, fixed tests
kushti Sep 23, 2024
dfc448f
LSV6 test, roundtrip test, deserializeTo predefined function
kushti Sep 23, 2024
0ee89b1
improved scaladoc, removing unused new code in SigmaTyper
kushti Sep 23, 2024
67bda6b
2.11 compilation fixes
kushti Sep 24, 2024
a072123
improving tests
kushti Sep 24, 2024
cb9e9eb
fixing JS tests
kushti Sep 24, 2024
a1a66ad
trees in LSV6
kushti Sep 26, 2024
ed310bf
merging w. 6.0.0
kushti Sep 26, 2024
072d811
fix ErgoTreeSpecification
kushti Sep 27, 2024
19a3e7f
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Sep 30, 2024
3901ba2
merging w. 6.0.0, Header support
kushti Sep 30, 2024
d0eef4c
merging w. 6.0.0
kushti Sep 30, 2024
6128fbd
fixing ErgoTreeSpec
kushti Oct 1, 2024
ee25e40
merging w. 6.0.0
kushti Oct 1, 2024
a49b2de
merging w. 6.0.0
kushti Oct 2, 2024
3c06856
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 2, 2024
40fe947
versioned header check
kushti Oct 2, 2024
19c752d
fixing most of tests
kushti Oct 3, 2024
f77be78
fixing JS tests
kushti Oct 3, 2024
6c1ac1e
fix for AVLtreedata lift in JS
kushti Oct 3, 2024
4247cf0
post-merging fix of MethodCallSerializerSpecification
kushti Oct 3, 2024
f31e483
refined n & k values, polishing
kushti Oct 3, 2024
e71abfa
tree versioning artefact removed from test
kushti Oct 3, 2024
6b77c25
JS reflection for powHit_eval added
kushti Oct 3, 2024
ce11553
fixing JS reflection
kushti Oct 4, 2024
e4a611d
fixing MethodCallSerializerSpecification
kushti Oct 4, 2024
c5c37ff
fixing JS reflection
kushti Oct 4, 2024
bdaa884
fixing comp issue
kushti Oct 4, 2024
2a22f6d
fixing reflection data
kushti Oct 6, 2024
08b02c7
initial some test passing
kushti Oct 7, 2024
2ba5a4f
PropertyCallSerializer fix, explicitTypeArgs fix, more tests
kushti Oct 8, 2024
904e209
merging w. 6.0.0
kushti Oct 8, 2024
0aa88be
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 8, 2024
e87ad02
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 8, 2024
7b48ddd
merging w. 6.0.0
kushti Oct 8, 2024
e532630
fixing ErgoTreeSpecification
kushti Oct 8, 2024
7452f5f
JS reflection
kushti Oct 9, 2024
ba4b3b3
Merge branch 'i905' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Oct 9, 2024
14db2e2
merging i978
kushti Oct 9, 2024
ef0e266
Merge branch 'i909' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Oct 9, 2024
8d0d95f
merging i06
kushti Oct 9, 2024
611780f
merging i554
kushti Oct 9, 2024
5b3721e
merging 6.0-deserialize
kushti Oct 9, 2024
ae0a025
merging i958
kushti Oct 9, 2024
4b2b443
merging w. i675-2
kushti Oct 9, 2024
ac11237
CheckAndGetMethod/CheckAndGetMethodV6, versioned methodById
kushti Oct 15, 2024
09ec5f1
ignoring bulletproof test, impoving comments
kushti Oct 18, 2024
06fff23
merging w. 6.0.0
kushti Oct 24, 2024
e9e59e0
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 29, 2024
901c868
1007 & 1008 replacement & versioning
kushti Oct 29, 2024
a160997
UnsignedBigInt support in DataSerializerSpecification
kushti Oct 31, 2024
fdf712e
ErgoTreeSpecification update
kushti Oct 31, 2024
dde7f6e
fixing DataJsonEncoderSpecification
kushti Oct 31, 2024
a18967c
SigmaTyperTest fix
kushti Oct 31, 2024
2d8af9d
adding UnsignedBigInt to JS reflection , pt1
kushti Nov 1, 2024
933b2cc
improving UnsignedBigInt support in JS
kushti Nov 1, 2024
3a5c6d6
JS tests fixed
kushti Nov 4, 2024
b1d2b17
toUnsigned test in LSV6
kushti Nov 4, 2024
f84bce5
toUnsignedMod test in LSV6, more tests in BOS
kushti Nov 4, 2024
1496770
tests for .toBytes, UnsignedBigInt support added to to new Numeric me…
kushti Nov 5, 2024
ac4bbbc
unsigned encoding, .toBytes & .toBits tests passing
kushti Nov 5, 2024
a87bfb3
bitwiseInverse
kushti Nov 5, 2024
77be8a6
more .toBytes and .toBits tests
kushti Nov 11, 2024
626edc8
bitwise or/and/xor and tests
kushti Nov 11, 2024
aa246c3
shiftLeft/shiftRight and tests
kushti Nov 11, 2024
7fdcdbd
more tests for shiftLeft/shiftRight
kushti Nov 11, 2024
9566177
LSV6 tests for UnsignedBigInt
kushti Nov 13, 2024
503f0c7
bitwiseInverse fix, tests fixes
kushti Nov 13, 2024
6a15e5f
expUnsigned test
kushti Nov 13, 2024
b0e41a8
mod ops tests
kushti Nov 14, 2024
8da5f89
_eval mathods removed
kushti Nov 14, 2024
11bc3d0
More descriptions, some code cleaning
kushti Nov 14, 2024
8c5172b
costing
kushti Nov 14, 2024
dd33642
arith test
kushti Nov 14, 2024
8109a28
embeddable type list / serializers versioning, code cleaning , toUnsi…
kushti Nov 14, 2024
b3a10a5
1007 rule update
kushti Nov 14, 2024
ae0421a
fixing JS test
kushti Nov 14, 2024
aa3fbbd
JS test comment
kushti Nov 14, 2024
cedcfbe
fixing tupleGen
kushti Nov 15, 2024
491f878
versioned rulesSpecs
kushti Nov 15, 2024
a66ab55
compilation err fix
kushti Nov 15, 2024
a5c0937
merging unsigned big int
kushti Nov 17, 2024
d4f2c01
merging activation details update
kushti Nov 17, 2024
fe3b907
fixing MethodCallSerializerSpecification
kushti Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import sigma.VersionContext
import sigma.ast.SCollectionType.{CollectionTypeCode, NestedCollectionTypeCode}
import sigma.ast._
import sigma.util.safeNewArray
import sigma.validation.ValidationRules.{CheckPrimitiveTypeCode, CheckTypeCode}
import sigma.validation.ValidationRules.{CheckPrimitiveTypeCode, CheckPrimitiveTypeCodeV6, CheckTypeCode, CheckTypeCodeV6}

import java.nio.charset.StandardCharsets

Expand All @@ -14,7 +14,12 @@ class TypeSerializer {
import TypeSerializer._

def getEmbeddableType(code: Int): SType = {
CheckPrimitiveTypeCode(code.toByte)
// todo : add unsigned bit int to embeddable id to type
if (VersionContext.current.isV6SoftForkActivated) {
CheckPrimitiveTypeCodeV6(code.toByte)
} else {
CheckPrimitiveTypeCode(code.toByte)
}
embeddableIdToType(code)
}

Expand Down Expand Up @@ -215,9 +220,13 @@ class TypeSerializer {
}
SFunc(tDom, tRange, tpeParams)
case _ =>
// todo: 6.0: replace 1008 check with identical behavior but other opcode, to activate
// ReplacedRule(1008 -> new opcode) during 6.0 activation
CheckTypeCode(c.toByte)
// 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) {
CheckTypeCodeV6(c.toByte)
} else {
CheckTypeCode(c.toByte)
}
NoType
}
}
Expand Down
43 changes: 34 additions & 9 deletions core/shared/src/main/scala/sigma/validation/ValidationRules.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sigma.validation

import sigma.SigmaException
import sigma.{SigmaException, VersionContext}
import sigma.ast.{SGlobal, SOption, TypeCodes}
import sigma.serialization.{ReaderPositionLimitExceeded, SerializerException}
import sigma.util.Extensions.toUByte
Expand Down Expand Up @@ -77,7 +77,7 @@ object ValidationRules {
/** The id of the first validation rule. Can be used as the beginning of the rules id range. */
val FirstRuleId = 1000.toShort

object CheckPrimitiveTypeCode extends ValidationRule(1007,
class CheckPrimitiveTypeCodeTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the primitive type code is supported or is added via soft-fork")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = coreSettings
Expand All @@ -93,10 +93,14 @@ object ValidationRules {
}
}

object CheckTypeCode extends ValidationRule(1008,
object CheckPrimitiveTypeCode extends CheckPrimitiveTypeCodeTemplate(1007)

object CheckPrimitiveTypeCodeV6 extends CheckPrimitiveTypeCodeTemplate(1017)

class CheckTypeCodeTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the non-primitive type code is supported or is added via soft-fork")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = coreSettings
override protected def settings: SigmaValidationSettings = coreSettings

final def apply[T](typeCode: Byte): Unit = {
checkRule()
Expand All @@ -109,10 +113,14 @@ object ValidationRules {
}
}

object CheckTypeCode extends CheckTypeCodeTemplate(1008)

object CheckTypeCodeV6 extends CheckTypeCodeTemplate(1018)

object CheckSerializableTypeCode extends ValidationRule(1009,
"Check the data values of the type (given by type code) can be serialized")
with SoftForkWhenReplaced {
override protected lazy val settings: SigmaValidationSettings = coreSettings
override protected def settings: SigmaValidationSettings = coreSettings

/** Creates an exception which is used as a cause when throwing a ValidationException. */
def throwValidationException(typeCode: Byte): Nothing = {
Expand Down Expand Up @@ -141,7 +149,7 @@ object ValidationRules {
object CheckTypeWithMethods extends ValidationRule(1010,
"Check the type (given by type code) supports methods")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = coreSettings
override protected def settings: SigmaValidationSettings = coreSettings

final def apply[T](typeCode: Byte, cond: Boolean): Unit = {
checkRule()
Expand All @@ -160,7 +168,7 @@ object ValidationRules {
*/
object CheckPositionLimit extends ValidationRule(1014,
"Check that the Reader has not exceeded the position limit.") with SoftForkWhenReplaced {
override protected lazy val settings: SigmaValidationSettings = coreSettings
override protected def settings: SigmaValidationSettings = coreSettings

/** Wraps the given cause into [[ValidationException]] and throws it. */
def throwValidationException(cause: ReaderPositionLimitExceeded): Nothing = {
Expand All @@ -183,21 +191,38 @@ object ValidationRules {
}
}

private val ruleSpecs: Seq[ValidationRule] = Seq(
private val ruleSpecsV5: Seq[ValidationRule] = Seq(
CheckPrimitiveTypeCode,
CheckTypeCode,
CheckSerializableTypeCode,
CheckTypeWithMethods,
CheckPositionLimit
)

private val ruleSpecsV6: Seq[ValidationRule] = Seq(
CheckPrimitiveTypeCodeV6,
CheckTypeCodeV6,
CheckSerializableTypeCode,
CheckTypeWithMethods,
CheckPositionLimit
)

private def ruleSpecs: Seq[ValidationRule] = {
if(VersionContext.current.isV6SoftForkActivated) {
ruleSpecsV6
} else {
ruleSpecsV5
}
}

/** Validation settings that correspond to the current version of the ErgoScript implementation.
* Different version of the code will have a different set of rules here.
* This variable is globally available and can be use wherever checking of the rules is necessary.
* This is immutable data structure, it can be augmented with RuleStates from block extension
* sections of the blockchain, but that augmentation is only available in stateful context.
*/
val coreSettings: SigmaValidationSettings = new MapSigmaValidationSettings({
// todo: versioned cache here for efficiency
def coreSettings: SigmaValidationSettings = new MapSigmaValidationSettings({
val map = ruleSpecs.map(r => r.id -> (r, EnabledRule)).toMap
assert(map.size == ruleSpecs.size, s"Duplicate ruleIds ${ruleSpecs.groupBy(_.id).filter(g => g._2.length > 1)}")
map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.ergoplatform.validation

import sigma.SigmaException
import sigma.{SigmaException, VersionContext}
import sigma.ast.{DeserializeContext, ErgoTree, MethodsContainer, SMethod}
import sigma.ast.TypeCodes.LastConstantCode
import sigma.serialization.{InvalidOpCode, SerializerException}
Expand All @@ -23,7 +23,7 @@ object ValidationRules {

object CheckDeserializedScriptType extends ValidationRule(FirstRuleId,
"Deserialized script should have expected type") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

final def apply[T](d: DeserializeContext[_], script: SValue): Unit = {
checkRule()
Expand All @@ -38,7 +38,7 @@ object ValidationRules {

object CheckDeserializedScriptIsSigmaProp extends ValidationRule(1001,
"Deserialized script should have SigmaProp type") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

/** @param root candidate node before it is added as a root of ErgoTree */
final def apply[T](root: SValue): Unit = {
Expand All @@ -54,7 +54,7 @@ object ValidationRules {
object CheckValidOpCode extends ValidationRule(1002,
"Check the opcode is supported by registered serializer or is added via soft-fork")
with SoftForkWhenCodeAdded {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

final def apply[T](ser: ValueSerializer[_], opCode: OpCode): Unit = {
checkRule()
Expand All @@ -69,26 +69,26 @@ object ValidationRules {
/** Not used since v5.0.1. */
object CheckIsSupportedIndexExpression extends ValidationRule(1003,
"Check the index expression for accessing collection element is supported.") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings
}

/** Not used since v5.0.3 */
object CheckCostFunc extends ValidationRule(1004,
"Cost function should contain only operations from specified list.") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings
}

object CheckCalcFunc extends ValidationRule(1005,
"If SigmaProp.isProven method calls exists in the given function,\n then it is the last operation") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings
}

/** This rule is not use in v5.x, keep the commented code below as a precise
* documentation of its semantics.
*/
object CheckTupleType extends ValidationRule(1006,
"Supported tuple type.") with SoftForkWhenReplaced {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

// final def apply[Ctx <: IRContext, T](ctx: Ctx)(e: ctx.Elem[_]): Unit = {
// checkRule()
Expand All @@ -102,9 +102,9 @@ object ValidationRules {
// }
}

object CheckAndGetMethod extends ValidationRule(1011,
class CheckAndGetMethodTemplate(ruleId: Short) extends ValidationRule(ruleId,
"Check the type has the declared method.") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

final def apply[T](objType: MethodsContainer, methodId: Byte): SMethod = {
checkRule()
Expand All @@ -128,9 +128,12 @@ object ValidationRules {
}
}

object CheckAndGetMethod extends CheckAndGetMethodTemplate(1011)
object CheckAndGetMethodV6 extends CheckAndGetMethodTemplate(1016)

object CheckHeaderSizeBit extends ValidationRule(1012,
"For version greater then 0, size bit should be set.") with SoftForkWhenReplaced {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings

final def apply(header: HeaderType): Unit = {
checkRule()
Expand All @@ -146,16 +149,16 @@ object ValidationRules {
/** Not used since v5.0.3 */
object CheckCostFuncOperation extends ValidationRule(1013,
"Check the opcode is allowed in cost function") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings
}

/** Not used since v5.0.1 */
object CheckLoopLevelInCostFunction extends ValidationRule(1015,
"Check that loop level is not exceeded.") {
override protected lazy val settings: SigmaValidationSettings = currentSettings
override protected def settings: SigmaValidationSettings = currentSettings
}

val ruleSpecs: Seq[ValidationRule] = Seq(
private val ruleSpecsV5: Seq[ValidationRule] = Seq(
CheckDeserializedScriptType,
CheckDeserializedScriptIsSigmaProp,
CheckValidOpCode,
Expand All @@ -174,13 +177,26 @@ object ValidationRules {
CheckLoopLevelInCostFunction
)

// v6 validation rules below
private val ruleSpecsV6: Seq[ValidationRule] = {
ruleSpecsV5.filter(_.id != CheckAndGetMethod.id) ++ Seq(CheckAndGetMethodV6)
}

def ruleSpecs: Seq[ValidationRule] = {
if (VersionContext.current.isV6SoftForkActivated) {
ruleSpecsV6
} else {
ruleSpecsV5
}
}

/** Validation settings that correspond to the current version of the ErgoScript implementation.
* Different version of the code will have a different set of rules here.
* This variable is globally available and can be use wherever checking of the rules is necessary.
* This is immutable data structure, it can be augmented with RuleStates from block extension
* sections of the blockchain, but that augmentation is only available in stateful context.
*/
val currentSettings: SigmaValidationSettings = new MapSigmaValidationSettings({
def currentSettings: SigmaValidationSettings = new MapSigmaValidationSettings({
val map = ruleSpecs.map(r => r.id -> (r, EnabledRule)).toMap
assert(map.size == ruleSpecs.size, s"Duplicate ruleIds ${ruleSpecs.groupBy(_.id).filter(g => g._2.length > 1)}")
map
Expand Down
8 changes: 6 additions & 2 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ sealed trait MethodsContainer {

/** Lookup method in this type by method's id or throw ValidationException.
* This method can be used in trySoftForkable section to either obtain valid method
* or catch ValidatioinException which can be checked for soft-fork condition.
* or catch ValidationException which can be checked for soft-fork condition.
* It delegate to getMethodById to lookup method.
*
* @see getMethodById
*/
def methodById(methodId: Byte): SMethod = {
ValidationRules.CheckAndGetMethod(this, methodId)
if (VersionContext.current.isV6SoftForkActivated) {
ValidationRules.CheckAndGetMethodV6(this, methodId)
} else {
ValidationRules.CheckAndGetMethod(this, methodId)
}
}

/** Finds a method descriptor [[SMethod]] for the given name. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import java.nio.ByteBuffer
* @see [[SigmaDslBuilder]] for detailed descriptions
*/
class CSigmaDslBuilder extends SigmaDslBuilder { dsl =>
def validationSettings: SigmaValidationSettings = ValidationRules.currentSettings

override val Colls: CollBuilder = sigma.Colls

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package org.ergoplatform.validation
import sigma.validation.SigmaValidationSettings

trait ValidationSpecification {
implicit val vs: SigmaValidationSettings = ValidationRules.currentSettings
def vs: SigmaValidationSettings = ValidationRules.currentSettings
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class SoftForkabilitySpecification extends SigmaTestingData
trySoftForkable(false) {
action
true
}
}(vs)
}, {
case ve: ValidationException if ve.rule == rule => true
case _ => false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ class BasicOpsSpecification extends CompilerTestingCommons
null
)
}

varTest()
}

Expand Down
Loading