Skip to content

feat(ton): address validation and explicit blind-sign warning#57

Merged
BitHighlander merged 5 commits intodevelopfrom
feature/ton-clear-signing
Mar 18, 2026
Merged

feat(ton): address validation and explicit blind-sign warning#57
BitHighlander merged 5 commits intodevelopfrom
feature/ton-clear-signing

Conversation

@BitHighlander
Copy link
Owner

Summary

  • Add ton_validateAddress(): Base64 URL-safe decode + CRC16-XMODEM checksum + tag byte validation
  • Validate destination address BEFORE display (rejects invalid with SyntaxError)
  • Add explicit "Blind Signature" warning on all TON signing paths
  • C unit tests for address validation + round-trip generate/validate

Security context

TON uses Cell/BoC encoding which cannot be parsed on embedded devices. PR #52 identified this as a HIGH finding — the device was displaying host-supplied to_address/amount as if verified, with no warning that the signed raw_tx Cell could contain different data.

This PR adds:

  1. Address validation: CRC16-XMODEM checksum verified before display — prevents garbage/malformed addresses from being shown to user
  2. Blind-sign warning: Explicit "TON TX details cannot be verified on device. Sign only if you trust the sending app." — user must acknowledge on every sign

Full Cell reconstruction (reconstruct-then-sign, matching what TRON does) is a future improvement tracked separately.

Base

Built on top of upstream keepkey#387 (feat/tron-ton-support)

Test plan

  • C unit tests pass (ton.cpp — address validation, round-trip, formatting)
  • ARM firmware build succeeds
  • Emulator build succeeds
  • On-device: valid TON address shown with amount, then blind-sign warning
  • On-device: invalid TON address rejected before display
  • Legacy signing shows blind-sign warning

BitHighlander and others added 5 commits March 17, 2026 21:18
TRON: secp256k1 + Keccak256 address derivation, SHA256 tx signing
TON: Ed25519 address derivation with CRC16 + Base64url, Ed25519 tx signing

Both use existing trezor-crypto primitives only.
TON uses Cell/BoC encoding which cannot be parsed on embedded devices.
This commit adds the minimum viable clear-signing improvements:

- Add ton_validateAddress(): Base64 URL-safe decode + CRC16-XMODEM
  checksum verification + tag byte validation. Destination address
  is now validated BEFORE being displayed to the user.
- Add explicit "Blind Signature" warning on all TON signing paths.
  Users must acknowledge that TX details cannot be verified on-device.
- Reject invalid destination addresses with FailureType_Failure_SyntaxError
  instead of showing unvalidated data.
- C unit tests: address validation (NULL, wrong length, bad checksum,
  bad tag), round-trip generate+validate, amount formatting.

Note: Full Cell reconstruction (reconstruct-then-sign) for TON is a
future improvement. Cell/BoC bit-level encoding is too complex for
this pass. The blind-sign warning makes the security model explicit.

Based on upstream keepkey#387 (feat/tron-ton-support)
- Validate to_address CRC16 even when amount is not provided. Previously
  validation was gated by (has_to_address && has_amount), so a malformed
  address without amount would reach signing unchecked.
- Restrict workchain to 0 (basechain) or -1 (masterchain) in both
  GetAddress and SignTx handlers. ton_get_address truncates workchain
  to uint8 for the user-friendly address but prints the full sint32 in
  raw_address — out-of-range inputs would produce inconsistent addresses.
@BitHighlander BitHighlander force-pushed the feature/ton-clear-signing branch from fc3de78 to ef79baf Compare March 18, 2026 03:19
@BitHighlander BitHighlander marked this pull request as ready for review March 18, 2026 03:24
@BitHighlander BitHighlander merged commit 8fecf35 into develop Mar 18, 2026
18 checks passed
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