From 7fdcdbd8c80ac6a386dd93dea6b9928b4b1db7a1 Mon Sep 17 00:00:00 2001 From: Alexander Chepurnoy Date: Mon, 11 Nov 2024 23:02:46 +0300 Subject: [PATCH] more tests for shiftLeft/shiftRight --- .../utxo/BasicOpsSpecification.scala | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala index ae34c5bbf..f7a9fab2b 100644 --- a/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/utxo/BasicOpsSpecification.scala @@ -1171,6 +1171,39 @@ class BasicOpsSpecification extends CompilerTestingCommons } } + property("UnsignedBigInt.shiftLeft over limits") { + def shiftLeftTest(): Assertion = test("UnsignedBigInt.shiftLeft", env, ext, + s"""{ + | val x = unsignedBigInt("${CryptoConstants.groupOrder}") + | x.shiftLeft(1) > x + |}""".stripMargin, + null + ) + + if (VersionContext.current.isV6SoftForkActivated) { + an[ArithmeticException] shouldBe thrownBy(shiftLeftTest()) + } else { + an[sigma.validation.ValidationException] shouldBe thrownBy(shiftLeftTest()) + } + } + + + property("UnsignedBigInt.shiftLeft - neg shift") { + def shiftLeftTest(): Assertion = test("UnsignedBigInt.shiftLeft", env, ext, + s"""{ + | val x = unsignedBigInt("${CryptoConstants.groupOrder}") + | x.shiftLeft(-1) > x + |}""".stripMargin, + null + ) + + if (VersionContext.current.isV6SoftForkActivated) { + an[java.lang.IllegalArgumentException] shouldBe thrownBy(shiftLeftTest()) + } else { + an[sigma.validation.ValidationException] shouldBe thrownBy(shiftLeftTest()) + } + } + property("BigInt.shiftLeft over limits") { def shiftLeftTest(): Assertion = test("BigInt.shiftLeft", env, ext, s"""{ @@ -1327,6 +1360,24 @@ class BasicOpsSpecification extends CompilerTestingCommons } } + property("UnsignedBigInt.shiftRight - neg shift") { + def shiftRightTest(): Assertion = test("UnsignedBigInt.shiftRight", env, ext, + s"""{ + | val x = unsignedBigInt("${CryptoConstants.groupOrder.divide(new BigInteger("2"))}") + | val y = -2 + | val z = unsignedBigInt("${CryptoConstants.groupOrder.divide(new BigInteger("8"))}") + | z.shiftRight(y) == x + |}""".stripMargin, + null + ) + + if (VersionContext.current.isV6SoftForkActivated) { + an[java.lang.IllegalArgumentException] shouldBe thrownBy(shiftRightTest()) + } else { + an[sigma.validation.ValidationException] shouldBe thrownBy(shiftRightTest()) + } + } + property("getVarFromInput - invalid var") { def getVarTest(): Assertion = { val customExt = Map(