Skip to content
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

Add sage script for generating scalar_split_lambda constants #852

Merged

Conversation

real-or-random
Copy link
Contributor

 * Move curve parameters to separate file
 * Rename main prover script for clarity
@roconnor-blockstream
Copy link
Contributor

I recommend trying LLL to replace find_split_constants_explicit_tof.

Add/replace the BETA and LAMBDA assertions with an assertion that the value is a root of X^2 + X + 1.

@real-or-random real-or-random force-pushed the 202011-sage-split-lambda branch 2 times, most recently from 7f2238f to 5b316a8 Compare November 25, 2020 15:24
@real-or-random
Copy link
Contributor Author

real-or-random commented Nov 25, 2020

I recommend trying LLL to replace find_split_constants_explicit_tof.

I think the current one is more instructive... I don't know, I don't want to spend a lot of time on this.

I added root assumptions for BETA and LAMBDA.

@real-or-random real-or-random force-pushed the 202011-sage-split-lambda branch from 5b316a8 to 0854198 Compare November 25, 2020 15:29
@roconnor-blockstream
Copy link
Contributor

I'm not really familiar with sage, and I haven't tested this PR, but it is okay by me.

@roconnor-blockstream
Copy link
Contributor

roconnor-blockstream commented Nov 27, 2020

Another check to add is that lambda*P = <beta*P.x, y>. Checking for P := G is probably sufficient. The point is that the two roots of X^2+X+1 in Zn and Zp need to be matched up in accordance to the group operation on the secp256k1 curve. e.g. all the current assertions would pass if BETA were replaced by BETA^2.

(It will also be the case that all the assertions would pass if both LAMBDA and BETA were replaced with LAMBDA^2 and BETA^2, but there is no helping that because that would be a valid, but different, implementation.)

@real-or-random real-or-random force-pushed the 202011-sage-split-lambda branch from 0854198 to 4e4158e Compare December 2, 2020 17:01
@real-or-random
Copy link
Contributor Author

I addressed all of your comments.

while True:
if inf_norm(v2) < inf_norm(v1):
v1, v2 = v2, v1
m = round( (v1[0]*v2[0] + v1[1]*v2[1]) // inf_norm(v1)**2 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to round anymore with //.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought / vs // is just a python2 compatibility thing but I think what you had in mind is to avoid floating-point arithmetic. But this changed the semantics.

The correct thing is to round (to the nearest int) and not floor (for a reason), so that's why I used / and round instead of //. (It just happens that the output is the same for our specific input.)

So I now changed this to a version which

  • rounds to the nearest integer (what the textbooks do TM [1]),
  • relies integer arithmetic instead of floating-point arithmetic, and
  • should work in Python 2 and Python 3 because it does not use /.

[1] https://en.wikipedia.org/wiki/Lattice_reduction#In_two_dimensions Ok not a book but you get the point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saying, you could delete the whole thing and call LLL where all this has been worked out.

@sipa
Copy link
Contributor

sipa commented Dec 2, 2020

Looks good, ACK 4e4158e

@real-or-random real-or-random force-pushed the 202011-sage-split-lambda branch from 4e4158e to 329a2e0 Compare December 3, 2020 10:56
@sipa
Copy link
Contributor

sipa commented Dec 4, 2020

ACK 329a2e0

CI failure is unrelated.

@jonasnick jonasnick merged commit 2d9e717 into bitcoin-core:master Dec 7, 2020
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Apr 8, 2021
…ants

Summary: Backport of [[bitcoin-core/secp256k1#852 | secp256k1#852]]

Test Plan:
  sage gen_split_lambda_constants.sage

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D9377
deadalnix pushed a commit to Bitcoin-ABC/secp256k1 that referenced this pull request Apr 9, 2021
…ants

Summary: Backport of [[bitcoin-core/secp256k1#852 | secp256k1#852]]

Test Plan:
  sage gen_split_lambda_constants.sage

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D9377
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants