-
Notifications
You must be signed in to change notification settings - Fork 153
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 serious issue in .toString(16)
#295
Conversation
The hex encoding of some numbers is wrong. Since the string representation is also used for interoperability between BigInt libraries, this bug is causing a number modification when a BN.js number is converted into another BigInt class, for example the BigNumber of ethers.js.
FYI, I have confirmed this issue. @indutny Would you have an idea of when you would be able to get to this? I am debating including a hack to fix this temporarily into ethers if you don’t have time to get to it. :) |
@alexdupre thanks for the fix. Can you explain what's wrong with current code and how moving |
The issue is present when these conditions are true:
In this case the |
Make sense, thanks. |
If you are 100% sure that the fix is correct, then I think it should be released as |
I think changes are correct but it would be great if somebody except @ricmoo confirmed that everything is correct. |
FWIW I think this may be a good candidate for a property-based testing methodology (it'd be interesting to know if it would have spotted this issue as well). |
Any update? |
Thank you for the reminder! Published as |
@fanatid Could I bug you to also get the version in |
Only @indutny can do this :/ |
Fixes correctness bug for .toString(16): indutny/bn.js#295 ethers-io/ethers.js#3017
Fixes correctness bug: indutny/bn.js#295
Fixes correctness bug for .toString(16): indutny/bn.js#295 ethers-io/ethers.js#3017
Could this be backported to v4? |
Hey need help getting it out
Sent from Yahoo Mail for iPhone
On Friday, November 8, 2024, 7:38 AM, Nikita Skovoroda ***@***.***> wrote:
Could this be backported to v4?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
* Add test for `.toString(16)` * Fix serious issue in `.toString(16)` The hex encoding of some numbers is wrong. Since the string representation is also used for interoperability between BigInt libraries, this bug is causing a number modification when a BN.js number is converted into another BigInt class, for example the BigNumber of ethers.js.
published as 4.12.1, thanks @ChALkeR! |
In some circumstances the hex encoding of big numbers is wrong. In addition to a display issue, given that the the hex string if often used as an intermediate representation in transport/conversion scenarios, the re-constructed big number can actually change its value, creating serious issues.