This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
fix(core): fix decimal string IntOrHex parsing #2359
Merged
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.
Motivation
Previously, we would parse decimal strings like
"100000"
as hex, because they did not match a rawserde_json::Number
variant inIntOrHex
. This caused problems when parsing genesis fields withfrom_int_or_hex
, for example:This would parse
"1000000000000000000000000000"
instead as0x1000000000000000000000000000
.This did not fail
U256
parsing because itsFromStr
implementation accepts both0x
-prefixed and non-0x
-prefixed strings, and will deserialize both as hex.Solution
Check for
0x
prefixes infrom_int_or_hex
andfrom_u64_or_hex
if the value matches aString
instead ofserde_json::Number
. If there is a prefix, deserialize as hex. Otherwise, the value deserializes as a decimal string.Tests are added for the failing
Genesis
alloc, and unit tests for thefrom_int_or_hex
method itself are added.PR Checklist