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: validation and handling of unsafe integers #3491

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

petertonysmith94
Copy link
Contributor

@petertonysmith94 petertonysmith94 commented Dec 19, 2024

Release notes

In this release, we:

  • Improved validation and handling of unsafe integers in BigNumberCoder

Summary

  • Any number bigger than Number.MAX_SAFE_INTEGER, encoded using the BigNumber coder, could lead to malformed data. We should ensure that the numbers of MAX_SAFE_INTEGER are encoded correctly and throw an error when attempting to handle a number more than this value.

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@petertonysmith94 petertonysmith94 added the bug Issue is a bug label Dec 19, 2024
@petertonysmith94 petertonysmith94 self-assigned this Dec 19, 2024
Copy link

vercel bot commented Dec 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
fuels-template ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 23, 2024 10:01am
ts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 23, 2024 10:01am
ts-docs-api ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 23, 2024 10:01am

Copy link

codspeed-hq bot commented Dec 19, 2024

CodSpeed Performance Report

Merging #3491 will degrade performances by 20.27%

Comparing ps/fix/issue-with-big-numbers (b68944c) with master (41c72fb)

Summary

❌ 1 regressions
✅ 17 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark master ps/fix/issue-with-big-numbers Change
should successfully conduct a custom transfer between wallets (x20 times) 50.3 ms 63.1 ms -20.27%

Dhaiwat10
Dhaiwat10 previously approved these changes Dec 21, 2024
arboleya
arboleya previously approved these changes Dec 23, 2024
.changeset/orange-moles-leave.md Outdated Show resolved Hide resolved
@petertonysmith94 petertonysmith94 changed the title fix: handling very large numbers gracefully fix: validation and handling of unsafe integers Dec 23, 2024
const value: number = 76472027892439376;

expect(() => coder.encode(value)).toThrow(
new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid u64 type - number value is too large.')
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid u64 type - number value is too large.')
new FuelError(ErrorCode.ENCODE_ERROR, 'Invalid u64 type - too large. Number can only safely handle up to 53 bits').

JW if it needs more detail

Copy link
Contributor

Coverage Report:

Lines Branches Functions Statements
76.33%(+0%) 69.88%(+0.04%) 74.2%(+0%) 76.34%(+0%)
Changed Files:

Coverage values did not change👌.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle large number values gracefully
4 participants