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 signature recovery and Ed25519 verification #486

Merged
merged 19 commits into from
Jul 12, 2023
Merged

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented Jun 12, 2023

Closes #464 and FuelLabs/fuel-specs#484.

This PR also removes the apparently unused Keystore and Signer traits from fuel-crypto.

The PR creates some technical debt: ed25519-dalek crate is near it's 2.0 release, and once that's released, we should update to it. Also, secp256r1 signing (that isn't used by any instruction currently) is somewhat inefficient due to limitations of the p256 crate, and that must be addressed if we're going to have opcodes for doing ec signatures.

@Dentosal Dentosal added breaking A breaking api change fuel-vm Related to the `fuel-vm` crate. labels Jun 12, 2023
@Dentosal Dentosal self-assigned this Jun 12, 2023
@Dentosal Dentosal changed the title Secp256r1 signature recovery Secp256r1 signature recovery and Ed25519 verification Jun 13, 2023
@Dentosal Dentosal requested a review from a team June 19, 2023 01:15
@Dentosal Dentosal marked this pull request as ready for review June 19, 2023 01:15
fuel-crypto/src/secp256r1.rs Outdated Show resolved Hide resolved

let signature = signature.normalize_s().unwrap_or(signature);

// TODO: this is a hack to get the recovery id. The signature should be normalized
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, we can create an issue in their repository to support normalized signatures. Even we can try to propose a change for it=)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I can make a PR to support that. However, it's not really blocking this PR since the version used here works, and the VM doesn't use this function so there is not performance penaly for now. I'm simply uncertain whether we're going to end up using this library for the signatures. If we end up adding more EC opcodes as proposed in the spec issue, we're likely going to write our own EC library anyway.

b: Word,
c: Word,
) -> Result<(), RuntimeError> {
let pub_key = Bytes32::from(read_bytes(memory, a)?);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is sad that ed25519 can't recover pub_key. It affects our API(two curves recover the pub key return it into register a, but here we need to get it from the user)=(

Copy link
Member

Choose a reason for hiding this comment

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

On the other hand, having the public key readily available during signature verification enables efficient batch verification (while it is impossible to do batch recovery).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't find it any more sad than division by zero existing. We cannot alter reality to match our APIs. We just have to make sure the documentation is clear about the API differences.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's just the nature of the curve.

fuel-crypto/src/ed25519.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,33 @@
//! ED25519 signature verification

Copy link
Member

Choose a reason for hiding this comment

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

should we rexport the dalek lib, (maybe even under test-helpers)? That way applications using ed25519 don't have to worry about importing the correct version of dalek or pontentially compiling it twice.

@xgreenx xgreenx added this pull request to the merge queue Jul 12, 2023
Merged via the queue into master with commit 6a3964a Jul 12, 2023
@xgreenx xgreenx deleted the dento/secp256r1 branch July 12, 2023 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking api change fuel-vm Related to the `fuel-vm` crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement ED25519 and Secp256r1
4 participants