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 generate now can't throw exception #160

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

vird
Copy link

@vird vird commented Nov 2, 2021

Based on: fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
Probability of throw was ~1/2**499
But after fix it should never throw

@holgerd77
Copy link
Member

Hi there, thanks for the PR! 🙂

Could you please give some more context and explain what you are doing here?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 85.036% when pulling 6ee26f6 on vird:fix/generate_now_cant_throw_exception into 83c1b1a on ethereumjs:master.

@vird
Copy link
Author

vird commented Nov 4, 2021

randomBytes(32) is used in current implementation of .generate() for generating new wallet. But this is not 100% correct way to properly generate ECDSA point for private key. My fix allows code to be formally correct and never throw exception (even with astronomically low probability)

src/index.ts Outdated
}
} catch (ignoreError) {
// Do not crash
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation.

Can we update here that only this specific error is ignored and all other errors rethrown? Otherwise all other errors will get hidden with this implementation.

Also: can you add a test case which would fail before the change and pass afterwards?

Copy link
Author

Choose a reason for hiding this comment

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

I made better implementation, but it's almost impossible to mock randomBytes. Because randombytes module uses
module.exports = require('crypto').randomBytes
this implementation. So mocking crypto.randomBytes will have no effect, mocking result of require is impossible (or I don't know how to do that), and mocking whole require is kinda overkill

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

3 participants