Skip to content

refactor: hash to curve #674

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

Merged
merged 16 commits into from
Apr 15, 2025
Merged

refactor: hash to curve #674

merged 16 commits into from
Apr 15, 2025

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Apr 7, 2025

Description

This PR exposes the primitive methods of hash-to-curve so that it can be implemented in gnark. Also separated the code generation into separate method.

Kept the current public methods intact, so it is fully backwards compatible.

Type of change

  • refactor

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ivokub ivokub self-assigned this Apr 7, 2025
@ivokub ivokub added the cleanup Suggestion to clean up the code label Apr 7, 2025
@ivokub ivokub requested a review from Copilot April 7, 2025 12:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 71 out of 71 changed files in this pull request and generated no comments.

@ivokub
Copy link
Collaborator Author

ivokub commented Apr 7, 2025

Currently not yet ready, I'll confirm it would also be useful for map to G2 in gnark.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 71 out of 71 changed files in this pull request and generated no comments.

@ivokub ivokub marked this pull request as ready for review April 9, 2025 22:53
@ivokub
Copy link
Collaborator Author

ivokub commented Apr 9, 2025

@ThomasPiellard, @Tabaie - ready for review now.

Copy link
Contributor

@Tabaie Tabaie left a comment

Choose a reason for hiding this comment

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

I don't think it makes a lot of sense to have hash_to_curve source files in both packages. imo every hash to curve function should be moved to the new package and only add a few wrappers to the root package, thus removing hash_to_g{{i}}.go from the root package. This way we can avoid making all those internal functions public as well.

@ivokub
Copy link
Collaborator Author

ivokub commented Apr 11, 2025

I don't think it makes a lot of sense to have hash_to_curve source files in both packages. imo every hash to curve function should be moved to the new package and only add a few wrappers to the root package, thus removing hash_to_g{{i}}.go from the root package. This way we can avoid making all those internal functions public as well.

The goal of the PR is to make some internal things public so that we can reuse in gnark:

  • isogeny map coefficients
  • isogenous curve coefficients
  • sqrtRatio method
  • clear cofactor method (for tests)

For the MapToG, MapToCurve, EncodeToG and HashToG, I tried moving them to the hash_to_curve package, but it resulted in import cycle, as it depends on G1Affine and G1Jac, so root package would import hash_to_curve which would then import root package again.

For the Isogeny methods I overcame that by working directly with the point coordinates. I could have done it also for MapToG, MapToCurve and EncodeToG, but as HashToG explicitly depends on curve arithmetic, then I cannot use only the coordinates. And if I need to keep HashToG in the root package, then it also made sense to keep rest.

@ivokub ivokub requested review from Tabaie and removed request for Tabaie and ThomasPiellard April 11, 2025 14:37
@ivokub ivokub marked this pull request as draft April 11, 2025 14:41
@ivokub ivokub force-pushed the refactor/hash_to_curve branch 2 times, most recently from 98b60e1 to c7145fa Compare April 13, 2025 22:38
@ivokub ivokub requested a review from Tabaie April 13, 2025 22:51
@ivokub ivokub marked this pull request as ready for review April 13, 2025 22:51
@ivokub ivokub requested a review from ThomasPiellard April 13, 2025 22:51
@ivokub ivokub force-pushed the refactor/hash_to_curve branch from c7145fa to 6b6896c Compare April 13, 2025 23:30
Copy link
Contributor

@Tabaie Tabaie left a comment

Choose a reason for hiding this comment

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

Thanks looks good

@ivokub ivokub merged commit c838dcd into master Apr 15, 2025
5 checks passed
@ivokub ivokub deleted the refactor/hash_to_curve branch April 15, 2025 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Suggestion to clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants