Skip to content

fix(swap): say "enable AdvancedMode" instead of "Action cancelled" - #417

Merged
BitHighlander merged 1 commit into
developfrom
fix/swap-advanced-mode-required-message
Aug 15, 2026
Merged

fix(swap): say "enable AdvancedMode" instead of "Action cancelled"#417
BitHighlander merged 1 commit into
developfrom
fix/swap-advanced-mode-required-message

Conversation

@BitHighlander

Copy link
Copy Markdown
Collaborator

A relay swap died with a bare Action cancelled while the device sat there
having shown "Blocked". The reason existed and was thrown away.

What actually happens

Relay routes are not in the firmware's pinned clear-sign allowlist, so the
device must blind-sign them — and blind-signing arbitrary contract data is
gated on AdvancedMode (ethereum.c). It renders "Blocked" and replies
Failure_ActionCancelled with the message "Blind signing disabled by policy".

hdwallet's transport then does:

throw new core.ActionCancelled();          // message discarded
if (response.message_type === FAILURE) throw response;   // next line: kept

Only ActionCancelled is flattened; every other failure keeps its payload. And
firmware uses that same code for a genuine user cancel, so once the string is
gone Vault cannot tell "user pressed cancel" from "policy refused" — it has
nothing left to build a prompt from.

Clear-signing is not an escape hatch here. Metadata verification needs a
runtime-loaded signer and loading one ALSO requires AdvancedMode; there is no
built-in trust anchor (signed_metadata.c only ever returns loaded keys —
"deliberately rejects persistent trust anchors"). The delegation work that
would change this is docs-only, gated on an owner custody decision:
docs/security/clearsign-key-delegation-roadmap.md. So AdvancedMode is required
for relay today, by design, and it is documented in
docs/security/7.15.0-rc21-clearsign-release-control.md:

"runtime signer loading, and runtime metadata verification are usable only
while the user has enabled AdvancedMode"

The fix

Check before prompting, not after failing — same shape as the Solana opaque
gate directly above it, using the isAdvancedModeEnabled hook that was already
on SwapContext for exactly that purpose but never applied to EVM.

Fires only when all of: EVM, real calldata, NOT in the firmware allowlist
(firmwareClearSigns), and the policy is known-disabled. undefined (features
not cached / policy not reported) deliberately does not fire — guessing would
block a swap the device would have signed.

The message names the blocker, says where to fix it, and warns that it turns
itself back off on reboot (#373 made AdvancedMode session-scoped, which is why
this went from rare to constant).

Not fixed here: hdwallet still destroys the reason string, so a cancel arriving
from any other path is still ambiguous. That is the real repair and it belongs
in hdwallet transport.ts; this makes the reported case actionable now.

Tests

Wires tests/firmware-clearsign-gate.test.ts into make test-unit. It already
asserts the exact predicate this gate depends on — including "firmware-unknown
contracts → blind (Uniswap / 1inch / relay)" — and had never run in CI, the
third such file found this session.

make test-unit 480 pass, 0 fail across 32 files, +35 btc-backend, +10 cosmos
tsc --noEmit 627, unchanged, 2 below baseline 629

A relay swap died with a bare `Action cancelled` while the device sat there
having shown "Blocked". The reason existed and was thrown away.

## What actually happens

Relay routes are not in the firmware's pinned clear-sign allowlist, so the
device must blind-sign them — and blind-signing arbitrary contract data is
gated on AdvancedMode (ethereum.c). It renders "Blocked" and replies
Failure_ActionCancelled with the message "Blind signing disabled by policy".

hdwallet's transport then does:

    throw new core.ActionCancelled();          // message discarded
    if (response.message_type === FAILURE) throw response;   // next line: kept

Only ActionCancelled is flattened; every other failure keeps its payload. And
firmware uses that same code for a genuine user cancel, so once the string is
gone Vault cannot tell "user pressed cancel" from "policy refused" — it has
nothing left to build a prompt from.

Clear-signing is not an escape hatch here. Metadata verification needs a
runtime-loaded signer and loading one ALSO requires AdvancedMode; there is no
built-in trust anchor (signed_metadata.c only ever returns loaded keys —
"deliberately rejects persistent trust anchors"). The delegation work that
would change this is docs-only, gated on an owner custody decision:
docs/security/clearsign-key-delegation-roadmap.md. So AdvancedMode is required
for relay today, by design, and it is documented in
docs/security/7.15.0-rc21-clearsign-release-control.md:

  "runtime signer loading, and runtime metadata verification are usable only
   while the user has enabled AdvancedMode"

## The fix

Check before prompting, not after failing — same shape as the Solana opaque
gate directly above it, using the `isAdvancedModeEnabled` hook that was already
on SwapContext for exactly that purpose but never applied to EVM.

Fires only when all of: EVM, real calldata, NOT in the firmware allowlist
(firmwareClearSigns), and the policy is known-disabled. `undefined` (features
not cached / policy not reported) deliberately does not fire — guessing would
block a swap the device would have signed.

The message names the blocker, says where to fix it, and warns that it turns
itself back off on reboot (#373 made AdvancedMode session-scoped, which is why
this went from rare to constant).

Not fixed here: hdwallet still destroys the reason string, so a cancel arriving
from any other path is still ambiguous. That is the real repair and it belongs
in hdwallet transport.ts; this makes the reported case actionable now.

## Tests

Wires __tests__/firmware-clearsign-gate.test.ts into make test-unit. It already
asserts the exact predicate this gate depends on — including "firmware-unknown
contracts → blind (Uniswap / 1inch / relay)" — and had never run in CI, the
third such file found this session.

make test-unit   480 pass, 0 fail across 32 files, +35 btc-backend, +10 cosmos
tsc --noEmit     627, unchanged, 2 below baseline 629
@BitHighlander
BitHighlander merged commit 6ad7fe2 into develop Aug 15, 2026
4 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