pay: domain-separate tip and gate legacy signature acceptance
All checks were successful
ci / test (pull_request) Successful in 19m52s
ci / sdk (pull_request) Successful in 2m16s

`tip` was the one payment frame with no domain tag: sign_tip signed the
LF-joined fields, so its signature could be confused with any other
newline-joined preimage. Mirror inv/rcp: sign_tip now emits
"onionwire-tip-v1" || 0x00-separated txid/amount/address/memo/ts, and
verify_tip tries that form then the historical layout.

Legacy acceptance is now one switch instead of nine call sites:
`pay::LEGACY_SIGS` (default true) plus `pay::legacy_sigs()`. Every v1 /
concat fallback reads it — the `onionwire:v1` invite string and its two
historical signature forms, `loc`, `inv`, `rcp`, and `tip`. `prf` is not
gated here because src/profile.rs is outside this card's file scope; the
spec says so.

Tests: legacy-on keeps every untagged form verifying (incl. a new tip
case); legacy-off rejects each untagged form while the tagged form still
verifies (loc, inv, rcp, tip, invite); sign_tip is pinned to the tagged
layout.

docs/PROTOCOL.md gains the emitted/accepted table per signed frame and
the mixed-fleet consequence.
This commit is contained in:
rust-dev 2026-10-22 22:23:44 -04:00
commit b8c52ca97d
No known key found for this signature in database
6 changed files with 352 additions and 35 deletions

View file

@ -312,20 +312,42 @@ prefix.
### Application-frame signatures
`loc`, `prf`, `inv`, and `rcp` each carry an ed25519 signature over the
`loc`, `prf`, `inv`, `rcp`, and `tip` each carry an ed25519 signature over the
**fields**, not the 4-byte typed prefix. Encode MUST sign the domain-separated
form (type tag, then each field, `0x00` separators). Verify MUST accept that
form and, for mixed-version peers, the legacy untagged LF-joined layout.
Anything else fails closed. Do not emit the legacy layout.
`tip` is signed over the LF-joined fields only (no domain tag on encode today).
The `tip ` prefix is not signed.
The invite string is separate and uses `onionwire-invite-v2` (see Invite).
The invite string is separate and keeps `onionwire-invite-v1` (see Invite).
Legacy acceptance is one switch, `LEGACY_SIGS`, default **on**. Every fallback
listed below reads it; with it off, verification accepts only the emitted
(tagged) form. It is a local capability constant, not a wire field: it is never
sent, and a peer cannot negotiate it.
Older builds verify only the untagged bytes, so they reject tagged signatures
(fail closed, no downgrade). Mixed-version fleets break outbound application
frames from a new sender to an old receiver until both sides are updated.
| frame | emitted | accepted inbound |
| --- | --- | --- |
| invite | `onionwire-invite-v2`, `0x00`-separated over `k`, `o`, `spk`, `kem` | same; `onionwire:v1` over `onionwire-invite-v1` `0x00`-separated `k`,`o`,`spk`, or over `k \|\| o \|\| spk` (legacy only) |
| `loc ` | `"onionwire-loc-v1"` `0x00` `onion` `0x00` `ts` | same; `onion \|\| LF \|\| ts` (legacy only) |
| `prf ` | `"onionwire-prf-v1"` `0x00` `name` `0x00` `bio` `0x00` `xmr_addr` `0x00` `ts` | same; the four fields joined by LF (not yet gated — see below) |
| `inv ` | `"onionwire-inv-v1"` `0x00` `amount_atomic` `0x00` `address` `0x00` `memo` `0x00` `ts` | same; the four fields joined by LF (legacy only) |
| `rcp ` | `"onionwire-rcp-v1"` `0x00` `txid` `0x00` `amount_atomic` `0x00` `address` `0x00` `ts` | same; the four fields joined by LF (legacy only) |
| `tip ` | `"onionwire-tip-v1"` `0x00` `txid` `0x00` `amount_atomic` `0x00` `address` `0x00` `memo` `0x00` `ts` | same; the five fields joined by LF (legacy only) |
The tag suffixes do say `-v1`; that is the tag's own version, not the invite
string version.
`prf ` is the one frame whose legacy fallback is not yet gated: it is accepted
unconditionally in this revision and moving it under `LEGACY_SIGS` is a
separate change.
**Mixed-fleet consequence.** Older builds verify only the untagged bytes, so
they reject every tagged signature from a new sender — including `tip `, which
older builds emitted and verified untagged. That direction needs the peer
updated before tips flow. The reverse works while `LEGACY_SIGS` is on: a new
build verifies an old sender's untagged `loc`/`prf`/`inv`/`rcp`/`tip` and an
`onionwire:v1` invite. Turning the switch off is a fleet-wide cutover, not a
per-peer choice.
### `loc ` — locator update
@ -348,8 +370,8 @@ ed25519_sign(identity_sk,
```
**Legacy accept:** a signature over `onion || LF || ascii(ts)` is still
accepted on verify so old loc frames verify. New loc frames MUST use the
domain-separated form. Do not emit legacy.
accepted on verify while `LEGACY_SIGS` is on, so old loc frames verify. New loc
frames MUST use the domain-separated form. Do not emit legacy.
Apply only if **all** of:
@ -380,7 +402,7 @@ ed25519_sign(identity_sk,
**Legacy accept:** a signature over the four fields joined by LF is still
accepted on verify. New profile frames MUST use the domain-separated form.
Do not emit legacy.
Do not emit legacy. This fallback is not yet read through `LEGACY_SIGS`.
Apply only for an existing friend, valid signature, newer `ts`. Not a public
profile. Not a directory.
@ -403,8 +425,8 @@ ed25519_sign(identity_sk,
```
**Legacy accept:** a signature over the four fields joined by LF is still
accepted on verify. New invoices MUST use the domain-separated form. Do not
emit legacy.
accepted on verify while `LEGACY_SIGS` is on. New invoices MUST use the
domain-separated form. Do not emit legacy.
The frame is a signed claim, not a payment. It is one-shot: if the peer onion
is down, the send fails. There is no queued invoice.
@ -425,8 +447,8 @@ ed25519_sign(identity_sk,
```
**Legacy accept:** a signature over the four fields joined by LF is still
accepted on verify. New receipts MUST use the domain-separated form. Do not
emit legacy.
accepted on verify while `LEGACY_SIGS` is on. New receipts MUST use the
domain-separated form. Do not emit legacy.
Signature proves which friend sent the claim. It does **not** prove money
moved. Local `verified=1` only if a user-hosted `monero-wallet-rpc` returns
@ -442,13 +464,20 @@ Sent after a chain transfer, together with `rcp `. One-shot.
tip <txid>\n<amount_atomic>\n<address>\n<memo>\n<ts>\n<sig_hex>
```
The `tip ` prefix is **not** signed. Encode signs the LF-joined fields:
The `tip ` prefix is **not** signed.
**Current signature (encode this):**
```
ed25519_sign(identity_sk,
txid || LF || amount_atomic || LF || address || LF || memo || LF || ascii(ts))
"onionwire-tip-v1" || 0x00 || txid || 0x00 || amount_atomic || 0x00 ||
address || 0x00 || memo || 0x00 || ascii(ts))
```
**Legacy accept:** a signature over the five fields joined by LF is still
accepted on verify while `LEGACY_SIGS` is on. New tips MUST use the
domain-separated form. Do not emit legacy.
`memo` MUST NOT contain newlines. Same address and amount rules as invoices.
A peer that does not implement `tip ` MUST drop it as an unknown typed prefix,
not render it as chat.
@ -880,7 +909,8 @@ signature covers `kem_ascii`, removing the field or substituting a different
key fails verification — that is the anti-strip/anti-substitution property.
**Legacy accept (`onionwire:v1`):** a v1 invite has no `kem` field. Decode
accepts it and yields a friend with no `kem_pk`, i.e. a classical peer. A v1
accepts it while `LEGACY_SIGS` is on and yields a friend with no `kem_pk`, i.e.
a classical peer; with the switch off a v1 invite fails closed. A v1
signature is accepted in either historical form: the tagged
`"onionwire-invite-v1" || 0x00 || k || 0x00 || o || 0x00 || spk` or the raw
concatenation `k || o || spk` (no tag, no separators), so old invites keep