diff --git a/data/shared/src/main/scala/sigma/ast/SMethod.scala b/data/shared/src/main/scala/sigma/ast/SMethod.scala index 669625ef1e..7179bdfc84 100644 --- a/data/shared/src/main/scala/sigma/ast/SMethod.scala +++ b/data/shared/src/main/scala/sigma/ast/SMethod.scala @@ -298,7 +298,7 @@ object SMethod { * @return an instance of [[SMethod]] which may contain generic type variables in the * signature (see SMethod.stype). As a result `specializeFor` is called by * deserializer to obtain monomorphic method descriptor. - * @consensus this is method is used in [[sigmastate.serialization.MethodCallSerializer]] + * @consensus this is method is used in [[sigma.serialization.MethodCallSerializer]] * `parse` method and hence it is part of consensus protocol */ def fromIds(typeId: Byte, methodId: Byte): SMethod = { diff --git a/data/shared/src/main/scala/sigma/ast/methods.scala b/data/shared/src/main/scala/sigma/ast/methods.scala index 41814dd108..2f99b1f4cd 100644 --- a/data/shared/src/main/scala/sigma/ast/methods.scala +++ b/data/shared/src/main/scala/sigma/ast/methods.scala @@ -1512,21 +1512,23 @@ case object SGlobalMethods extends MonoTypeMethods { .withInfo(Xor, "Byte-wise XOR of two collections of bytes", ArgInfo("left", "left operand"), ArgInfo("right", "right operand")) + private def powHitCostKind = PerItemCost(baseCost = JitCost(10), perChunkCost = JitCost(10), chunkSize = 128) + lazy val powHitMethod = SMethod( - this, "powHit", SFunc(Array(SGlobal, SInt, SByteArray, SByteArray, SByteArray, SInt), SBigInt), 3, GroupGenerator.costKind) // todo: cost + this, "powHit", SFunc(Array(SGlobal, SInt, SByteArray, SByteArray, SByteArray, SInt), SBigInt), 3, powHitCostKind) .withIRInfo(MethodCallIrBuilder) .withInfo(MethodCall, "Calculating Proof-of-Work hit (Autolykos 2 hash value) for custom Autolykos 2 function", ArgInfo("k", "k parameter of Autolykos 2 (number of inputs in k-sum problem)"), ArgInfo("msg", "Message to calculate Autolykos hash 2 for"), ArgInfo("nonce", "Nonce used to pad the message to get Proof-of-Work hash function output with desirable properties"), - ArgInfo("h", "PoW protocol specific padding (e.g. block height in Ergo)"), + ArgInfo("h", "PoW protocol specific padding for table uniqueness (e.g. block height in Ergo)"), ArgInfo("N", "Size of table filled with pseudo-random data to find k elements in"), ) def powHit_eval(mc: MethodCall, G: SigmaDslBuilder, k: Int, msg: Coll[Byte], nonce: Coll[Byte], h: Coll[Byte], N: Int) (implicit E: ErgoTreeEvaluator): BigInt = { - E.addSeqCost(Xor.costKind, msg.length, Xor.opDesc) { () => // todo: proper costing + E.addSeqCost(powHitCostKind, k * (msg.length + nonce.length + h.length), powHitMethod.opDesc) { () => CBigInt(Autolykos2PowValidation.hitForVersion2ForMessage(k, msg.toArray, nonce.toArray, h.toArray, N).bigInteger) } } diff --git a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala index ce78f1fa47..7bf43b8ada 100644 --- a/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala +++ b/sc/shared/src/test/scala/sigma/LanguageSpecificationV6.scala @@ -1,10 +1,13 @@ package sigma -import sigma.ast.{Apply, Downcast, FixedCost, FixedCostItem, FuncValue, GetVar, JitCost, OptionGet, SBigInt, SByte, SInt, SLong, SShort, ValUse} +import sigma.ast.SCollection.SByteArray +import sigma.ast.{Apply, BlockValue, Downcast, FixedCost, FixedCostItem, FuncValue, GetVar, Global, JitCost, MethodCall, OptionGet, SBigInt, SByte, SCollection, SGlobal, SGlobalMethods, SInt, SLong, SPair, SShort, SelectField, ValDef, ValUse, Value} import sigma.data.{CBigInt, ExactNumeric} import sigma.eval.SigmaDsl +import sigma.pow.Autolykos2PowValidation import sigma.util.Extensions.{BooleanOps, ByteOps, IntOps, LongOps} import sigmastate.exceptions.MethodNotFound +import sigma.BigIntRType import java.math.BigInteger import scala.util.Success @@ -115,10 +118,6 @@ class LanguageSpecificationV6 extends LanguageSpecificationBase { suite => } } - property("") { - - } - property("Int methods equivalence (new features)") { if (activatedVersionInTests < VersionContext.V6SoftForkVersion) { // NOTE, for such versions the new features are not supported