-
Notifications
You must be signed in to change notification settings - Fork 14
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
tests: NAF and splitK in crypto.secp256k1.curve #74
Conversation
Bah, dataclasses were introduced in Python 3.7 . Shall I use a standard class or a dictionary? It's just a few lines in a test. EDIT: another possibility is to add the EDIT2: alas, Poetry won't install I'll use a dictionary. |
@@ -210,10 +210,10 @@ def splitK(self, k): | |||
# being a bottleneck. | |||
# c1 = round(b2 * k / n) from step 4. | |||
# Rounding isn't really necessary and costs too much, hence skipped | |||
c1 = (self.b2 + k) // self.N | |||
c1 = (self.b2 * k) // self.N |
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.
This (and the similar one below) is a bugfix: the original Go code has a bigInt.Mul here, and tests fail without this change.
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.
Weird that we never hit an issue with this with signature verification. Hmmm.
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.
Wish I understood all this math.
I won't claim I understand it either. I did have a quick look at the algorithms in the book mentioned in the Go code, but most of the work is translating the Go code and tests anyway. |
@@ -210,10 +210,10 @@ def splitK(self, k): | |||
# being a bottleneck. | |||
# c1 = round(b2 * k / n) from step 4. | |||
# Rounding isn't really necessary and costs too much, hence skipped | |||
c1 = (self.b2 + k) // self.N | |||
c1 = (self.b2 * k) // self.N |
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.
Weird that we never hit an issue with this with signature verification. Hmmm.
decred/decred/util/helpers.py
Outdated
return 0 | ||
|
||
|
||
random.seed(0) |
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.
Can't set the random seed in production code. I'm hesitant to add any functions here that are just for tests. How about a test utilities module somewhere?
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.
Can't set the random seed in production code. I'm hesitant to add any functions here that are just for tests.
Makes sense.
How about a test utilities module somewhere?
Test code does not live in packages and modules. Test discovery is performed by pytest according to its own rules. For cases like this, pytest offers fixtures, I'll change randBytes
and sign
as such.
The remaining question is whether setting the seed should be done in the fixture or in the test that uses it: I lean towards the latter.
- test helpers "randBytes" and "sign" removed from util/helpers.py and moved to a conftest.py file in the tests/ root directory, as pytest fixtures; - test_curve.py changed to use the new fixtures; - unit/util/test_database.py restored to its original state.
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.
Looks great.
Part of #70.
Converted the
crypto.secp256k1.curve
unit tests to pytest format.Added tests for
NAF
andsplitK
incrypto.secp256k1.curve
, and fixed a double bug insplitK
.Moved
randBytes
toutil.helpers
and added asign
function (that Python unfortunately lacks).Changed
curve.lamda
tocurve.lambda_
(trailing underscores are the usual Python convention for avoiding name conflicts).