-
Notifications
You must be signed in to change notification settings - Fork 1k
Don't mutate the elliptic curve prototype with get* additions #238
base: master
Are you sure you want to change the base?
Conversation
Point's prototype is set to the prototype of ec('secp256k1').curve.point(), which means mutation to it is shared across users of 'elliptic' via the in-memory representation of those objects. This is not generally a problem, for example, with `validate` it's a simple set, so the greatest risk is that it will be directly overwritten. But in the case of `getX` and `getY`, both methods are overwritten with others that depend on the prior implementation as stored in `_get*`. If this happens twice, then the implementation of `_getX` is replaced with something that depends on a call to `_getX`, and the callers is stuck in an infinite loop.
I would like to also remove the
|
I also tried adding an intermediate object into the prototype chain, by wrapping
|
Hi, thanks a lot for the insight. I think I have hit this problem before when bundling bitcore-lib and bitcore-lib-cash on the same JS using webpack. we will review the PR soon. Thanks again! |
Greate improvement, thank you, @Empact! Currently using of |
I think the same should also apply to bn.js I hope all other forks merge this one rapidly. |
Yeah, ideally we should make upstream libraries completely isolated / independent. Could do that by using composition instead of inheritance. |
Yes,
Definitely agree. These implementations should be done in an isolated
module where it exposes the same methods from main libraries and also
provides its own new methods, something like a wrapper.
The only drawback with the mentioned solution is that a lot of places in
bitcore-lib should change to use new module instead of main ec and bn.
…On Sat, 20 Oct 2018, 03:42 Ben Woosley, ***@***.***> wrote:
Yeah, ideally we should make upstream libraries completely isolated /
independent. Could do that by using composition instead of inheritance.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#238 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGbOZEV8JAJhYFBWdl6K8Dt2MdJ5145Gks5ummp7gaJpZM4TwgQq>
.
|
Point's prototype is set to the prototype of
ec('secp256k1').curve.point()
, which means the library itself is global state, and mutation to it is shared across users of 'elliptic'.This is not generally a problem, for example, with
validate
it's a simple set, so the greatest risk is that it will be directly overwritten.But in the case of
getX
andgetY
, both methods are overwritten with others that depend on the prior implementation as stored in_get*
. If this happens twice, then the implementation of_getX
is replaced with something that depends on a call to_getX
, and the callers is stuck in an infinite loop.Here's an example of the infinite loop, which I came across by interaction between bitcore-lib-dash and zcash-bitcore-lib, but by inspection it seems they are both downstream of this code.