Skip to content

Commit

Permalink
more tests for shiftLeft/shiftRight
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 11, 2024
1 parent aa246c3 commit 7fdcdbd
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"""{
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7fdcdbd

Please sign in to comment.