diff --git a/core/shared/src/main/scala/sigma/SigmaDsl.scala b/core/shared/src/main/scala/sigma/SigmaDsl.scala index e2870a3c8..26fd0a749 100644 --- a/core/shared/src/main/scala/sigma/SigmaDsl.scala +++ b/core/shared/src/main/scala/sigma/SigmaDsl.scala @@ -977,7 +977,7 @@ trait SigmaDslBuilder { def xor(l: Coll[Byte], r: Coll[Byte]): Coll[Byte] /** Calculates value of a custom Autolykos 2 hash function */ - def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): BigInt + def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): UnsignedBigInt /** Deserializes provided `bytes` into a value of type `T`. **/ def deserializeTo[T](bytes: Coll[Byte])(implicit cT: RType[T]): T diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index a69654de7..469c2a4d4 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -16,8 +16,7 @@ import sigma.data.ExactIntegral.{ByteIsExactIntegral, IntIsExactIntegral, LongIs import sigma.data.NumericOps.BigIntIsExactIntegral import sigma.data.OverloadHack.Overloaded1 import sigma.data.UnsignedBigIntNumericOps.UnsignedBigIntIsExactIntegral -import sigma.data.{DataValueComparer, KeyValueColl, Nullable, RType, SigmaConstants} -import sigma.data.{CBigInt, DataValueComparer, KeyValueColl, Nullable, RType, SigmaConstants} +import sigma.data.{CBigInt, CUnsignedBigInt, DataValueComparer, KeyValueColl, Nullable, RType, SigmaConstants} import sigma.eval.{CostDetails, ErgoTreeEvaluator, TracedCost} import sigma.pow.Autolykos2PowValidation import sigma.reflection.RClass @@ -1944,7 +1943,7 @@ case object SGlobalMethods extends MonoTypeMethods { ArgInfo("left", "left operand"), ArgInfo("right", "right operand")) lazy val powHitMethod = SMethod( - this, "powHit", SFunc(Array(SGlobal, SInt, SByteArray, SByteArray, SByteArray, SInt), SBigInt), methodId = 8, + this, "powHit", SFunc(Array(SGlobal, SInt, SByteArray, SByteArray, SByteArray, SInt), SUnsignedBigInt), methodId = 8, PowHitCostKind) .withIRInfo(MethodCallIrBuilder) .withInfo(MethodCall, @@ -1957,10 +1956,10 @@ case object SGlobalMethods extends MonoTypeMethods { ) def powHit_eval(mc: MethodCall, G: SigmaDslBuilder, k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int) - (implicit E: ErgoTreeEvaluator): BigInt = { + (implicit E: ErgoTreeEvaluator): UnsignedBigInt = { val cost = PowHitCostKind.cost(k, msg, nonce, h) E.addCost(FixedCost(cost), powHitMethod.opDesc) - CBigInt(Autolykos2PowValidation.hitForVersion2ForMessageWithChecks(k, msg.toArray, nonce.toArray, h.toArray, N).bigInteger) + CUnsignedBigInt(Autolykos2PowValidation.hitForVersion2ForMessageWithChecks(k, msg.toArray, nonce.toArray, h.toArray, N).bigInteger) } private val deserializeCostKind = PerItemCost(baseCost = JitCost(30), perChunkCost = JitCost(20), chunkSize = 32) diff --git a/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala b/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala index 6e599a360..ebede0391 100644 --- a/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala +++ b/data/shared/src/main/scala/sigma/data/CSigmaDslBuilder.scala @@ -267,9 +267,9 @@ class CSigmaDslBuilder extends SigmaDslBuilder { dsl => Colls.fromArray(w.toBytes) } - override def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): BigInt = { + override def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): UnsignedBigInt = { val bi = Autolykos2PowValidation.hitForVersion2ForMessageWithChecks(k, msg.toArray, nonce.toArray, h.toArray, N) - this.BigInt(bi.bigInteger) + this.UnsignedBigInt(bi.bigInteger) } diff --git a/docs/LangSpec.md b/docs/LangSpec.md index 3f5453072..9468e4793 100644 --- a/docs/LangSpec.md +++ b/docs/LangSpec.md @@ -1053,7 +1053,7 @@ There are some functions which do not belong to other types, thus they put under * @param nonce - used to pad the message to get Proof-of-Work hash function output with desirable properties * @param h - PoW protocol specific padding for table uniqueness (e.g. block height in Ergo) */ - def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): BigInt + def powHit(k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int): UnsignedBigInt /** Deserializes provided `bytes` into a value of type `T`. **/ def deserializeTo[T](bytes: Coll[Byte])(implicit cT: RType[T]): T diff --git a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala index 52cc6af66..f80a244d0 100644 --- a/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala +++ b/interpreter/shared/src/test/scala/sigmastate/eval/BasicOpsTests.scala @@ -7,7 +7,7 @@ import scorex.util.encode.Base16 import sigma.Extensions.ArrayOps import sigma.ast.{ByteArrayConstant, IntConstant} import sigma.crypto.SecP256K1Group -import sigma.data.{CBigInt, TrivialProp} +import sigma.data.{CBigInt, CUnsignedBigInt, TrivialProp} import sigma.eval.SigmaDsl import sigma.util.Extensions.SigmaBooleanOps import sigma.util.NBitsUtils @@ -108,7 +108,7 @@ class BasicOpsTests extends AnyFunSuite with ContractsTestkit with Matchers { val hbs = Colls.fromArray(Base16.decode("00000000").get) val N = 1024 * 1024 - SigmaDsl.powHit(k, msg, nonce, hbs, N) shouldBe CBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344")) + SigmaDsl.powHit(k, msg, nonce, hbs, N) shouldBe CUnsignedBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344")) val es = CErgoTreeEvaluator.DefaultEvalSettings val accumulator = new CostAccumulator( @@ -129,9 +129,9 @@ class BasicOpsTests extends AnyFunSuite with ContractsTestkit with Matchers { val res = MethodCall(Global, SGlobalMethods.powHitMethod, IndexedSeq(IntConstant(k), ByteArrayConstant(msg), ByteArrayConstant(nonce), ByteArrayConstant(hbs), IntConstant(N)), Map.empty) - .evalTo[sigma.BigInt](Map.empty)(evaluator) + .evalTo[sigma.UnsignedBigInt](Map.empty)(evaluator) - res should be(CBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344"))) + res should be(CUnsignedBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344"))) } } diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala index 84c43f14d..c167e624c 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/SigmaDslUnit.scala @@ -135,7 +135,7 @@ import scalan._ def xor(l: Ref[Coll[Byte]], r: Ref[Coll[Byte]]): Ref[Coll[Byte]] def encodeNbits(bi: Ref[BigInt]): Ref[Long] def decodeNbits(l: Ref[Long]): Ref[BigInt] - def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[BigInt]; + def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[UnsignedBigInt]; def serialize[T](value: Ref[T]): Ref[Coll[Byte]] def fromBigEndianBytes[T](bytes: Ref[Coll[Byte]])(implicit cT: Elem[T]): Ref[T] def deserializeTo[T](bytes: Ref[Coll[Byte]])(implicit cT: Elem[T]): Ref[T] diff --git a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala index 695f50324..4abe309bd 100644 --- a/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala +++ b/sc/shared/src/main/scala/sigma/compiler/ir/wrappers/sigma/impl/SigmaDslImpl.scala @@ -2294,11 +2294,11 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { } - override def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[BigInt] = { - asRep[BigInt](mkMethodCall(self, + override def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[UnsignedBigInt] = { + asRep[UnsignedBigInt](mkMethodCall(self, SigmaDslBuilderClass.getMethod("powHit", classOf[Sym], classOf[Sym], classOf[Sym], classOf[Sym], classOf[Sym]), Array[AnyRef](k, msg, nonce, h, N), - true, false, element[BigInt])) + true, false, element[UnsignedBigInt](UnsignedBigInt.unsignedBigIntElement))) } override def encodeNbits(bi: Ref[BigInt]): Ref[Long] = { @@ -2474,11 +2474,11 @@ object SigmaDslBuilder extends EntityObject("SigmaDslBuilder") { true, true, element[Coll[Byte]])) } - def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[BigInt] = { - asRep[BigInt](mkMethodCall(source, + def powHit(k: Ref[Int], msg: Ref[Coll[Byte]], nonce: Ref[Coll[Byte]], h: Ref[Coll[Byte]], N: Ref[Int]): Ref[UnsignedBigInt] = { + asRep[UnsignedBigInt](mkMethodCall(source, SigmaDslBuilderClass.getMethod("powHit", classOf[Sym], classOf[Sym], classOf[Sym], classOf[Sym], classOf[Sym]), Array[AnyRef](k, msg, nonce, h, N), - true, true, element[BigInt])) + true, true, element[UnsignedBigInt](UnsignedBigInt.unsignedBigIntElement))) } def serialize[T](value: Ref[T]): Ref[Coll[Byte]] = { diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala index 29b78d0e9..b6e193de1 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala @@ -1468,12 +1468,12 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => } property("Global.powHit") { - def powHit: Feature[Coll[Byte], sigma.BigInt] = newFeature( + def powHit: Feature[Coll[Byte], sigma.UnsignedBigInt] = newFeature( { (x: Coll[Byte]) => val msg = x.slice(0, 7).toArray val nonce = x.slice(7, 15).toArray val h = x.slice(15, 19).toArray - CBigInt(Autolykos2PowValidation.hitForVersion2ForMessageWithChecks(32, msg, nonce, h, 1024 * 1024).bigInteger) + CUnsignedBigInt(Autolykos2PowValidation.hitForVersion2ForMessageWithChecks(32, msg, nonce, h, 1024 * 1024).bigInteger) }, "{ (x: Coll[Byte]) => val msg = x.slice(0,7); val nonce = x.slice(7,15); val h = x.slice(15,19); " + "Global.powHit(32, msg, nonce, h, 1024 * 1024) }", @@ -1499,7 +1499,7 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => val nonce = Base16.decode("000000000000002c").get val h = Base16.decode("00000000").get val x = Colls.fromArray(msg ++ nonce ++ h) - val hit = CBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344")) + val hit = CUnsignedBigInt(new BigInteger("326674862673836209462483453386286740270338859283019276168539876024851191344")) verifyCases( Seq( diff --git a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala index 4075ec5d7..275882f66 100644 --- a/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala +++ b/sc/shared/src/test/scala/sigmastate/TestingInterpreterSpecification.scala @@ -345,7 +345,7 @@ class TestingInterpreterSpecification extends CompilerTestingCommons val source = """ |{ - | val b: BigInt = bigInt("1157920892373161954235709850086879078528375642790749043826051631415181614943") + | val b = unsignedBigInt("1157920892373161954235709850086879078528375642790749043826051631415181614943") | val k = 32 | val N = 1024 * 1024 | val msg = fromBase16("0a101b8c6a4f2e")