fix(bitcore-lib): normalize elliptic BN in ECDSA.sign#4144
fix(bitcore-lib): normalize elliptic BN in ECDSA.sign#4144wqy000wqy wants to merge 1 commit intobitpay:masterfrom
Conversation
|
The only failing check appears to be
The failure is Since this PR only changes |
|
@wqy000wqy Thanks for the PR. You'll need to sign your commits before this can be merged - see CONTRIBUTING.md |
57216f0 to
06fced9
Compare
06fced9 to
84cae99
Compare
|
I checked the existing issues before opening this PR. This appears to be related to #3883, which describes broader compatibility problems around bitcore's BN/Point abstractions and their interaction with underlying I reproduced the problem against the latest This PR is intended as a minimal, focused fix for the concrete failure in I have also updated the PR with a signed commit, and the latest commit is now marked as |
Summary
This fixes an assertion failure in
bitcore-libECDSA.sign()that can happen in bundled environments wherebitcore-libandellipticend up using differentbn.jsinstances.Root cause
ECDSA.sign()computes:In some bundled runtimes:
Q.xcomes fromellipticNcomes from bitcore's BN wrapperEven though both are BN-like values, they are not guaranteed to be compatible for direct arithmetic across instances, which can trigger internal assertions.
Fix
Normalize the elliptic coordinate through bytes before modular arithmetic:
Q.xis produced byelliptic, while the subsequent arithmetic uses bitcore's BN wrapper. Normalizing through bytes preserves the math while avoiding cross-instance BN operations.Validation
test/crypto/ecdsa.jsnpx mocha test/crypto/ecdsa.jsnpx mocha test/message.js