Skip to content

[MEDIUM] BigInt-to-Number precision loss in display formatting across 5 files #2324

Description

@v1ktorrr0x

Severity: Medium

Source

Multiple files:

  • useLpPositions.ts:213: Number(lpBalanceRaw)
  • DepositWithdrawPanel.tsx:253: Number(previewShares)
  • LpPositionDashboard.tsx:48,53,144: Number(userRedeemableValue), Number(vaultBalance), Number(redemptionRateE6)
  • PositionsDock.tsx:181: Number(pnlTokens)

Description

Number(bigint) silently loses precision for values exceeding Number.MAX_SAFE_INTEGER (~9e15). For USDC (6 decimals) this is safe up to ~9 billion USD. For tokens with 9+ decimals, the safe range shrinks to ~9 million. The conversions produce wrong display values with no indication of precision loss.

At current playground TVL levels this is cosmetic, but there is no precision awareness anywhere in the codebase.

Fix

For amounts that could theoretically exceed the safe range, compute with BigInt arithmetic and convert to Number only at the final display step with explicit documentation of the safe ceiling. At minimum, add a sentinel guard: if the value exceeds Number.MAX_SAFE_INTEGER, display a truncation indicator rather than a wrong number.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions