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

Secp256r1 support #1983

Merged
merged 44 commits into from
Mar 12, 2024
Merged

Secp256r1 support #1983

merged 44 commits into from
Mar 12, 2024

Conversation

maurolacy
Copy link
Contributor

@maurolacy maurolacy commented Jan 7, 2024

Completes the work done in #1877, which is in turn a follow-up of #1083.

  • Rebased from main.
  • Added test vectors.
  • Reorganised the code a bit for generality.
  • Added support for secp256r1_recover_pubkey.
  • Added secp256r1_verify endpoint / tests to crypto-verify.
  • Fixed lints / made CI pass.

@maurolacy maurolacy enabled auto-merge (rebase) January 8, 2024 11:32
@maurolacy maurolacy requested a review from uint January 8, 2024 21:14
@webmaster128 webmaster128 disabled auto-merge January 9, 2024 19:40
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Very nice, thank you. I did not do a full review yet but will follow up.

Some high level questions:

  • Who needs this implementation for what? I was planning to add it to 2.1 to be prepared for passkey apps.
  • Don't we need pubkey recovery here?
  • I was thinking not requiring low-S signatures in secp256k1 by default was a mistake as all modern blockchain applications require low-S. Right now in CosmWasm you have to check low-S yourself in the contract if your protocol needs it. Maybe it's a good opportunity to make a better decision here. Any thoughts?

packages/std/src/results/mod.rs Outdated Show resolved Hide resolved
packages/vm/src/environment.rs Outdated Show resolved Hide resolved
packages/vm/src/modules/mod.rs Outdated Show resolved Hide resolved
packages/vm/src/wasm_backend/mod.rs Outdated Show resolved Hide resolved
@maurolacy
Copy link
Contributor Author

maurolacy commented Jan 9, 2024

  • Who needs this implementation for what? I was planning to add it to 2.1 to be prepared for passkey apps.

I just saw the pending / partial long standing PR and decided to jump in.

  • Don't we need pubkey recovery here?

Will take a look. Seen some comments about lack of recovery for this, but that may be wrong.

  • I was thinking not requiring low-S signatures in secp256k1 by default was a mistake as all modern blockchain applications require low-S. Right now in CosmWasm you have to check low-S yourself in the contract if your protocol needs it. Maybe it's a good opportunity to make a better decision here. Any thoughts?

I think there's a normalisation step related to that. Do you want to fail in case of high S?

@maurolacy maurolacy force-pushed the secp256r1-support branch 2 times, most recently from 13abb59 to 442c163 Compare January 9, 2024 23:10
@webmaster128
Copy link
Member

I think there's a normalisation step related to that. Do you want to fail in case of high S?

For non-Ethereum and non-Bitcoin ECDSA, high S is perfectly valid. It's really up to the application to limit it. This is why we accept both in secp256k1_verify. The comments in https://twitter.com/simon_warta/status/1744814900164059555 are also not really convincing me to change it.

Maybe it is better to just create a secp256k1_verify_strict and secp256r1_verify_strict later on.

@maurolacy
Copy link
Contributor Author

maurolacy commented Jan 10, 2024

  • Don't we need pubkey recovery here?

Will take a look. Seen some comments about lack of recovery for this, but that may be wrong.

Added to the crypto package. Will work in the rest (imports / mappings) later.

@maurolacy maurolacy force-pushed the secp256r1-support branch 3 times, most recently from ed59b75 to 3d7970f Compare January 20, 2024 09:52
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Nice work, thanks a lot!

Befor the final merge, we should ensure this new API works for Passkeys. I am asking around how to best find test vectors for that.

packages/std/src/errors/std_error.rs Outdated Show resolved Hide resolved
packages/vm/src/environment.rs Show resolved Hide resolved
packages/vm/src/modules/mod.rs Outdated Show resolved Hide resolved
packages/vm/src/wasm_backend/mod.rs Outdated Show resolved Hide resolved
@webmaster128 webmaster128 mentioned this pull request Jan 23, 2024
13 tasks
Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

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

Thank you for this nice work!

@webmaster128 webmaster128 merged commit f214b92 into main Mar 12, 2024
5 of 27 checks passed
@webmaster128 webmaster128 deleted the secp256r1-support branch March 12, 2024 10:50
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.

3 participants