Skip to content

Commit

Permalink
raising costs for encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
kushti committed Nov 18, 2024
1 parent e374229 commit eb50ab4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions core/shared/src/main/scala/sigma/SigmaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ trait SigmaDslBuilder {
def groupGenerator: GroupElement

/**
* @return big integer provided as input approximately encoded using NBits,
* @return NBits-encoded approximate representation of given big integer,
* see (https://bitcoin.stackexchange.com/questions/57184/what-does-the-nbits-value-represent)
* for format details
* for NBits format details
*/
def encodeNbits(bi: BigInt): Long

Expand Down
8 changes: 5 additions & 3 deletions data/shared/src/main/scala/sigma/ast/methods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1845,15 +1845,17 @@ case object SGlobalMethods extends MonoTypeMethods {
"Decode a number from big endian bytes.",
ArgInfo("first", "Bytes which are big-endian encoded number."))

private lazy val EnDecodeNBitsCost = FixedCost(JitCost(5)) // the same cost for nbits encoding and decoding
private lazy val EncodeNBitsCost = FixedCost(JitCost(25)) // the same cost for nbits encoding and decoding

private lazy val DecodeNBitsCost = FixedCost(JitCost(50)) // the same cost for nbits encoding and decoding

lazy val encodeNBitsMethod: SMethod = SMethod(
this, "encodeNbits", SFunc(Array(SGlobal, SBigInt), SLong), 6, EnDecodeNBitsCost)
this, "encodeNbits", SFunc(Array(SGlobal, SBigInt), SLong), 6, EncodeNBitsCost)
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "Encode big integer number as nbits", ArgInfo("bigInt", "Big integer"))

lazy val decodeNBitsMethod: SMethod = SMethod(
this, "decodeNbits", SFunc(Array(SGlobal, SLong), SBigInt), 7, EnDecodeNBitsCost)
this, "decodeNbits", SFunc(Array(SGlobal, SLong), SBigInt), 7, DecodeNBitsCost)
.withIRInfo(MethodCallIrBuilder)
.withInfo(MethodCall, "Decode nbits-encoded big integer number", ArgInfo("nbits", "NBits-encoded argument"))

Expand Down

0 comments on commit eb50ab4

Please sign in to comment.