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

chore(crypto): add publickey verification #3974

Merged
merged 2 commits into from
Aug 25, 2020
Merged

Conversation

sleepdefic1t
Copy link
Contributor

Summary

Current master/develop only checks for valid hex during PublicKey validation, but does not verify the correctness of a publicKey.

This can lead to the unexpected creation of an unaccessible but technically-"valid" Address.

This PR recommends the following:

  • add a verify method to class PublicKey using the already-present secp256k1 module
  • modify Address.fromPublicKey to drop hex-validation in favor of PublicKey.verify
  • modify PublicKey.fromMultiSignatureAsset to drop hex-validation in favor of PublicKey.verify
  • add relevant unit-tests

Checklist

  • Tests
  • Ready to be merged

Additional Comments

  • No change of import modules needed
  • maintains resolution of circular-dep fixes in c84b976

There are other areas that would benefit from the PublicKey.verify method; however, no additional checks are being added at this time.

It should also be stated that a developer should use this new method whenever:

  • the correctness of a publicKey cannot be guaranteed
  • the publicKey is NOT already being checked (.verify(sig, pubKey, msg))

## Summary

Current master/develop only checks for valid hex during PublicKey validation, but does not verify the correctness of a publicKey.

This can lead to the unexpected creation of an unaccessable but technically-"valid" Address.

This PR recommends the following:
- add a 'verify' method to 'class PublicKey' using the already-present 'secp256k1' module
- modify 'Address.fromPublicKey' to drop hex-validation in favor of 'PublicKey.verify'
- add relevant unit-tests

## Additional Comments

- No change of import modules needed
- maintains resolution of circular-dep fixes in c84b976

There are other areas thay would benefit from the 'PublicKey.verify' method; however, no additional checks are being added at this time.

It should also be stated that a developer should use this new method whenever:
- the correctness of a publicKey cannot be guaranteed
- the publicKey is NOT already being checked (`.verify(sig, pubKey, msg)`)
@codecov
Copy link

codecov bot commented Aug 22, 2020

Codecov Report

Merging #3974 into develop will decrease coverage by 1.75%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3974      +/-   ##
===========================================
- Coverage    97.44%   95.69%   -1.76%     
===========================================
  Files          631      631              
  Lines        14582    14582              
  Branches      1734     1734              
===========================================
- Hits         14210    13954     -256     
- Misses         181      437     +256     
  Partials       191      191              
Flag Coverage Δ
#functional ?
#integration 9.88% <ø> (ø)
#unit 95.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/migrations/20190307000000-drop-wallets-table.ts 0.00% <0.00%> (-100.00%) ⬇️
...c/migrations/20180305200000-create-rounds-table.ts 0.00% <0.00%> (-100.00%) ⬇️
...c/migrations/20180305300000-create-blocks-table.ts 0.00% <0.00%> (-100.00%) ⬇️
.../migrations/20180305100000-create-wallets-table.ts 0.00% <0.00%> (-100.00%) ⬇️
...igrations/20190626000000-enforce-chained-blocks.ts 0.00% <0.00%> (-100.00%) ⬇️
...rations/20191003000000-migrate-vendor-field-hex.ts 0.00% <0.00%> (-100.00%) ⬇️
...ations/20180305400000-create-transactions-table.ts 0.00% <0.00%> (-100.00%) ⬇️
.../20190718000000-check_previous_block-add-schema.ts 0.00% <0.00%> (-100.00%) ⬇️
...20190619000000-drop-id-column-from-rounds-table.ts 0.00% <0.00%> (-100.00%) ⬇️
...81204200000-add-timestamp-index-to-blocks-table.ts 0.00% <0.00%> (-100.00%) ⬇️
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f8727b...ef58d52. Read the comment docs.

Use valid publicKeys to resolve failing tests after adding PKV.
@sleepdefic1t
Copy link
Contributor Author

@air1one @faustbrian

No idea what's up with functional/htlc-lock tests step:10:208, doesn't appear to be anything I touched.

@air1one air1one merged commit 4408899 into develop Aug 25, 2020
@ghost ghost deleted the chore(crypto)/add-pkv branch August 25, 2020 12:42
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.

None yet

2 participants