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

ZIR-181: Add Elliptic Curve BigInt circuits #41

Merged
merged 67 commits into from
Oct 2, 2024
Merged

Conversation

tzerrell
Copy link
Member

@tzerrell tzerrell commented Sep 24, 2024

Adds Elliptic Curve functions/ZKRs based on the BigInt dialect, with operations for verifying add/sub/neg/mul/double plus point equality and verifying point on curve. Includes curve parameters for secp256k1 as well as a tiny custom curve for testing purposes.

This represents curves as Weierstrass curves and points in affine coordinates. This is good for fast computations in our particular case, but does preclude representing the zero point or calculations involving it, causing some minor incompleteness (which is typically cryptographically irrelevant). Due to the lack of control flow in the recursion circuit, this is slightly more incomplete than similar systems, particularly in multiply, where if a zero would be computed when multiplying by a scalar that differs from the actual scalar by a single bit, then the multiply can't go through (as both branches are computed and combined during the double-and-add algorithm). An alternative approach using an arbitrary offset point would allow people to avoid this problem in specific cases (by choosing a different arbitrary offset point), although the general problem would still exist (it's just in different places depending on the offset), and in that implementation this arbitrary offset must be provided to all multiplies, which did not seem like the best tradeoffs to me.

This produces a lot of ZKRs for unit testing. This can make compile/testing time a bit slow -- I've tried to trim them to achieve a good balance of testing perf & coverage, but I'm definitely open to suggestions for improvement here.

This includes @shkoo's work making compile times faster through BigInt macros (7b2e4bf)

Developed in conjunction with risc0/risc0#2371, which includes a test suite.

@tzerrell tzerrell requested review from shkoo and jbruestle September 24, 2024 20:48
@tzerrell tzerrell self-assigned this Sep 24, 2024
@github-actions github-actions bot changed the title Add Elliptic Curve BigInt circuits ZIR-181: Add Elliptic Curve BigInt circuits Sep 24, 2024
Copy link
Contributor

@shkoo shkoo left a comment

Choose a reason for hiding this comment

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

Can't speak to the math stuff, but the rest looks good!

@tzerrell tzerrell enabled auto-merge (squash) October 2, 2024 17:11
Commit rebased with updated message to mollify GitHub signed commit verifier
@tzerrell tzerrell force-pushed the tzerrell/bigint-ec-mul branch from 0e26472 to e774c4a Compare October 2, 2024 20:13
@tzerrell
Copy link
Member Author

tzerrell commented Oct 2, 2024

(I force-pushed the last few commits to mollify the verified-commit checker. No changes to the code in these new commits)

@tzerrell tzerrell merged commit e06f7c4 into main Oct 2, 2024
8 checks passed
@tzerrell tzerrell deleted the tzerrell/bigint-ec-mul branch October 2, 2024 20:53
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.

2 participants