Skip to content

feat: validate token decimals during create_vault#592

Merged
1nonlypiece merged 3 commits into
Disciplr-Org:mainfrom
dextro172-ui:feat/token-decimals-validation
Jun 2, 2026
Merged

feat: validate token decimals during create_vault#592
1nonlypiece merged 3 commits into
Disciplr-Org:mainfrom
dextro172-ui:feat/token-decimals-validation

Conversation

@dextro172-ui
Copy link
Copy Markdown

Closes #491

Add token_decimals validation in create_vault rejecting tokens with unsupported decimals in accountability_vault.

Changes:

  • Add Error::UnsupportedTokenDecimals (error code 400)
  • Add MIN_TOKEN_DECIMALS=0 and MAX_TOKEN_DECIMALS=18 constants
  • Query token::Client::decimals() during create_vault
  • Reject tokens whose decimals fall outside [0, 18]
  • Cache validated decimals in persistent storage (TokenDecimals key)
  • Add get_token_decimals() query function
  • Add 6 unit tests covering:
    • Valid decimals: 0, 7, 17, 18 (boundary tests)
    • Invalid decimals: 19, 255 (rejection tests)
    • Decimals NOT cached on rejection
  • Document the bound and rationale in contracts/README.md
  • Document fixed-decimals assumption in src/services/soroban.ts

Rationale:

Add token_decimals validation in create_vault rejecting tokens with
unsupported decimals in accountability_vault.

Changes:
- Add Error::UnsupportedTokenDecimals (error code 400)
- Add MIN_TOKEN_DECIMALS=0 and MAX_TOKEN_DECIMALS=18 constants
- Query token::Client::decimals() during create_vault
- Reject tokens whose decimals fall outside [0, 18]
- Cache validated decimals in persistent storage (TokenDecimals key)
- Add get_token_decimals() query function
- Add 6 unit tests covering:
  * Valid decimals: 0, 7, 17, 18 (boundary tests)
  * Invalid decimals: 19, 255 (rejection tests)
  * Decimals NOT cached on rejection
- Document the bound and rationale in contracts/README.md
- Document fixed-decimals assumption in src/services/soroban.ts

Rationale:
- Backend src/services/soroban.ts assumes fixed decimals contract
- JavaScript Number (IEEE 754) loses precision above ~15 digits
- Stellar ecosystem standardizes on 7 decimals
- ERC-20 caps at 18 decimals
- Prevents overflow attacks with extreme decimal values
Refs: Disciplr-Org#491
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@dextro172-ui Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@1nonlypiece 1nonlypiece merged commit 64591c1 into Disciplr-Org:main Jun 2, 2026
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.

Add token_decimals validation in create_vault rejecting tokens with unsupported decimals in accountability_vault

3 participants