Skip to content

fix(drive): add bounds check for i64 cast in token balance addition#3295

Merged
QuantumExplorer merged 1 commit into
v3.1-devfrom
fix/token-balance-i64-truncation
Mar 15, 2026
Merged

fix(drive): add bounds check for i64 cast in token balance addition#3295
QuantumExplorer merged 1 commit into
v3.1-devfrom
fix/token-balance-i64-truncation

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Summary

  • Add i64 bounds check before cast in token balance checked_add path
  • The insert path already has this check but the add path was missing it

Issue

Security audit found that balance_to_add as i64 in the add-to-existing-balance path has no bounds check. Values above i64::MAX silently wrap to negative, potentially producing incorrect balance results. The insert path correctly checks balance_to_add > i64::MAX as u64.

Test plan

  • Test verifies error on balance_to_add > i64::MAX
  • Test verifies normal additions work
  • cargo test passes
  • cargo clippy clean

🤖 Generated with Claude Code

The add-to-existing-balance path was missing a bounds check before
casting balance_to_add from u64 to i64. Values above i64::MAX would
silently wrap to negative, potentially producing incorrect balance
results. The insert path already had this check but the add path
was missing it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@QuantumExplorer has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c8502fb-ddee-4bc1-abf7-20eca22ef7ca

📥 Commits

Reviewing files that changed from the base of the PR and between 658d02d and 591213f.

📒 Files selected for processing (1)
  • packages/rs-drive/src/drive/tokens/balance/add_to_previous_token_balance/v0/mod.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/token-balance-i64-truncation
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added this to the v3.1.0 milestone Mar 15, 2026
@codecov

codecov Bot commented Mar 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.50549% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.32%. Comparing base (658d02d) to head (591213f).
⚠️ Report is 21 commits behind head on v3.1-dev.

Files with missing lines Patch % Lines
...ns/balance/add_to_previous_token_balance/v0/mod.rs 94.50% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           v3.1-dev    #3295      +/-   ##
============================================
- Coverage     70.42%   68.32%   -2.10%     
============================================
  Files          3293     3293              
  Lines        262598   262689      +91     
============================================
- Hits         184931   179487    -5444     
- Misses        77667    83202    +5535     
Components Coverage Δ
dpp 56.61% <ø> (-1.82%) ⬇️
drive 74.88% <94.50%> (-3.32%) ⬇️
drive-abci 81.44% <ø> (-1.49%) ⬇️
sdk 30.34% <ø> (-0.91%) ⬇️
dapi-client 39.08% <ø> (ø)
platform-version ∅ <ø> (∅)
platform-value 39.35% <ø> (ø)
platform-wallet 60.40% <ø> (ø)
drive-proof-verifier ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@QuantumExplorer QuantumExplorer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sure

@QuantumExplorer QuantumExplorer merged commit edf29c8 into v3.1-dev Mar 15, 2026
23 of 24 checks passed
@QuantumExplorer QuantumExplorer deleted the fix/token-balance-i64-truncation branch March 15, 2026 15:54
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.

1 participant