Skip to content

fix: canonicalize SOL amounts as lamports - #16

Open
newmattock wants to merge 2 commits into
FeeeeelixWong:mainfrom
newmattock:codex/canonical-lamports
Open

fix: canonicalize SOL amounts as lamports#16
newmattock wants to merge 2 commits into
FeeeeelixWong:mainfrom
newmattock:codex/canonical-lamports

Conversation

@newmattock

@newmattock newmattock commented Aug 9, 2026

Copy link
Copy Markdown

What changed

Related to #1. This PR makes the SOL amount path canonical and fail-closed:

  • Adds a strict decimal-SOL parser with exact lamport conversion.
  • Rejects scientific notation, zero/negative values, surrounding whitespace, sub-lamport precision, non-canonical serialized lamports, and unsafe transaction ranges.
  • Uses the same lamport integer for policy caps, daily accounting, approval fingerprints, receipts, and SystemProgram.transfer.
  • Validates non-blocked Solana receipts and documents the serialized representation while preserving verification of legacy v1 amountSol receipts.
  • Adds deterministic parser, arithmetic, policy, receipt, and UI-safe display coverage.

The blocked invalid-amount receipt path is preserved and rendered as Invalid amount instead of crashing the local app.

Validation

  • npm test -- --maxWorkers=1 --no-file-parallelism (38 passed)
  • npm run lint
  • npm run build
  • Added deterministic tests for exact conversion, rejection boundaries, integer arithmetic, invalid policy input, and receipt binding.
  • Smoke-tested the Vite preview: a sub-lamport input is blocked and the receipt remains visible.
  • No layout change; the visible changes are amount formatting and the safe invalid-receipt label.

Safety

  • No private keys, seed phrases, wallet connections, or network transactions were requested.
  • Policy evaluation still occurs before any wallet signing request.
  • No dependencies, generated build output, or secrets were added.

AI assistance

This contribution was implemented by an AI coding agent. I manually verified the source diff, the required validation commands, and the local browser smoke test.

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