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

fix: ECDSA and ED25519 public key mismatch when you get it from mnemonic #2451

Merged
merged 8 commits into from
Aug 9, 2024

Conversation

ivaylonikolov7
Copy link
Contributor

@ivaylonikolov7 ivaylonikolov7 commented Aug 7, 2024

Description:

This PR modifies the crypto package and in particular the ECDSA and ED25519 private key classes. A user found out that a mnemonic and a key that share the same private key mismatch their public key. In order to fix it, this PR modifies the ECDSA and ED25519 so they don't add trailing zeroes. This addition only happens only when the private key is shorter than 32 bytes. Example: 3030020100300706052b8104000a04220420a5b9dedc7c7767c4a88a0ac3cc6b9171948bada579226bd550d3342db11dc800

The last 2 trailing zeroes should be added after the DER prefix bytes (3030020100300706052b8104000a04220420)
e.g 3030020100300706052b8104000a0422042000a5b9dedc7c7767c4a88a0ac3cc6b9171948bada579226bd550d3342db11dc8

Fixes

#2419

Notes for reviewer:
Not sure if 100 tests are enough of a stress test but otherwise the test gets slow. For example 10000 iterations take around 15 seconds per test case. Considering there is 4 of these per file, thats gonna take 2 minute in total which in my opiion is a lot.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
@ivaylonikolov7 ivaylonikolov7 self-assigned this Aug 7, 2024
@ivaylonikolov7 ivaylonikolov7 added this to the v2.50.0 milestone Aug 7, 2024
Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
@ivaylonikolov7 ivaylonikolov7 marked this pull request as ready for review August 7, 2024 12:06
@ivaylonikolov7 ivaylonikolov7 requested review from a team as code owners August 7, 2024 12:06
@svetoslav-nikol0v svetoslav-nikol0v removed the request for review from rwalworth August 7, 2024 13:33
test/unit/EcdsaPrivateKey.js Outdated Show resolved Hide resolved
test/unit/EcdsaPrivateKey.js Outdated Show resolved Hide resolved
test/unit/EcdsaPrivateKey.js Outdated Show resolved Hide resolved
test/unit/EcdsaPrivateKey.js Outdated Show resolved Hide resolved
test/unit/Ed25519PrivateKey.js Outdated Show resolved Hide resolved
test/unit/Ed25519PrivateKey.js Outdated Show resolved Hide resolved
test/unit/Ed25519PrivateKey.js Outdated Show resolved Hide resolved
test/unit/Ed25519PrivateKey.js Outdated Show resolved Hide resolved
test/unit/Ed25519PrivateKey.js Outdated Show resolved Hide resolved
Copy link

sonarcloud bot commented Aug 9, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
69.3% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

Copy link
Contributor

@agadzhalov agadzhalov left a comment

Choose a reason for hiding this comment

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

LGTM

@ivaylonikolov7 ivaylonikolov7 merged commit 856b8c2 into main Aug 9, 2024
6 of 7 checks passed
@ivaylonikolov7 ivaylonikolov7 deleted the fix/mnemonics-from-string-mismatch branch August 9, 2024 10:34
This was referenced Aug 12, 2024
ivaylogarnev-limechain pushed a commit that referenced this pull request Aug 22, 2024
…nic (#2451)

* fix: ecdsa public key mismatch when converting from mnemonic

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* fix: ed25519 public key mismatch when converting from mnemonic

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* refactor: add privatekey offset variable for better naming

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* feat(test): update stress test count

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* fix(test): remove await when unnecessary

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

* fix(tests): add timeout on beforeEach test so it has enough time

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>

---------

Signed-off-by: Ivaylo Nikolov <ivaylo.nikolov@limechain.tech>
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.

Mnemonics -> ECDSA key -> ECDSA key doesn't yield same public key
4 participants