-
Notifications
You must be signed in to change notification settings - Fork 397
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
curve.n missing _move method in proto #191
Comments
@indutny if you could take a look at this as well...? |
Does this happen during some API call? What's the test case? |
The minimal working example is as indicated in the original post. Indeed, Turns out that calling (As a workaround, you can always use |
In other words, the test case is var q = BN.red(curve.n)
var temp = new BN(1234).toRed(q)
temp.redNeg().redMul(temp) // shouldn't crash |
I think the problem is happening because elliptic uses bn.js@4 and you're using the latest bn.js . |
cc @fanatid @calvinmetcalf : should we update bn.js in elliptic? What issues could it cause in browserify-crypto? |
Problem is that new version of I started check modules which used by I also found that some package uses deprecated Buffer API ( |
@calvinmetcalf @indutny are you okay with updating bn.js everywhere to version 5? |
I'm more than happy with this, as long as there is a coordination with crypto-browserify. cc @jprichardson |
I'm in full support 👍 |
Great, I'll add it to my list. List of packages for update (in order for update):
`yarn why bn.js` output:=> Found "bn.js@4.11.8"
info Reasons this module exists
- "browserify#crypto-browserify#create-ecdh" depends on it
- Hoisted from "browserify#crypto-browserify#create-ecdh#bn.js"
- Hoisted from "browserify#crypto-browserify#diffie-hellman#bn.js"
- Hoisted from "browserify#crypto-browserify#public-encrypt#bn.js"
- Hoisted from "browserify#crypto-browserify#browserify-sign#bn.js"
- Hoisted from "browserify#crypto-browserify#diffie-hellman#miller-rabin#bn.js"
- Hoisted from "browserify#crypto-browserify#browserify-sign#browserify-rsa#bn.js"
- Hoisted from "browserify#crypto-browserify#browserify-sign#elliptic#bn.js"
- Hoisted from "browserify#crypto-browserify#browserify-sign#parse-asn1#asn1.js#bn.js" |
Another question before move on, because indutny/asn1.js#103 |
I think that it's not required, support for Node.js < 4.5 could be just dropped. |
hi all (@fanatid)—any update on this? thank you! |
Oh, I forgot about this issue during long vacation. I'll revisit it shortly and try make some progress. Sorry. |
great, thanks, please keep posted. |
Solve issues for using with old bn.js versions (<5.0.0). See details at: indutny/elliptic#191
I added extra function (which still called in |
Submitted PR's to all packages for update |
hi @fanatid sorry for the delay! it's a bit tricky to test this, because |
Solve issues for using with old bn.js versions (<5.0.0). See details at: indutny/elliptic#191
@benediamond I published bn.js@5.1.1 with workaround (indutny/bn.js#238). Should work now. |
@fanatid excellent! i can confirm that the issue is fixed. feel free to close. |
updates as per fix of indutny/elliptic#191. also a few other adjustments. thanks @ibudisteanu for noticing a naming inconsistency.
updates as per fix of indutny/elliptic#191. also a few other adjustments. thanks @ibudisteanu for noticing a naming inconsistency.
Found another issue related with different versions: const BN = require('bn.js') // 5.1.1
const EC = require('elliptic').ec // 6.5.2
const ec = new EC('secp256k1')
const ecparams = ec.curve
console.log(new BN(42).toRed(BN.red('k256')).redSqr())
console.log(new BN(42).toRed(ecparams.red).redSqr()) <BN-R: 6e4>
/home/kirill/tmp/node_modules/elliptic/node_modules/bn.js/lib/bn.js:2975
r.strip();
^
TypeError: r.strip is not a function
at K256.ireduce (/home/kirill/tmp/node_modules/elliptic/node_modules/bn.js/lib/bn.js:2975:9)
at Red.imod (/home/kirill/tmp/node_modules/elliptic/node_modules/bn.js/lib/bn.js:3147:39)
at Red.mul (/home/kirill/tmp/node_modules/elliptic/node_modules/bn.js/lib/bn.js:3211:17)
at Red.sqr (/home/kirill/tmp/node_modules/elliptic/node_modules/bn.js/lib/bn.js:3219:17)
at BN.redSqr (/home/kirill/tmp/node_modules/bn.js/lib/bn.js:2996:21)
at Object.<anonymous> (/home/kirill/tmp/bnjs-t.js:8:44)
at Module._compile (internal/modules/cjs/loader.js:1139:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
at Module.load (internal/modules/cjs/loader.js:988:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14) Related with indutny/bn.js#105 |
Hey I came here because I'm getting the r.strip error as well. FAIL tests/apis/ava/keychain.test.ts (5.154s)
AssetsKeyPair
✕ Creation Empty (403ms)
● AssetsKeyPair › Creation Empty
TypeError: r.strip is not a function
at K256.ireduce (node_modules/elliptic/node_modules/bn.js/lib/bn.js:2975:9)
at Red.imod (node_modules/elliptic/node_modules/bn.js/lib/bn.js:3147:39)
at Red.mul (node_modules/elliptic/node_modules/bn.js/lib/bn.js:3211:17)
at BN.redMul (node_modules/bn.js/lib/bn.js:2984:21)
at JPoint.eqXToP (node_modules/elliptic/lib/elliptic/curve/short.js:909:36)
at EC.verify (node_modules/elliptic/lib/elliptic/ec/index.js:191:12)
at AssetsKeyPair.verify (src/apis/ava/keychain.ts:2440:17)
at Object.<anonymous> (tests/apis/ava/keychain.test.ts:15:19) from code: /**
* Verifies that the private key associated with the provided public key produces the signature associated with the given message.
*
* @param msg The message associated with the signature
* @param sig The signature of the signed message
*
* @returns True on success, false on failure
*/
verify = (msg:Buffer, sig:Buffer):boolean => {
let sigObj:elliptic.ec.SignatureOptions = this._sigFromSigBuffer(sig);
return ec.verify(msg, sigObj, this.keypair);
}
/**
* @ignore
*/
protected _sigFromSigBuffer = (sig:Buffer):elliptic.ec.SignatureOptions => {
let r:BN = new BN(bintools.copyFrom(sig, 0, 32));
let s:BN = new BN(bintools.copyFrom(sig, 32, 64));
let recoveryParam:number = bintools.copyFrom(sig, 64, 65).readUIntBE(0, 1);
let sigOpt = {
r:r,
s:s,
recoveryParam:recoveryParam
};
return sigOpt;
} |
Hi @collincusce |
Thanks! Thoughts on using this library (which is a wrapper) instead? https://github.com/cryptocoinjs/secp256k1-node |
updates as per fix of indutny/elliptic#191. also a few other adjustments. thanks @ibudisteanu for noticing a naming inconsistency.
In short weierstrass curves, the member
curve.n
is missing_move
from its prototype:If
n
is then used to initialize a reduction context, callingredNeg
causes_move
to drop, which leads to crashes:and yet,
Here is the stacktrace:
This issue only happens when
bn.js
version v5.0.0 is used! elliptic version is 6.5.0. @fanatidThe text was updated successfully, but these errors were encountered: