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

Candidate for 6.0.0 release #930

Open
wants to merge 385 commits into
base: master
Choose a base branch
from
Open
Changes from 22 commits
Commits
Show all changes
385 commits
Select commit Hold shift + click to select a range
fc6d856
mod, toSigned, subtractMod
kushti Jun 17, 2024
62fd2a3
initial stub and roundtrip test with longToByteArray
kushti Jun 17, 2024
8bcc1ef
impl and tests done without costing etc
kushti Jun 18, 2024
b7e2a38
first failing test
kushti Jun 19, 2024
828ba27
passing test from getVar from another input
kushti Jun 27, 2024
b80ef29
invalid tests
kushti Jun 28, 2024
6a3cbac
initial failing test & impl
kushti Jun 29, 2024
af92a3f
test passing
kushti Jun 29, 2024
a731962
simplifying the code
kushti Jul 5, 2024
cb7e262
initial toBits failing tests
kushti Jul 6, 2024
f577fd3
passing test (compilation fixed)
kushti Jul 8, 2024
cadf53d
tests for Byte and BigInt
kushti Jul 8, 2024
81ed008
Merge branch 'i486-toBytes' of github.com:ScorexFoundation/sigmastate…
kushti Jul 8, 2024
ee59083
Byte.toBits test passing
kushti Jul 8, 2024
3fde5fa
toBits tests for Long and BigInt(failing)
kushti Jul 8, 2024
9ea7597
BigInt.toBits test passing
kushti Jul 8, 2024
be77315
bitwise inversion
kushti Jul 9, 2024
a575d38
bitwiseInverse tests for Long and Byte
kushti Jul 9, 2024
7ff3542
bitwise or impl
kushti Jul 10, 2024
868fbb1
bitwiseAnd
kushti Jul 10, 2024
f21436d
bitwiseXor
kushti Jul 10, 2024
ced229f
shiftLeft
kushti Jul 11, 2024
9519ef6
shiftRight
kushti Jul 16, 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
7f3a33c
extending tests in LanguageSpecificationV6
kushti Jul 24, 2024
271ec30
Merge pull request #1007 from ScorexFoundation/i877
kushti Jul 24, 2024
793af1b
merging w. 6.0
kushti Jul 26, 2024
1271a79
ScalaDoc for headerDecoder
kushti Jul 26, 2024
b677b18
merging w. i969
kushti Jul 26, 2024
e501a8b
polishing, LSV6 test
kushti Jul 26, 2024
8f9b549
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Jul 30, 2024
4c63a60
LSV5 & LSV6 tests
kushti Jul 30, 2024
89f2df6
checkPoW added to collectMethods
kushti Jul 31, 2024
61f90cd
assertEXceptionThrown
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
ba878b8
fixing GraphIRReflection for checkPow, test for isoHeader for known v…
kushti Jul 31, 2024
b41d16c
test vectors for Blake2b256 and Long -> BigInt
kushti Jul 31, 2024
c2788b4
fixing checkPow test in JS
kushti Aug 1, 2024
26809c9
passing but improper changedFeature test
kushti Aug 2, 2024
eb219dd
merging w. 6.0.0
kushti Aug 2, 2024
bfd1049
yarn.lock added to .gitignore
kushti Aug 2, 2024
8133fad
yarn.lock removed
kushti Aug 2, 2024
6f509f9
Merge branch 'SethDusek-develop' into v6.0.0
kushti Aug 2, 2024
962a484
merging w. 6.0.0 , set tree size flag for trees v0 in SigmaDslTesting…
kushti Aug 3, 2024
04f6fee
test for substConstants with 5 elems
kushti Aug 4, 2024
f851b62
LSV5 fix
kushti Aug 5, 2024
3f7e784
Scala 2.11 compilation fix, ScalaDoc returned
kushti Aug 5, 2024
75a1fdb
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 5, 2024
8b17643
fixed regression in CrossVersionProps
kushti Aug 5, 2024
b6aad2c
userDefinedInvoke ScalaDoc
kushti Aug 5, 2024
2a3c72d
Merge pull request #995 from ScorexFoundation/i994-fix-subst-constants
kushti Aug 5, 2024
17c3e6b
mrging w. 6.0.0
kushti Aug 5, 2024
2cfd2ff
Merge pull request #1002 from ScorexFoundation/v6.0-methodcall
kushti Aug 6, 2024
2e3db09
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 6, 2024
e7fde10
versioned execution depending on tree version, newFeature test
kushti Aug 6, 2024
fed22d6
merging w. 6.0.0, AutolykosSolution eq and hashcode
kushti Aug 6, 2024
04eb6aa
Merge branch 'i969' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Aug 6, 2024
57ba522
merging w. 6.0.0
kushti Aug 8, 2024
8da3575
fixed tests in LSV6
kushti Aug 9, 2024
ea0890b
tree versioning removed, scaladoc
kushti Aug 12, 2024
26f92f1
merging w. 6.0.0
kushti Aug 12, 2024
12e888d
scala 2.11 compilation fix
kushti Aug 12, 2024
b0fbfbb
fixing getVar typing during tree building, simpler execution for getV…
kushti Aug 13, 2024
65144a9
merging w. 6.0.0
kushti Aug 13, 2024
49a393c
merged w. 6.0.0
kushti Aug 19, 2024
649069b
fixed cost, improved args list for SigmaDslBuilder.fromBigEndianBytes
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
3037f1a
merging w 6.0.0, fixing ErgoTreeSpec
kushti Aug 27, 2024
016262b
removing unused SNumericTypeMethods.getMethods
kushti Aug 27, 2024
5063bae
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 27, 2024
acb76c9
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Aug 27, 2024
877ed78
adding new methods to GraphIRReflection
kushti Aug 30, 2024
a988d90
Merge pull request #972 from ScorexFoundation/i969
kushti Sep 2, 2024
2cd57e1
Merge pull request #968 from ScorexFoundation/i958-2
kushti Sep 2, 2024
baef87f
more efficient toBits impl
kushti Sep 2, 2024
c7918ad
merging v6.0.0
kushti Sep 2, 2024
8208dd8
Box.getReg with computable index
kushti Sep 3, 2024
05c9e67
merging w. 6.0.0
kushti Sep 3, 2024
8e46b69
Merge pull request #1015 from ScorexFoundation/i416
kushti Sep 3, 2024
b068b10
Serialize SFunc in TypeSerializer
kushti Sep 3, 2024
1990030
Merge pull request #1020 from ScorexFoundation/i847
kushti Sep 3, 2024
5a983b3
merging w. 6.0.0
kushti Sep 3, 2024
2e8d8f4
optimizing imports, polishing
kushti Sep 3, 2024
d284f79
fixing post-merging failing test
kushti Sep 3, 2024
0c674fe
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Sep 4, 2024
ed5b8f5
fixing SigmaTyperTest
kushti Sep 4, 2024
b2de9cf
scaladoc
kushti Sep 6, 2024
9a10d17
merging w. i1006 (numeric methods)
kushti Sep 9, 2024
eccc9ca
6.0 methods for Byte in LSV6
kushti Sep 10, 2024
f566b7b
6.0 methods for Short in LSV6
kushti Sep 10, 2024
8cf4264
6.0 methods for Int in LSV6
kushti Sep 10, 2024
fa2c2df
Long tests in LSV6, shift check in shiftRight
kushti Sep 11, 2024
48db432
shiftLeft/shiftRight shift limit
kushti Sep 11, 2024
a2f3030
bigint - LSV6 tests
kushti Sep 11, 2024
297265f
arg descs, 2.11 comp fix, BOS tests fixed
kushti Sep 12, 2024
89d4477
Merge branch 'i1006' of github.com:ScorexFoundation/sigmastate-interp…
kushti Sep 12, 2024
f20635e
merging w v6.0.0
kushti Sep 13, 2024
7e3b676
fixing method calls check test
kushti Sep 16, 2024
55d03cd
addressing review comments
kushti Sep 16, 2024
4343bc9
fix for longToByteArray support in JS
kushti Sep 17, 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
5f0c5c5
scaladoc improvements, Ints.toBits
kushti Sep 20, 2024
3d88fc2
Merge pull request #1017 from ScorexFoundation/i1006
kushti Sep 20, 2024
9c310c7
merging w. 6.0.0
kushti Sep 20, 2024
f5feee5
Merge pull request #989 from ScorexFoundation/v6.0-serialize
kushti Sep 20, 2024
43db8df
scrypto 3.0.0
kushti Sep 23, 2024
9fd499a
merging w. 6.0.0
kushti Sep 24, 2024
8136c8f
new methods added to ReflectionData
kushti Sep 24, 2024
1999a2a
merging w. 6.0.0
kushti Sep 26, 2024
586aadd
LSV6 tests, predefined method
kushti Sep 26, 2024
2cdc34e
fixing JS tests
kushti Sep 26, 2024
d738ac5
fixing JS tests
kushti Sep 27, 2024
1989d19
LSV6 tests
kushti Sep 27, 2024
8f45909
merging w 6.0.0
kushti Sep 27, 2024
6459b07
fix ErgoTreeSpec
kushti Sep 27, 2024
ee35792
merging w. 6.0.0
kushti Sep 29, 2024
a3f25ef
LSV6 tests
kushti Sep 30, 2024
f24e9ad
predefined fn, LangSpec notes, polishing PR
kushti Sep 30, 2024
166c261
merging w. 6.0.0
kushti Sep 30, 2024
edc91ba
tests
kushti Sep 30, 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
af792b5
addressing review comments
kushti Oct 1, 2024
6fa801c
Merge pull request #1013 from ScorexFoundation/i993
kushti Oct 1, 2024
ee25e40
merging w. 6.0.0
kushti Oct 1, 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
e052255
merging w. 6.0.0
kushti Oct 3, 2024
d8fab5e
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 3, 2024
5c4ccf1
merging w. 6.0.0
kushti Oct 3, 2024
6c1ac1e
fix for AVLtreedata lift in JS
kushti Oct 3, 2024
e4a611d
fixing MethodCallSerializerSpecification
kushti Oct 4, 2024
c5c37ff
fixing JS reflection
kushti Oct 4, 2024
1d47d5f
addressing review comments
kushti Oct 7, 2024
83ba4a4
Merge pull request #1010 from ScorexFoundation/i1004
kushti Oct 7, 2024
11d869f
merging w. 6.0.0
kushti Oct 7, 2024
08b02c7
initial some test passing
kushti Oct 7, 2024
2ba5a4f
PropertyCallSerializer fix, explicitTypeArgs fix, more tests
kushti Oct 8, 2024
29ed83a
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 8, 2024
f151e1d
merging w. 6.0.0
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
09ec5f1
ignoring bulletproof test, impoving comments
kushti Oct 18, 2024
5cabedd
equalsPairCollWithCollOverArray
kushti Oct 18, 2024
571e721
Merge pull request #1011 from ergoplatform/i909
kushti Oct 18, 2024
c21ed63
Merge pull request #1008 from ergoplatform/i906
kushti Oct 21, 2024
35fe87a
merging w. 6.0.0
kushti Oct 21, 2024
9036aec
improving tests in BasicOpsSpecification, type test for getVarFromInput
kushti Oct 21, 2024
8ae51e4
split in LSV6
kushti Oct 21, 2024
ceff4b2
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Oct 21, 2024
5f6b9ee
LSV6 tests
kushti Oct 22, 2024
03bfd6a
polishing
kushti Oct 22, 2024
1fbd4e5
Update docs/LangSpec.md
kushti Oct 24, 2024
208a191
Update docs/LangSpec.md
kushti Oct 24, 2024
b074b28
Merge pull request #1016 from ergoplatform/i978
kushti Oct 24, 2024
9d7962a
merging w. 6.0.0
kushti Oct 24, 2024
06fff23
merging w. 6.0.0
kushti Oct 24, 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
ae0421a
fixing JS test
kushti Nov 14, 2024
aa3fbbd
JS test comment
kushti Nov 14, 2024
cedcfbe
fixing tupleGen
kushti Nov 15, 2024
a66ab55
compilation err fix
kushti Nov 15, 2024
6d80439
merging w. 6.0.0
kushti Nov 18, 2024
20f68c0
decoding nbits from an Ergo block header
kushti Nov 18, 2024
e374229
LSV6 test
kushti Nov 18, 2024
eb50ab4
raising costs for encode/decode
kushti Nov 18, 2024
367d320
fixing cost comments
kushti Nov 19, 2024
494221a
Merge pull request #962 from ergoplatform/i675-2
kushti Nov 19, 2024
b0e7690
merging w. 6.0.0
kushti Nov 19, 2024
4c03c24
merging w. 6.0.0
kushti Nov 19, 2024
f195072
Global.deserializeTo[] method
kushti Nov 22, 2024
47b5558
Merge pull request #979 from ergoplatform/6.0-deserialize
kushti Nov 22, 2024
c0ea4b0
Autolykos 2 validation for custom message
kushti Nov 22, 2024
6d5a18b
Merge pull request #965 from ergoplatform/i958
kushti Nov 22, 2024
ee5fa99
merging w. 6.0.0
kushti Nov 22, 2024
46433f8
merging w. 6.0.0
kushti Nov 22, 2024
fa4b4b4
doc update
kushti Nov 22, 2024
f3e21b1
Merge pull request #1026 from ergoplatform/i462
kushti Nov 27, 2024
42d7fc7
merging w. 6.0.0
kushti Nov 27, 2024
912a523
Update core/js/src/main/scala/sigma/js/Type.scala
kushti Nov 29, 2024
0af752d
Update core/shared/src/main/scala/sigma/SigmaDsl.scala
kushti Nov 29, 2024
b545aa5
Update sc/shared/src/test/scala/sigmastate/ErgoTreeSpecification.scala
kushti Nov 29, 2024
ad3506e
addressing review comments
kushti Nov 29, 2024
847e4bb
Merge branch 'i554' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Nov 29, 2024
c1e5ba3
not throwing exception on duplicate key
kushti Dec 2, 2024
0c74184
insertOrUpdate
kushti Dec 3, 2024
754d624
fixing JS tests and ErgoTree specification
kushti Dec 3, 2024
469eab7
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Dec 4, 2024
b2ef5b5
Merge branch 'i554' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Dec 4, 2024
326b315
UnsignedBigInt added to liftToConstant
kushti Dec 4, 2024
6e34213
versioning for SUnsignedBigInt check
kushti Dec 4, 2024
1969223
Merge pull request #997 from ergoplatform/i554
kushti Dec 4, 2024
780b28b
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Dec 4, 2024
a506be8
merging w. 6.0.0
kushti Dec 4, 2024
38c2f63
Update interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.s…
kushti Dec 5, 2024
b85ba9c
cleared outdated comments in SigmaBuilderTest
kushti Dec 5, 2024
3952ab4
Merge branch 'i905' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Dec 5, 2024
2ad87f4
PreHeader added
kushti Dec 5, 2024
d13dd4d
Merge pull request #1021 from ergoplatform/i905
kushti Dec 5, 2024
b80b3af
Merge branch 'v6.0.0' of github.com:ScorexFoundation/sigmastate-inter…
kushti Dec 5, 2024
ea31523
polishing, doc and comments update
kushti Dec 16, 2024
aa61236
close #1044 : fix for Global.decodeNBits method can produce bigint ou…
kushti Jan 6, 2025
2c501a7
Update interpreter/shared/src/main/scala/sigmastate/interpreter/CErgo…
kushti Jan 9, 2025
18a6a77
comments improved
kushti Jan 9, 2025
45a4686
Merge branch 'i908' of github.com:ScorexFoundation/sigmastate-interpr…
kushti Jan 9, 2025
f1c1287
Merge pull request #1038 from ergoplatform/i908
kushti Jan 9, 2025
bff17fe
merging w. v6.0.0
kushti Jan 16, 2025
21f71a3
ok and invalid values in tests
kushti Jan 20, 2025
5f3be02
Merge pull request #1045 from ergoplatform/i1044
kushti Jan 20, 2025
8a24f5d
merging w. develop
kushti Feb 13, 2025
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
24 changes: 13 additions & 11 deletions data/js/src/main/scala/sigma/Platform.scala
Original file line number Diff line number Diff line change
@@ -14,31 +14,33 @@ object Platform {
private[sigma] def liftToConstant(obj: Any, builder: SigmaBuilder): Nullable[Constant[SType]] = {
import builder._
obj match {
case arr: Array[Boolean] => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean))
case arr: Array[Byte] => Nullable(mkCollectionConstant[SByte.type](arr, SByte))
case arr: Array[Short] => Nullable(mkCollectionConstant[SShort.type](arr, SShort))
case arr: Array[Int] => Nullable(mkCollectionConstant[SInt.type](arr, SInt))
case arr: Array[Long] => Nullable(mkCollectionConstant[SLong.type](arr, SLong))
case arr: Array[BigInteger] => Nullable(mkCollectionConstant[SBigInt.type](arr.map[BigInt](n => CBigInt(n)), SBigInt))
case arr: Array[String] => Nullable(mkCollectionConstant[SString.type](arr, SString))
case arr: Array[Boolean] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean))
case arr: Array[Byte] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SByte.type](arr, SByte))
case arr: Array[Short] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SShort.type](arr, SShort))
case arr: Array[Int] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SInt.type](arr, SInt))
case arr: Array[Long] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SLong.type](arr, SLong))
case arr: Array[BigInteger] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBigInt.type](arr.map[BigInt](n => CBigInt(n)), SBigInt))
case arr: Array[String] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SString.type](arr, SString))
case v: AnyValue =>
val tpe = Evaluation.rtypeToSType(v.tVal)
Nullable(mkConstant[tpe.type](v.value.asInstanceOf[tpe.WrappedType], tpe))
case v: Int => Nullable(mkConstant[SInt.type](v, SInt))
case v: Long => Nullable(mkConstant[SLong.type](v, SLong))
case v: BigInteger => Nullable(mkConstant[SBigInt.type](CBigInt(v), SBigInt))
case v: BigInteger if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBigInt.type](CBigInt(v), SBigInt))
case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt))
case n: sigma.UnsignedBigInt => Nullable(mkConstant[SUnsignedBigInt.type](n, SUnsignedBigInt))
case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement))
case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf)
case v: String => Nullable(mkConstant[SString.type](v, SString))
case v: String if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SString.type](v, SString))
case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader))
case h: PreHeader if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SPreHeader.type](h, SPreHeader))

// The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the
// isCorrectType requirement would fail in ConstantNode constructor.
// This method is used as part of consensus in SubstConstants operation, however
// ErgoBox cannot be passed as argument as it is never valid value during evaluation.
// Thus we can use activation-based versioning and fix this code when v5.0 is activated.
case b: ErgoBox =>
case b: ErgoBox if !VersionContext.current.isV6SoftForkActivated =>
Nullable(mkConstant[SBox.type](CBox(b), SBox)) // fixed in v5.0

// this case is added in v5.0 and it can be useful when the box value comes from a
@@ -48,7 +50,7 @@ object Platform {
Nullable(mkConstant[SBox.type](b, SBox))
else
Nullable.None // return the same result as in v4.x when there was no this case
case avl: AvlTreeData => Nullable(mkConstant[SAvlTree.type](CAvlTree(avl), SAvlTree))
case avl: AvlTreeData if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SAvlTree.type](CAvlTree(avl), SAvlTree))
case avl: AvlTree => Nullable(mkConstant[SAvlTree.type](avl, SAvlTree))
case sb: SigmaBoolean => Nullable(mkConstant[SSigmaProp.type](CSigmaProp(sb), SSigmaProp))
case p: SigmaProp => Nullable(mkConstant[SSigmaProp.type](p, SSigmaProp))
26 changes: 15 additions & 11 deletions data/jvm/src/main/scala/sigma/Platform.scala
Original file line number Diff line number Diff line change
@@ -16,29 +16,33 @@ object Platform {
private[sigma] def liftToConstant(obj: Any, builder: SigmaBuilder): Nullable[Constant[SType]] = {
import builder._
obj match {
case arr: Array[Boolean] => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean))
case arr: Array[Byte] => Nullable(mkCollectionConstant[SByte.type](arr, SByte))
case arr: Array[Short] => Nullable(mkCollectionConstant[SShort.type](arr, SShort))
case arr: Array[Int] => Nullable(mkCollectionConstant[SInt.type](arr, SInt))
case arr: Array[Long] => Nullable(mkCollectionConstant[SLong.type](arr, SLong))
case arr: Array[BigInteger] => Nullable(mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt(_)), SBigInt))
case arr: Array[String] => Nullable(mkCollectionConstant[SString.type](arr, SString))
case arr: Array[Boolean] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBoolean.type](arr, SBoolean))
case arr: Array[Byte] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SByte.type](arr, SByte))
case arr: Array[Short] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SShort.type](arr, SShort))
case arr: Array[Int] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SInt.type](arr, SInt))
case arr: Array[Long] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SLong.type](arr, SLong))
case arr: Array[BigInteger] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt(_)), SBigInt))
case arr: Array[String] if !VersionContext.current.isV6SoftForkActivated => Nullable(mkCollectionConstant[SString.type](arr, SString))
case v: Byte => Nullable(mkConstant[SByte.type](v, SByte))
case v: Short => Nullable(mkConstant[SShort.type](v, SShort))
case v: Int => Nullable(mkConstant[SInt.type](v, SInt))
case v: Long => Nullable(mkConstant[SLong.type](v, SLong))
case v: BigInteger => Nullable(mkConstant[SBigInt.type](SigmaDsl.BigInt(v), SBigInt))
case v: BigInteger if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SBigInt.type](SigmaDsl.BigInt(v), SBigInt))
case n: sigma.BigInt => Nullable(mkConstant[SBigInt.type](n, SBigInt))
case ge: GroupElement => Nullable(mkConstant[SGroupElement.type](ge, SGroupElement))
case b: Boolean => Nullable(if (b) TrueLeaf else FalseLeaf)
case v: String => Nullable(mkConstant[SString.type](v, SString))
case h: Header if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SHeader.type](h, SHeader))
case h: PreHeader if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SPreHeader.type](h, SPreHeader))
case n: sigma.UnsignedBigInt if VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SUnsignedBigInt.type](n, SUnsignedBigInt))

case v: String if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SString.type](v, SString))

// The Box lifting was broken in v4.x. `SigmaDsl.Box(b)` was missing which means the
// isCorrectType requirement would fail in ConstantNode constructor.
// This method is used as part of consensus in SubstConstants operation, however
// ErgoBox cannot be passed as argument as it is never valid value during evaluation.
// Thus we can use activation-based versioning and fix this code when v5.0 is activated.
case b: ErgoBox =>
case b: ErgoBox if !VersionContext.current.isV6SoftForkActivated =>
Nullable(mkConstant[SBox.type](SigmaDsl.Box(b), SBox)) // fixed in v5.0

// this case is added in v5.0 and it can be useful when the box value comes from a
@@ -48,7 +52,7 @@ object Platform {
Nullable(mkConstant[SBox.type](b, SBox))
else
Nullable.None // return the same result as in v4.x when there was no this case
case avl: AvlTreeData => Nullable(mkConstant[SAvlTree.type](SigmaDsl.avlTree(avl), SAvlTree))
case avl: AvlTreeData if !VersionContext.current.isV6SoftForkActivated => Nullable(mkConstant[SAvlTree.type](SigmaDsl.avlTree(avl), SAvlTree))
case avl: AvlTree => Nullable(mkConstant[SAvlTree.type](avl, SAvlTree))
case sb: SigmaBoolean => Nullable(mkConstant[SSigmaProp.type](SigmaDsl.SigmaProp(sb), SSigmaProp))
case p: SigmaProp => Nullable(mkConstant[SSigmaProp.type](p, SSigmaProp))
85 changes: 71 additions & 14 deletions interpreter/shared/src/test/scala/sigma/ast/SigmaBuilderTest.scala
Original file line number Diff line number Diff line change
@@ -117,14 +117,18 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma

def testArray[T <: SType]
(v: T#WrappedType, c: Constant[T])(implicit t: RType[T#WrappedType]) = {
// for any Byte and Short value `v`, lifting of array should succeed
val arr = Array.fill[T#WrappedType](10)(v)(t.classTag)
testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant(arr, c.tpe))
}

def testArrayFailure[T <: SType]
(v: T#WrappedType, c: Constant[T])(implicit t: RType[T#WrappedType]) = {
val arr = Array.fill[T#WrappedType](10)(v)(t.classTag)
testFailure(arr)
}

def testColl[T <: SType]
(v: T#WrappedType, c: Constant[T])(implicit t: RType[T#WrappedType]) = {
// for any Byte and Short value `v`, lifting of Coll should succeed
val arr = Array.fill[T#WrappedType](10)(v)(t.classTag)
val coll = arr.toColl
testSuccess(coll, TransformingSigmaBuilder.mkCollectionConstant(coll, c.tpe))
@@ -134,7 +138,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma
val v = true
val c = BooleanConstant(v)
test[SBoolean.type](v, c)
testArray[SBoolean.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testArray[SBoolean.type](v, c)
} else {
testArrayFailure[SBoolean.type](v, c)
}
testColl[SBoolean.type](v, c)
}

@@ -143,7 +151,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma
val c = ByteConstant(v)
testNumeric[SByte.type](v, c)
testLiftingOfCAnyValue[SByte.type](v, c)
testArray[SByte.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testArray[SByte.type](v, c)
} else {
testArrayFailure[SByte.type](v, c)
}
testColl[SByte.type](v, c)
}

@@ -152,40 +164,65 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma
val c = ShortConstant(v)
testNumeric[SShort.type](v, c)
testLiftingOfCAnyValue[SShort.type](v, c)
testArray[SShort.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testArray[SShort.type](v, c)
} else {
testArrayFailure[SShort.type](v, c)
}
testColl[SShort.type](v, c)
}

property("liftToConstant Int") {
val v = 1
val c = IntConstant(v)
test[SInt.type](v, c)
testArray[SInt.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testArray[SInt.type](v, c)
} else {
testArrayFailure[SInt.type](v, c)
}
testColl[SInt.type](v, c)
}

property("liftToConstant Long") {
val v = 1L
val c = LongConstant(v)
test[SLong.type](v, c)
testArray[SLong.type](v, c) // TODO v6.0: arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testArray[SLong.type](v, c)
} else {
testArrayFailure[SLong.type](v, c)
}
testColl[SLong.type](v, c)
}

property("liftToConstant String") {
val v = "abc"
val c = StringConstant(v)
test[SString.type](v, c)
testArray[SString.type](v, c) // TODO v6.0: String should be liftable at all (not supported in ErgoTree) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
testColl[SString.type](v, c)
if (!VersionContext.current.isV6SoftForkActivated) {
// v6.0: String should not be liftable at all (not supported in ErgoTree) (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
test[SString.type](v, c)
testArray[SString.type](v, c)
testColl[SString.type](v, c)
} else {
testFailure(v)
}
}

property("liftToConstant BigInteger") {
val v = BigInteger.valueOf(1L)
val c = BigIntConstant(v)
testSuccess(v, c) // TODO v6.0: both BigInteger and arrays should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testSuccess(v, c)
} else {
testFailure(v)
}
val arr = Array.fill(10)(v)
testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt), c.tpe))
if (!VersionContext.current.isV6SoftForkActivated) {
testSuccess(arr, TransformingSigmaBuilder.mkCollectionConstant[SBigInt.type](arr.map(SigmaDsl.BigInt), c.tpe))
} else {
testFailure(arr)
}
}

property("liftToConstant BigInt") {
@@ -204,10 +241,26 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma
testColl[SGroupElement.type](v, c)
}

property("liftToConstant Header") {
val h = TestData.h1
val c = HeaderConstant(h)
if (VersionContext.current.isV6SoftForkActivated) {
testSuccess(h, c)
} else {
testFailure(h)
}
testFailure(Array.fill(10)(h))
testColl[SHeader.type](h, c)
}

property("liftToConstant ErgoBox") {
val v = TestData.b2.asInstanceOf[CBox].wrappedValue
val c = BoxConstant(TestData.b2)
testSuccess(v, c) // TODO v6.0: ErgoBox should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testSuccess(v, c)
} else {
testFailure(v)
}
testFailure(Array.fill(10)(v))
}

@@ -234,7 +287,11 @@ class SigmaBuilderTest extends AnyPropSpec with ScalaCheckPropertyChecks with Ma
property("liftToConstant AvlTreeData") {
val v = TestData.t1.asInstanceOf[CAvlTree].wrappedValue
val c = AvlTreeConstant(SigmaDsl.avlTree(v))
testSuccess(v, c) // TODO v6.0: AvlTreeData should not be liftable directly (see https://github.com/ScorexFoundation/sigmastate-interpreter/issues/905)
if (!VersionContext.current.isV6SoftForkActivated) {
testSuccess(v, c)
} else {
testFailure(v)
}
testFailure(Array.fill(10)(v))
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ergoplatform

import org.ergoplatform.ErgoAddressEncoder.NetworkPrefix
import sigma.Colls
import sigma.ast.SType
import sigma.ast.syntax.SigmaPropValue
import sigma.ast.Value
@@ -32,7 +33,7 @@ object ErgoScriptPredef {
networkPrefix: NetworkPrefix)
(implicit IR: IRContext): SigmaPropValue = {
val env = emptyEnv +
("tokenId" -> tokenId, "thresholdAmount" -> thresholdAmount)
("tokenId" -> Colls.fromArray(tokenId), "thresholdAmount" -> thresholdAmount)
val res = compileWithCosting(env,
"""{
| val sumValues = { (xs: Coll[Long]) => xs.fold(0L, { (acc: Long, amt: Long) => acc + amt }) }
24 changes: 12 additions & 12 deletions sc/shared/src/test/scala/org/ergoplatform/ErgoTreePredefSpec.scala
Original file line number Diff line number Diff line change
@@ -58,8 +58,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio
boxesToSpend = inputBoxes,
spendingTransaction,
self = inputBox, activatedVersionInTests)
val pr = prover.prove(emptyEnv + (ScriptNameProp -> "boxCreationHeight_prove"), propTree, ctx, fakeMessage).get
verifier.verify(emptyEnv + (ScriptNameProp -> "boxCreationHeight_verify"), propTree, ctx, pr, fakeMessage).get._1 shouldBe true
val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).get
verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).get._1 shouldBe true
}

property("collect coins from the founders' box") {
@@ -118,8 +118,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio
boxesToSpend = inputBoxes,
spendingTransaction,
self = inputBoxes.head, activatedVersionInTests)
val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkSpending_prove"), prop, ctx, fakeMessage).get
verifier.verify(emptyEnv + (ScriptNameProp -> "checkSpending_verify"), prop, ctx, pr, fakeMessage).get._1 shouldBe true
val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).get
verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).get._1 shouldBe true
}
}

@@ -148,13 +148,13 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio
self = inputBoxes.head, activatedVersionInTests)

// should not be able to collect before minerRewardDelay
val prove = prover.prove(emptyEnv + (ScriptNameProp -> "rewardOutputScript_prove"), prop, ctx, fakeMessage).get
verifier.verify(emptyEnv + (ScriptNameProp -> "rewardOutputScript_verify"), prop, prevBlockCtx, prove, fakeMessage)
val prove = prover.prove(emptyEnv, prop, ctx, fakeMessage).get
verifier.verify(emptyEnv, prop, prevBlockCtx, prove, fakeMessage)
.getOrThrow should matchPattern { case (false,_) => }

// should be able to collect after minerRewardDelay
val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove"), prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv + (ScriptNameProp -> "verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
}

property("create transaction collecting the emission box") {
@@ -232,8 +232,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio
self = inputBoxes.head,
activatedVersionInTests).withCostLimit(scriptCostLimitInTests * 10)

val pr = prover.prove(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_prove"), prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv + (ScriptNameProp -> "tokenThresholdScript_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
}


@@ -308,8 +308,8 @@ class ErgoTreePredefSpec extends CompilerTestingCommons with CompilerCrossVersio
boxesToSpend = inputBoxes,
spendingTransaction,
self = inputBoxes.head, activatedVersionInTests)
val pr = prover.prove(emptyEnv + (ScriptNameProp -> "checkRewardTx_prove"), prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv + (ScriptNameProp -> "checkRewardTx_verify"), prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
val pr = prover.prove(emptyEnv, prop, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv, prop, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
spendingTransaction
}

Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import sigma.Colls
import sigma.VersionContext.V6SoftForkVersion
import sigma.VersionContext.V6SoftForkVersion
import sigma.VersionContext
import sigma.data.{CAND, CAvlTree, CHeader, ProveDlog, SigmaBoolean, TrivialProp}
import sigma.data.{CAND, CAvlTree, CBox, CHeader, ProveDlog, SigmaBoolean, TrivialProp}
import sigma.interpreter.ContextExtension
import sigma.data.{AvlTreeData, CAND, ProveDlog, SigmaBoolean, TrivialProp}
import sigma.VersionContext.V6SoftForkVersion
@@ -147,12 +147,18 @@ class TestingInterpreterSpecification extends CompilerTestingCommons
val env = Map(
"dk1" -> dk1,
"dk2" -> dk2,
"bytes1" -> Array[Byte](1, 2, 3),
"bytes2" -> Array[Byte](4, 5, 6),
"box1" -> testBox(10, TrueTree, 0, Seq(), Map(
"bytes1" -> Colls.fromArray(Array[Byte](1, 2, 3)),
"bytes2" -> Colls.fromArray(Array[Byte](4, 5, 6)),
"box1" -> (if(VersionContext.current.isJitActivated) {
CBox(testBox(10, TrueTree, 0, Seq(), Map(
reg1 -> IntArrayConstant(Array[Int](1, 2, 3)),
reg2 -> BoolArrayConstant(Array[Boolean](true, false, true))
)))} else {
testBox(10, TrueTree, 0, Seq(), Map(
reg1 -> IntArrayConstant(Array[Int](1, 2, 3)),
reg2 -> BoolArrayConstant(Array[Boolean](true, false, true))
))
))
})
)
val prop = mkTestErgoTree(compile(env, code)(IR).asBoolValue.toSigmaProp)
val challenge = Array.fill(32)(Random.nextInt(100).toByte)
Original file line number Diff line number Diff line change
@@ -15,14 +15,13 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn
import sigmastate.helpers.TestingHelpers._
import sigmastate.interpreter.Interpreter.ScriptNameProp
import sigma.ast.syntax._
import sigma.Coll
import sigma.{AvlTree, Coll, Colls, Context}
import sigma.ast.SAvlTree
import sigma.ast.syntax.{GetVarByteArray, OptionValueOps}
import sigma.compiler.ir.IRContext
import sigma.data.{AvlTreeData, AvlTreeFlags, CSigmaProp, TrivialProp}
import sigma.eval.SigmaDsl
import sigma.interpreter.ProverResult
import sigma.{AvlTree, Context}
import sigmastate.eval.Extensions.AvlTreeOps


@@ -39,9 +38,6 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons
def genKey(str: String): ADKey = ADKey @@@ Blake2b256("key: " + str)
def genValue(str: String): ADValue = ADValue @@@ Blake2b256("val: " + str)

val inKey = genKey("init key")
val inValue = genValue("init value")

property("avl tree - removals") {
case class AvlTreeContract[Spec <: ContractSpec]
(ops: Coll[Coll[Byte]], proof: Coll[Byte], prover: Spec#ProvingParty)
@@ -204,7 +200,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons

val treeData = new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None)

val env = Map("key" -> key, "proof" -> proof)
val env = Map("key" -> Colls.fromArray(key), "proof" -> Colls.fromArray(proof))
val prop = compile(env, """SELF.R4[AvlTree].get.contains(key, proof)""").asBoolValue.toSigmaProp

val propExp = IR.builder.mkMethodCall(
@@ -374,7 +370,7 @@ class AVLTreeScriptsSpecification extends CompilerTestingCommons
val treeData = SigmaDsl.avlTree(new AvlTreeData(digest.toColl, AvlTreeFlags.ReadOnly, 32, None))

val env = Map("proofId" -> proofId.toLong,
"keys" -> ConcreteCollection.fromItems(genKey("3"), genKey("4"), genKey("5")))
"keys" -> Colls.fromItems(Colls.fromArray(genKey("3")), Colls.fromArray(genKey("4")), Colls.fromArray(genKey("5"))))
val prop = compile(env,
"""{
| val tree = SELF.R4[AvlTree].get
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ import scorex.crypto.hash.Blake2b256
import sigma.ast._
import sigma.ast.syntax._
import sigmastate._
import sigmastate.helpers.{ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter, CompilerTestingCommons}
import sigma.Coll
import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter}
import sigma.{Coll, Colls}


class ContextEnrichingSpecification extends CompilerTestingCommons
@@ -19,7 +19,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons
val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]]
val pubkey = prover.dlogSecrets.head.publicImage

val env = Map("blake" -> Blake2b256(preimage.toArray), "pubkey" -> pubkey)
val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray)), "pubkey" -> pubkey)
val prop = compile(env,
"""{
| pubkey && blake2b256(getVar[Coll[Byte]](1).get) == blake
@@ -49,7 +49,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons
val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]]
val pubkey = prover.dlogSecrets.head.publicImage

val env = Map("blake" -> Blake2b256(preimage1.append(preimage2).toArray), "pubkey" -> pubkey)
val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage1.append(preimage2).toArray)), "pubkey" -> pubkey)
val prop = compile(env,
"""{
| pubkey && blake2b256(getVar[Coll[Byte]](1).get ++ getVar[Coll[Byte]](2).get) == blake
@@ -89,7 +89,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons
.withContextExtender(k1, ByteArrayConstant(v1))
.withContextExtender(k2, ByteArrayConstant(v2))

val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> r)
val env = Map("k1" -> k1.toInt, "k2" -> k2.toInt, "r" -> Colls.fromArray(r))
val prop = compile(env,
"{ xor(getVar[Coll[Byte]](k1).get, getVar[Coll[Byte]](k2).get) == r }").asBoolValue.toSigmaProp
val propTree = mkTestErgoTree(prop)
@@ -119,7 +119,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons
val prover = new ContextEnrichingTestProvingInterpreter
val preimage = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]]

val env = Map("blake" -> Blake2b256(preimage.toArray))
val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage.toArray)))
val prop = compile(env,
"""{
| blake2b256(getVar[Coll[Byte]](1).get) == blake
@@ -149,7 +149,7 @@ class ContextEnrichingSpecification extends CompilerTestingCommons
val preimage1 = prover.contextExtenders(1).value.asInstanceOf[Coll[Byte]]
val preimage2 = prover.contextExtenders(2).value.asInstanceOf[Coll[Byte]]

val env = Map("blake" -> Blake2b256(preimage2.append(preimage1).toArray))
val env = Map("blake" -> Colls.fromArray(Blake2b256(preimage2.append(preimage1).toArray)))
val prop = compile(env,
"""{
| blake2b256(getVar[Coll[Byte]](2).get ++ getVar[Coll[Byte]](1).get) == blake
Original file line number Diff line number Diff line change
@@ -5,11 +5,12 @@ import org.ergoplatform.ErgoBox.R4
import org.ergoplatform._
import org.scalatest.TryValues._
import scorex.crypto.hash.Blake2b256
import sigma.{Colls, VersionContext}
import sigma.ast.SCollection.SByteArray
import sigma.ast._
import sigmastate._
import sigma.ast.syntax._
import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog, TrivialProp}
import sigma.data.{AvlTreeData, CBox, ProveDHTuple, ProveDlog, TrivialProp}
import sigma.util.Extensions.EcpOps
import sigma.validation.ValidationException
import sigmastate.eval._
@@ -51,8 +52,8 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons
.withErgoTreeVersion(ergoTreeVersionInTests)

val e = compile(Map(
"h1" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes,
"h2" -> ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes),
"h1" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h1).bytes),
"h2" -> Colls.fromArray(ErgoTree.withSegregation(ergoTreeHeaderInTests, h2).bytes)),
"h1 == h1")
val exp = TrueLeaf
e shouldBe exp
@@ -192,7 +193,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons
val spendingTransaction = createTransaction(newBoxes)

def mixingRequestProp(sender: ProveDlog, timeout: Int): ErgoTree = {
val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> properHash)
val env = Map("sender" -> sender, "timeout" -> timeout, "properHash" -> Colls.fromArray(properHash))
val compiledProp = compile(env,
"""{
| val notTimePassed = HEIGHT <= timeout
@@ -459,9 +460,14 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons

val pubkey1 = prover.dlogSecrets.head.publicImage
val pubkey2 = prover.dlogSecrets(1).publicImage
val tb = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0)
val brother = if(VersionContext.current.isJitActivated) {
CBox(tb)
} else {
tb
}

val brother = testBox(value = 10, ergoTree = mkTestErgoTree(pubkey1), creationHeight = 0)
val brotherWithWrongId = testBox(value = 10,
val tbWithWrongId = testBox(value = 10,
ergoTree = mkTestErgoTree(pubkey1),
creationHeight = 0,
boxIndex = 120: Short)
@@ -482,7 +488,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons

val propExpected = BinAnd(
EQ(SizeOf(Inputs), IntConstant(2)),
EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(brother)))).toSigmaProp
EQ(ExtractId(ByIndex(Inputs, 0)), ExtractId(BoxConstant(tb)))).toSigmaProp
prop shouldBe propExpected

// try a version of the script that matches the white paper
@@ -496,18 +502,18 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons
currentHeight = 50,
lastBlockUtxoRoot = AvlTreeData.dummy,
minerPubkey = ErgoLikeContextTesting.dummyPubkey,
boxesToSpend = IndexedSeq(brother, s),
boxesToSpend = IndexedSeq(tb, s),
spendingTransaction,
self = s, activatedVersionInTests)

val pr = prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop"), propTree, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv + (ScriptNameProp -> "verify_prop"), propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true
val pr = prover.prove(emptyEnv, propTree, ctx, fakeMessage).getOrThrow
verifier.verify(emptyEnv, propTree, ctx, pr, fakeMessage).getOrThrow._1 shouldBe true

val wrongCtx = ErgoLikeContextTesting(
currentHeight = 50,
lastBlockUtxoRoot = AvlTreeData.dummy,
minerPubkey = ErgoLikeContextTesting.dummyPubkey,
boxesToSpend = IndexedSeq(brotherWithWrongId, s),
boxesToSpend = IndexedSeq(tbWithWrongId, s),
spendingTransaction,
self = s, activatedVersionInTests)

@@ -522,9 +528,9 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons
}""".stripMargin).asBoolValue.toSigmaProp
val prop2Tree = mkTestErgoTree(prop2)

prover.prove(emptyEnv + (ScriptNameProp -> "prove_prop2"), prop2Tree, ctx, fakeMessage).isFailure shouldBe true
prover.prove(emptyEnv, prop2Tree, ctx, fakeMessage).isFailure shouldBe true
verifier
.verify(emptyEnv + (ScriptNameProp -> "verify_prop2"), prop2Tree, ctx, pr, fakeMessage)
.verify(emptyEnv, prop2Tree, ctx, pr, fakeMessage)
.getOrThrow._1 shouldBe false
}

@@ -547,7 +553,12 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons
val newBoxes = IndexedSeq(newBox)
val spendingTransaction = createTransaction(newBoxes)

val env = Map("friend" -> friend)
val friendVar = if(VersionContext.current.isJitActivated){
CBox(friend)
} else {
friend
}
val env = Map("friend" -> friendVar)
val prop = compile(env,
"""{
|
@@ -623,7 +634,7 @@ class ErgoLikeInterpreterSpecification extends CompilerTestingCommons

val helloHash = Blake2b256.hash(preimageHello)

val env = Map("helloHash" -> helloHash)
val env = Map("helloHash" -> Colls.fromArray(helloHash))
val prop = compile(env,
"""{
| val cond = INPUTS(0).value > 10
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ class AtomicSwapExampleSpecification extends CompilerTestingCommons with Compile
val deadlineB = 500

val env = Map(
ScriptNameProp -> "atomic",
"height1" -> height1, "height2" -> height2,
"deadlineBob" -> deadlineB, "deadlineAlice" -> deadlineA,
"pubkeyA" -> pubkeyA, "pubkeyB" -> pubkeyB, "hx" -> hx)
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingIn
import sigmastate.helpers.TestingHelpers._
import sigmastate.interpreter.Interpreter.ScriptNameProp
import sigma.ast.syntax._
import sigmastate.interpreter.Interpreter


class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons
@@ -35,7 +36,6 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons
val minSpend = 100

val env = Map(
ScriptNameProp -> "env",
"user1" -> alicePubKey,
"user2" -> bobPubKey,
"user3" -> carolPubKey,
@@ -109,12 +109,9 @@ class ColdWalletAdvContractExampleSpecification extends CompilerTestingCommons
)
)

val dave = new ErgoLikeTestProvingInterpreter // paying to dave, some arbitrary user
val davePubKey = dave.dlogSecrets.head.publicImage

val firstWithdrawHeight = depositHeight + 1 //

val spendEnv = Map(ScriptNameProp -> "spendEnv")
val spendEnv = Interpreter.emptyEnv

// One of Alice, Bob or Carol withdraws
val firstWithdrawAmount1Key = depositAmount * percent1Key / 100 // less than or equal to percent
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@ class ColdWalletContractExampleSpecification extends CompilerTestingCommons
val minSpend = 100

val env = Map(
ScriptNameProp -> "env",
"alice" -> alicePubKey,
"bob" -> bobPubKey,
"blocksIn24h" -> IntConstant(blocksIn24h),
Original file line number Diff line number Diff line change
@@ -38,7 +38,6 @@ class DHTupleExampleSpecification extends CompilerTestingCommons
val g_x = alicePubKey.value // g_x is Alice's public key (g_x = g^x)

val env = Map(
ScriptNameProp -> "env",
"g" -> g.toGroupElement,
"g_x" -> g_x.toGroupElement
)
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@ class DemurrageExampleSpecification extends CompilerTestingCommons
val regScript = userProver.dlogSecrets.head.publicImage

val env = Map(
ScriptNameProp -> "Demurrage",
"demurragePeriod" -> demurragePeriod,
"demurrageCoeff" -> demurrageCoeff,
"regScript" -> regScript
Original file line number Diff line number Diff line change
@@ -252,8 +252,7 @@ class IcoExample extends CompilerTestingCommons
private val feeBytes = feeProp.bytes

val env = Map(
ScriptNameProp -> "withdrawalScriptEnv",
"feeBytes" -> feeBytes,
"feeBytes" -> Colls.fromArray(feeBytes),
"projectPubKey" -> project.secrets.head.publicImage
)
lazy val withdrawalScript: SigmaPropValue = compile(env,
@@ -313,7 +312,7 @@ class IcoExample extends CompilerTestingCommons
Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(withdrawalTree))
}

def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", wsHash),
def issuanceScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(wsHash)),
"""{
| val openTree = SELF.R5[AvlTree].get
|
@@ -349,7 +348,7 @@ class IcoExample extends CompilerTestingCommons
Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(tree))
}

def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", issuanceHash),
def fundingScript: SigmaPropValue = compile(env.updated("nextStageScriptHash", Colls.fromArray(issuanceHash)),
"""{
|
| val selfIndexIsZero = INPUTS(0).id == SELF.id
Original file line number Diff line number Diff line change
@@ -178,7 +178,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion

val letsTokenId = Digest32Coll @@ Colls.fromArray(Array.fill(32)(Random.nextInt(100).toByte))

val env = Map(ScriptNameProp -> "withdrawalScriptEnv", "letsToken" -> ByteArrayConstant(letsTokenId))
val env = Map("letsToken" -> ByteArrayConstant(letsTokenId))

private val miningRewardsDelay = 720
private val feeProp = ErgoTreePredef.feeProposition(miningRewardsDelay) // create ErgoTree v0
@@ -235,7 +235,7 @@ class LetsSpecification extends CompilerTestingCommons with CompilerCrossVersion

def userContractHash = Blake2b256(ErgoTreeSerializer.DefaultSerializer.serializeErgoTree(exchangeTree))

def managementScript = compile(env.updated("userContractHash", userContractHash),
def managementScript = compile(env.updated("userContractHash", Colls.fromArray(userContractHash)),
"""{
|
| val selfOut = OUTPUTS(0)
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ package sigmastate.utxo.examples
import java.math.BigInteger
import org.ergoplatform.ErgoBox.{R4, R5}
import scorex.crypto.hash.Blake2b256
import sigma.Colls
import sigma.data.{AvlTreeData, ProveDHTuple, ProveDlog}
import sigma.util.Extensions.EcpOps
import sigmastate.CompilerCrossVersionProps
@@ -41,7 +42,6 @@ class MixExampleSpecification extends CompilerTestingCommons
// val alicePubKey:ProveDlog = ProveDlog(g_x)

val fullMixEnv = Map(
ScriptNameProp -> "fullMixEnv",
"g" -> g.toGroupElement,
"gX" -> gX.toGroupElement
)
@@ -60,10 +60,9 @@ class MixExampleSpecification extends CompilerTestingCommons
).asSigmaProp)

val halfMixEnv = Map(
ScriptNameProp -> "halfMixEnv",
"g" -> g.toGroupElement,
"gX" -> gX.toGroupElement,
"fullMixScriptHash" -> Blake2b256(fullMixScript.bytes)
"fullMixScriptHash" -> Colls.fromArray(Blake2b256(fullMixScript.bytes))
)

// Note that below script allows Alice to spend the half-mix output anytime before Bob spends it.
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ package sigmastate.utxo.examples
import org.ergoplatform.ErgoBox.{R4, R5, R6, R7}
import scorex.crypto.hash.Blake2b256
import scorex.utils.Random
import sigma.Colls
import sigma.data.{AvlTreeData, ProveDlog}
import sigma.ast.{ByteArrayConstant, ByteConstant, ErgoTree, IntConstant, SigmaPropConstant}
import sigmastate._
@@ -51,9 +52,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons
val h = Blake2b256(s :+ a) // Alice's commitment

val fullGameEnv = Map(
ScriptNameProp -> "fullGameScriptEnv",
"alice" -> alicePubKey,
"k" -> h
"k" -> Colls.fromArray(h)
)

val fullGameScript = mkTestErgoTree(compile(fullGameEnv,
@@ -78,9 +78,8 @@ class RPSGameExampleSpecification extends CompilerTestingCommons
).asSigmaProp)

val halfGameEnv = Map(
ScriptNameProp -> "halfGameScript",
"alice" -> alicePubKey,
"fullGameScriptHash" -> Blake2b256(fullGameScript.bytes)
"fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes))
)

// Note that below script allows Alice to spend the half-game output anytime before Bob spends it.
Original file line number Diff line number Diff line change
@@ -3,13 +3,14 @@ package sigmastate.utxo.examples
import org.ergoplatform.ErgoBox.{R4, R5}
import org.ergoplatform._
import scorex.crypto.hash.Blake2b256
import sigma.Colls
import sigma.data.AvlTreeData
import sigma.ast.{ErgoTree, IntConstant, SigmaPropConstant}
import sigmastate._
import sigmastate.helpers.{CompilerTestingCommons, ContextEnrichingTestProvingInterpreter, ErgoLikeContextTesting, ErgoLikeTestInterpreter}
import sigmastate.helpers.TestingHelpers._
import sigmastate.interpreter.Interpreter.ScriptNameProp
import sigma.ast.syntax._
import sigmastate.interpreter.Interpreter


class ReversibleTxExampleSpecification extends CompilerTestingCommons
@@ -79,7 +80,6 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons
val carolPubKey = carol.dlogSecrets.head.publicImage

val withdrawEnv = Map(
ScriptNameProp -> "withdrawEnv",
"carol" -> carolPubKey // this pub key can reverse payments
)

@@ -94,12 +94,11 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons
val blocksIn24h = 500
val feeProposition = ErgoTreePredef.feeProposition()
val depositEnv = Map(
ScriptNameProp -> "depositEnv",
"alice" -> alicePubKey,
"blocksIn24h" -> blocksIn24h,
"maxFee" -> 10L,
"feePropositionBytes" -> feeProposition.bytes,
"withdrawScriptHash" -> Blake2b256(withdrawScript.bytes)
"feePropositionBytes" -> Colls.fromArray(feeProposition.bytes),
"withdrawScriptHash" -> Colls.fromArray(Blake2b256(withdrawScript.bytes))
)

val depositScript = mkTestErgoTree(compile(depositEnv,
@@ -189,7 +188,7 @@ class ReversibleTxExampleSpecification extends CompilerTestingCommons
self = reversibleWithdrawOutput, activatedVersionInTests
)

val spendEnv = Map(ScriptNameProp -> "spendEnv")
val spendEnv = Interpreter.emptyEnv

val proofBobSpend = bob.prove(spendEnv, withdrawScript, bobSpendContext, fakeMessage).get.proof

Original file line number Diff line number Diff line change
@@ -27,7 +27,6 @@ class TimedPaymentExampleSpecification extends CompilerTestingCommons
val bobPubKey = bob.dlogSecrets.head.publicImage

val env = Map(
ScriptNameProp -> "env",
"alice" -> alicePubKey
)

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ package sigmastate.utxo.examples
import org.ergoplatform.ErgoBox.{R4, R5, R6}
import scorex.crypto.hash.Blake2b256
import scorex.utils.Random
import sigma.Colls
import sigma.data.{AvlTreeData, ProveDlog}
import sigma.ast.{ByteArrayConstant, ByteConstant, IntConstant, SigmaPropConstant}
import sigmastate._
@@ -51,9 +52,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons
val h = Blake2b256(s :+ a) // Alice's commitment

val fullGameEnv = Map(
ScriptNameProp -> "fullGameScriptEnv",
"alice" -> alicePubKey,
"h" -> h
"h" -> Colls.fromArray(h)
)

val fullGameScript = mkTestErgoTree(compile(fullGameEnv,
@@ -73,9 +73,8 @@ class XorGameExampleSpecification extends CompilerTestingCommons
).asSigmaProp)

val halfGameEnv = Map(
ScriptNameProp -> "halfGameScript",
"alice" -> alicePubKey,
"fullGameScriptHash" -> Blake2b256(fullGameScript.bytes)
"fullGameScriptHash" -> Colls.fromArray(Blake2b256(fullGameScript.bytes))
)

// Note that below script allows Alice to spend the half-game output anytime before Bob spends it.