Skip to content
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(dyn-abi): correctly parse uints in coerce_str #577

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

ay
Copy link
Contributor

@ay ay commented Mar 17, 2024

Motivation

When using coerce_str to parse a uint from a decimal number in non-wei units, precision is lost due to use of f64. For example, parsing 123456.123456789123456789 ether returns 123456123456789126578176 wei, but the correct value is 123456123456789123456789 wei.

Solution

I removed uses of f64, and all math is now done using U256 only. This also means std is no longer required when parsing decimal numbers with coerce_str.

I also added test cases that fail without this change.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@ay ay requested a review from prestwich as a code owner March 17, 2024 14:14
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

@DaniPopes DaniPopes merged commit 6ace151 into alloy-rs:main Mar 18, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants