-
Notifications
You must be signed in to change notification settings - Fork 75
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
feat: transaction with CONTRACT_NEGATIVE_VALUE
breaks some routes
#3387
Open
natanasow
wants to merge
6
commits into
main
Choose a base branch
from
3367-transaction-with-contract-negative-value-breaks-routes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bde9a91
chore: handle contract negative value calls
natanasow ec6dc59
chore: remove .only
natanasow 48ce0a3
chore: fix comments
natanasow c17f02a
chore: edit imports
natanasow 5e9e1b1
chore: resolving comments
natanasow fa9f894
chore: fix json parsing
natanasow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: do we expect
number
bigger than53
bits? so it's not automatically coerced to double https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGERThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I don't know how often it will happen but we definitely must handle values bigger than
Number.MAX_SAFE_INTEGER
.The max Int64 positive value is
0x7fffffffffffffff
which has 63 "usable" bits.That's why we always convert the incoming value to BigInt here 👇
Hope that makes sense or am I wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm, I'm not sure that
BigInt(input.toString())
works as expected wheninput
being anumber
uses more than53
bits. Saybut the difference should be zero, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, the difference should be zero. Nice catch 👏 and thank you. That's something I must add more unit tests tomorrow.
Here are some more quick tests, it seems that
.toString()
messed things up, also using a shadow conversion like postfixingn
doesn't seem to work as expected.Do you have an idea how this can be completely fixed? I think removing
.toString()
is enough but that will be confirmed when I push the unit tests covering wide-bit range numbers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is with
number
altogether.The only way I see to proper fix it completely would be to not use
number
, and usebigint
everywhere for values that areint64
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Will try to refactor it in an elegant way and once I'm done will ping you again for review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @acuarica,
Richard Moore has the same thoughts as you ethers-io/ethers.js#452 (comment). Today I managed to resolve it but what do you think about the implementation?
What I've done:
JSON.parse
where the number will be rounded and lost foreverHere are the two mainnet transactions I tested with:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the advantage of using
json-bigint
overbigint
? Only parsing? doesn'tbigint
already comes with parsing capabilities?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json-bigint
is doingJSONBigInt.parse(data)
but under the hood, it transforms numeric values tobigint
instead of JS Number.If we're doing
JSON.parse()
and then manually transforming numeric values to bigint,JSON.parse()
already rounded the number and we lost it.json-bigint
doesn't replacebigint
and they are not correlated.json-bigint
is used instead ofJSON.parse()
due to its capability of converting string json input directly tobigint
instead of JS Number.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification.