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

crypto: ser/de update and use nonrecoverable sig for secp256k1/r1 #7423

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Jan 16, 2023

What Changed

  • For CLI and SDK, a ECDSA k1 signature is produced using the nonrecoverable form. This means the signature is 64 bytes instead of 65.
  • The signature verification in sui also uses the nonrecoverable option. A valid signature should have 64 bytes.
  • For wallet, since only Ed25519 is supported, the secp256k1 change should not affect.
  • Also exposes secp256k1_verify and secp256k1_verify_recoverable API in move.
  • Ser/de of public keys and signatures now uses the most compact serialization with ToFromBytes.

What Do You Need To Do

  • If you are using SDK to produce a Secp256k1 signature, no change is needed as long as you are using the latest version.
  • If you are using something else to produce a signature, your old signature will not be considered valid. You should just need to remove the last byte (65->64 bytes) to make it a valid signature again.

Next:

@vercel
Copy link

vercel bot commented Jan 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
explorer ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 30, 2023 at 4:32PM (UTC)
frenemies ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 30, 2023 at 4:32PM (UTC)
wallet-adapter ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 30, 2023 at 4:32PM (UTC)
1 Ignored Deployment
Name Status Preview Comments Updated
explorer-storybook ⬜️ Ignored (Inspect) Jan 30, 2023 at 4:32PM (UTC)

@joyqvq joyqvq force-pushed the updatefc branch 3 times, most recently from 1e7ce5c to 27bea1b Compare January 26, 2023 17:48
@joyqvq joyqvq changed the title chore: Update fastcrypto crypto: ser/de update and use nonrecoverable sig for secp256k1/r1 Jan 26, 2023
@vercel vercel bot temporarily deployed to Preview – wallet-adapter January 26, 2023 17:49 Inactive
@vercel vercel bot temporarily deployed to Preview – frenemies January 26, 2023 17:50 Inactive
@joyqvq joyqvq marked this pull request as ready for review January 26, 2023 21:22
@vercel vercel bot temporarily deployed to Preview – wallet-adapter January 26, 2023 21:23 Inactive
@vercel vercel bot temporarily deployed to Preview – frenemies January 26, 2023 21:23 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter January 26, 2023 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – frenemies January 26, 2023 21:27 Inactive
@MystenLabs MystenLabs deleted a comment from 2000090144 Jan 26, 2023
Err(_) => return Ok(NativeResult::ok(cost, smallvec![Value::bool(false)])),
};

match public_key.verify_hashed(&hashed_msg_ref, &signature) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified a bit:

let result = public_key.verify_hashed(&hashed_msg_ref, &signature).is_ok();
Ok(NativeResult::ok(cost, smallvec![Value::bool(result)]))`

@jonas-lj
Copy link
Contributor

Looks good to me!

@@ -0,0 +1,68 @@
// Copyright (c) Mysten Labs, Inc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this test to e2e since it needs to get api version to decide which signing function to use

@@ -44,7 +44,9 @@ export class Account {
async sign(data: Base64DataBuffer): Promise<SignaturePubkeyPair> {
return {
signatureScheme: this.#keypair.getKeyScheme(),
signature: this.#keypair.signData(data),
// TODO(joyqvq): Remove once 0.25.0 is released.
// This is fine to hardcode useRecoverable = false because wallet does not support Secp256k1. Ed25519 does not use this parameter.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @pchrysochoidis this will be removed after 0.25.0 is released

@vercel vercel bot temporarily deployed to Preview – frenemies January 30, 2023 16:31 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-adapter January 30, 2023 16:31 Inactive
@joyqvq joyqvq merged commit 21781ba into main Jan 30, 2023
@joyqvq joyqvq deleted the updatefc branch January 30, 2023 17:13
williampsmith pushed a commit that referenced this pull request Feb 3, 2023
)

## What Changed

- For CLI and SDK, a ECDSA k1 and r1 signature is produced using the
nonrecoverable form. This means the signature is 64 bytes instead of 65.
- The signature verification in sui also uses the nonrecoverable option.
A valid signature should have 64 bytes.
- For wallet, since only Ed25519 is supported, the secp256k1 change
should not affect.
- Also exposes secp256k1_verify and secp256k1_verify_recoverable API in
move.
- Ser/de of public keys and signatures now uses the most compact
serialization with ToFromBytes.

## What Do You Need To Do
- If you are using SDK to produce a Secp256k1 signature, no change is
needed as long as you are using the latest version.
- If you are using something else to produce a signature, your old
signature will not be considered valid. You should just need to remove
the last byte (65->64 bytes) to make it a valid signature again.

Next:
- r1 verify and verify_recoverable added in
#7773
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants