Preserve exact localized payment amounts - #107
Open
Jim8y wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new amount parser accepts unbounded-length input from app links/QR, which can lead to excessive allocations/CPU (DoS) unless a reasonable max-length guard is added.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR hardens payment amount handling so protocol-provided amounts are preserved as invariant, ungrouped strings through app-link/QR parsing and only localized at the Send form boundary, avoiding culture-sensitive decimal conversions and precision loss.
Changes:
- Introduces
TokenAmountto format/parse token-unit amounts viaBigIntegerwith culture-aware decimal separators (no grouping, no scientific notation). - Updates
PaymentAction,ScanPage, andSendPageto carry payment-link amounts as strings until token precision is known, then validate/convert to exact chain units for submission and bounds checks. - Adds a dedicated P2-02 regression test project covering locale behavior, precision limits, and real app-link parsing/navigation.
File summaries
| File | Description |
|---|---|
| tests/P2-02/TokenAmountTests.cs | Adds unit tests for formatting/parsing across locales and precision/bounds edge cases. |
| tests/P2-02/TokenAmount.Tests.csproj | Introduces standalone test project linking production parsing/link code for regression coverage. |
| tests/P2-02/README.md | Documents rationale, scope, and how to run the P2-02 regression suite. |
| tests/P2-02/PaymentPlatformStubs.cs | Provides minimal navigation/platform doubles so linked app-link code can run in tests. |
| tests/P2-02/PaymentActionTests.cs | Verifies payment URIs preserve protocol digits and reject ambiguous/localized inputs. |
| OneGateApp/Services/TokenAmount.cs | Adds exact BigInteger-based formatter/parser with culture-specific decimal separator support. |
| OneGateApp/Pages/SendPage.xaml.cs | Switches amount input to string + exact unit parsing/validation for All/bounds/submission. |
| OneGateApp/Pages/SendPage.xaml | Binds amount entry to AmountText and removes decimal Range validator. |
| OneGateApp/Pages/ScanPage.xaml.cs | Escapes amount when constructing navigation query to preserve exact digits safely. |
| OneGateApp/Models/AppLinks/PaymentAction.cs | Stores amount as invariant string and validates invariant dot-decimal syntax. |
| OneGateApp.slnx | Adds the new P2-02 test project to the solution. |
Review details
- Files reviewed: 11/11 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+20
to
+24
| units = BigInteger.Zero; | ||
| if (string.IsNullOrWhiteSpace(text)) return false; | ||
| culture ??= CultureInfo.CurrentCulture; | ||
| string[] parts = text.Trim().Split(culture.NumberFormat.NumberDecimalSeparator, StringSplitOptions.None); | ||
| if (parts.Length > 2) return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Payment amounts were parsed through culture-sensitive
decimalvalues in app links and through inconsistent parsers in the send form. A dot-decimal payment link could change value in a comma-decimal locale, and large/high-precision token amounts could be rounded or rejected prematurely.Change
BigIntegertoken units.BigIntegerparsing. This also covers payment-link/QR amounts routed throughPaymentAction, while preserving valid values at the boundary and exact 60-decimal-place amounts.This independent PR addresses audit P2-02 only, based on master
623603d.Validation
dotnet test tests/P2-02/TokenAmount.Tests.csproj --no-restore --nologo: 42 regression tests passed, including real PaymentAction/AppLinkAction parsing. The original link-entry regressions failed with the culture-dependent implementation; five follow-up cases failed before the early length guard was added.1.5links, amounts beyond decimal precision, exact 60-decimal-place values, minimum units, excessive precision, zero/over-balance input, and the full-balance action. On both platforms, the actual Entry binds a valid 1024-character amount, rejects 1025/16384-character values, and the production PaymentAction/AppLinkAction path rejects overlong amounts.0fa066d30f9fd58875501db9a4ce72ad85a41b98aaf715fce41624678a00c121relative to the original PR headfbcfd07df28ae55acaeadcb0f6dab3ae07c87bcb.Screenshots, native result JSON and simulator-only fixture code remain outside the repository.
Limits
The early guard bounds the amount parser's numeric work and intermediate allocations; it does not bound parsing of an entire incoming URI, which occurs before amount validation. Native checks used synthetic balances and direct production controls/models, not a camera scan or an on-chain transfer. No uploaded screenshots, hosted CI success, or combined validation with other audit branches is claimed.