-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.0.0] Conversion from Long-encoded nBits representation to BigInt and back #962
base: v6.0.0
Are you sure you want to change the base?
Conversation
@kushti, I suggest to add these operations as methods of SGlobal (i.e. in SGlobalMethods) |
moved, also, the PR is finalized now, please review. If you think anything is not tested, please specify what exactly, and so I will be able to add tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, the most important tests are those in LanguageSpecification, more specifically using verifyCases method.
When they are done, not only full coverage is ensured, but also cost profiling can be done.
I suggest to test these new operations as two separate property()
@@ -695,6 +695,20 @@ trait SigmaDslBuilder { | |||
*/ | |||
def groupGenerator: GroupElement | |||
|
|||
/** | |||
* @return big integer provided as input approximately encoded using NBits, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit confusing comment, says "@return big integer" while the actual return type is Long.
groupGeneratorMethod, | ||
xorMethod | ||
) | ||
private lazy val EnDecodeNBitsCost = FixedCost(JitCost(5)) // the same cost for nbits encoding and decoding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cost is too low. And encoding is cheaper than decoding (because of array creation).
There is a profiler in LSV5 (see the comments and afterAll method).
I suggest at least 2 for encoding and 40 for decoding.
@@ -175,6 +176,14 @@ class CSigmaDslBuilder extends SigmaDslBuilder { dsl => | |||
|
|||
override def groupGenerator: GroupElement = _generatorElement | |||
|
|||
def encodeNbits(bi: BigInt): Long = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override
missing
In this PR, two new methods, Global.encodeNbits() and Global.decodeNbits() are introduced, to support conversion from NBits-encoded numbers to big integers and back
Among new tests Bitcoin PoW check example can be found.
close #675
TODO: en/decodeNBits likely should work with UnsignedBigInt , which will be done in UnsignedBigInt PR, or during merging this into v6.0.0 with UnsignedBigInt impl being merged, depending on merging order