Skip to content

Commit

Permalink
first pow check test
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed May 26, 2024
1 parent c8d75cd commit c9d0889
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ case object SLongMethods extends SNumericTypeMethods {
override def ownerType: SMonoType = SLong

lazy val DecodeNBitsMethod: SMethod = SMethod(
this, "DecodeNBits", SFunc(this.ownerType, SBigInt), 8, FixedCost(JitCost(5)))
this, "decodeNbits", SFunc(this.ownerType, SBigInt), 8, FixedCost(JitCost(5)))
.withInfo(PropertyCall, "Consider this Long value as nbits-encoded BigInt value and decode it to BigInt")

protected override def getMethods(): Seq[SMethod] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sigmastate.utxo

import org.ergoplatform.ErgoBox.{AdditionalRegisters, R6, R8}
import org.ergoplatform._
import scorex.util.encode.Base16
import sigma.Extensions.ArrayOps
import sigma.ast.SCollection.SByteArray
import sigma.ast.SType.AnyOps
Expand Down Expand Up @@ -157,6 +158,45 @@ class BasicOpsSpecification extends CompilerTestingCommons
)
}

property("checking Bitcoin PoW") {
val h = "00000020a82ff9c62e69a6cbed277b7f2a9ac9da3c7133a59a6305000000000000000000f6cd5708a6ba38d8501502b5b4e5b93627e8dcc9bd13991894c6e04ade262aa99582815c505b2e17479a751b"
val customExt = Map(
1.toByte -> ByteArrayConstant(Base16.decode(h).get)
).toSeq

test("Prop1", env, customExt,
"""{
| def reverse4(bytes: Coll[Byte]): Coll[Byte] = {
| Coll(bytes(3), bytes(2), bytes(1), bytes(0))
| }
|
| def reverse32(bytes: Coll[Byte]): Coll[Byte] = {
| Coll(bytes(31), bytes(30), bytes(29), bytes(28), bytes(27), bytes(26), bytes(25), bytes(24),
| bytes(23), bytes(22), bytes(21), bytes(20), bytes(19), bytes(18), bytes(17), bytes(16),
| bytes(15), bytes(14), bytes(13), bytes(12), bytes(11), bytes(10), bytes(9), bytes(8),
| bytes(7), bytes(6), bytes(5), bytes(4), bytes(3), bytes(2), bytes(1), bytes(0))
| }
|
| val bitcoinHeader = getVar[Coll[Byte]](1).get
| val id = reverse32(sha256(sha256(bitcoinHeader)))
| val hit = byteArrayToBigInt(id)
|
| val nBitsBytes = reverse4(bitcoinHeader.slice(72, 76))
|
| val pad = Coll[Byte](0.toByte, 0.toByte, 0.toByte, 0.toByte)
|
| val nbits = byteArrayToLong(pad ++ nBitsBytes)
|
| val difficulty = nbits.decodeNbits
|
| hit < 500000000000L
|}
|""".stripMargin,
propExp = null,
testExceededCost = false
)
}

property("Relation operations") {
test("R1", env, ext,
"{ allOf(Coll(getVar[Boolean](trueVar).get, true, true)) }",
Expand Down

0 comments on commit c9d0889

Please sign in to comment.