spike: an ML-DSA-65 NEAR account runs the whole route on mainnet #72

Closed
opened 2026-10-09 08:46:16 +00:00 by grenade · 2 comments
Owner

Part of #71. Decides the epic's signer.

Create a named NEAR account whose only access key is ML-DSA-65, funded from the wNEAR in the operator's existing intents account (native_withdraw from it, then an ordinary account creation with a temporary ed25519 key that is replaced by the ML-DSA key and deleted). Then, signing every NEAR transaction with the ML-DSA key and nothing else, run the operator's route with small amounts:

  1. Bridge-in: QTC from a Quantus account to the account's PoA deposit address; see it credited as qtc.omft.near in intents.near.
  2. Pool leg: ft_withdraw of QTC to dclv2.ref-labs.near with a Swap message into wNEAR, called directly by the account; see the wNEAR paid back into its intents balance.
  3. 1Click leg: a 1Click quote for wNEAR to USDC funded by an mt_transfer from the account to the quote's deposit account; see 1Click settle it.
  4. Cash-out: withdraw a USDC (or the 1Click output) to an external chain.
  5. QTC back to Quantus, the 0.002 QTC fee route.

Also establish, from nearcore source and a mainnet transaction: the borsh form of an ML-DSA-65 key and signature, and the FIPS 204 context NEAR signs transactions under (empty or named). An ML-DSA signature under the wrong context is valid and refused, as on Quantus.

Acceptance: a comment on this issue with each step's transaction hash and outcome, and a verdict: PQ intents account viable for the route, or which step needs a classical signature and why. The spike's code is throwaway; its findings are what #71's design takes.

Part of #71. Decides the epic's signer. Create a named NEAR account whose only access key is ML-DSA-65, funded from the wNEAR in the operator's existing intents account (`native_withdraw` from it, then an ordinary account creation with a temporary ed25519 key that is replaced by the ML-DSA key and deleted). Then, signing every NEAR transaction with the ML-DSA key and nothing else, run the operator's route with small amounts: 1. Bridge-in: QTC from a Quantus account to the account's PoA deposit address; see it credited as `qtc.omft.near` in `intents.near`. 2. Pool leg: `ft_withdraw` of QTC to `dclv2.ref-labs.near` with a `Swap` message into wNEAR, called directly by the account; see the wNEAR paid back into its intents balance. 3. 1Click leg: a 1Click quote for wNEAR to USDC funded by an `mt_transfer` from the account to the quote's deposit account; see 1Click settle it. 4. Cash-out: withdraw a USDC (or the 1Click output) to an external chain. 5. QTC back to Quantus, the 0.002 QTC fee route. Also establish, from nearcore source and a mainnet transaction: the borsh form of an ML-DSA-65 key and signature, and the FIPS 204 context NEAR signs transactions under (empty or named). An ML-DSA signature under the wrong context is valid and refused, as on Quantus. Acceptance: a comment on this issue with each step's transaction hash and outcome, and a verdict: PQ intents account viable for the route, or which step needs a classical signature and why. The spike's code is throwaway; its findings are what #71's design takes.
grenade added the child label 2026-10-09 08:46:16 +00:00
Author
Owner

Verdict: viable. Every leg of the route ran on mainnet from a NEAR account whose only key is ML-DSA-65.

Account bbspike72.near, key ml-dsa-65-hash:BGQfipngvvnrNKHEV41FDVPiFy1kEajb9capGbX1uibt. Every transaction after the third was signed with ML-DSA-65 and nothing else, and none of them needed a signed intent (execute_intents). 2026-10-09, all times EEST.

step how NEAR tx result
fund native_withdraw 1.6 NEAR from the operator's ed25519 intents account to its own implicit account (relay publish_intent) intent 61gCQ6m4… 1.6 NEAR on 42d72e44…
create implicit account calls near.create_account with a temporary ed25519 key, 1.3 NEAR HmueC2ck1f6K3kdWVxfiuzEAPD9BLkJH6Z7t9rpimYkU ok
add PQ key AddKey ML-DSA-65 full access, ed25519-signed D7m6P2tc8aumLVdeNbnThfHpdRQhn863oRVzDNVajAFY stored as ml-dsa-65-hash:
drop classical key DeleteKey ed25519, ML-DSA-signed 9HN51j6VSHfkn7Wd6tZEpUB25b3iFoLvuZru2e9JPW2N the account is PQ-only from here
deposit wrap.near: storage_deposit + near_deposit 1 NEAR + ft_transfer_call to intents.near (msg: ""), one tx FdtcrSKHg3vEzV4EHWLNf7oh5bpCWn5RQ2Dq7p36ED8J 1 wNEAR in Intents
pool buy direct intents.near.ft_withdraw to dclv2.ref-labs.near with the Swap msg (client_echo = own account) F6KHGWDffvMkaqPibW77qiV6CvNk88VBgNjPqLvTiLnF 1 wNEAR → 0.035923 QTC in Intents
bridge out direct ft_withdraw of qtc.omft.near to itself, memo WITHDRAW_TO:qzoqjLjG…1ZC 4PGj6GetrQyyjoDrkFCHbGDwXR4wDhsJFiduQ7sjwRXm 0.033 QTC on Quantus about 60 s later (0.002 fee)
bridge in PoA deposit_address for the named account (qzm76Xye…kqfn), then a quantus send of 0.0315 QTC Quantus 0x5751f1f4…fc54 credited in Intents about 6 min later
pool sell direct ft_withdraw QTC → DCL pool, Swap to wNEAR AyBzNK5A5PdZ7zUA5kzqCuQYd9MPyJ7bDfT2pJdYGM49 0.032423 QTC → 0.889664 wNEAR
1Click swap live quote wNEAR → USDC, INTENTS in and out, funded by direct mt_transfer to the quote's deposit account 7AQgvJkCniVtmd38MxLa7DVXAr7PhmbkEYTxNjZMUJBR SUCCESS in about 10 s, 4.278655 USDC
cash-out live quote with recipientType: DESTINATION_CHAIN, funded the same way B8RavVUVP1i47qpRSP7C4UmiAQt9vMhAuyv6Xv7HamJM SUCCESS, USDC paid out on chain (8KrSKv7y…)
return ft_transfer_call USDC into intents.near with msg = the operator's account F88bTA1bQbAKefifbwbbiKbp5hXquDwSECmcw1WsbfVV credited to 42d72e44…

The cash-out went to NEAR's own chain, because no EVM address of ours was to hand. From the PQ account's side the mechanism is the same as an Ethereum payout: a 1Click quote funded by mt_transfer. Only 1Click's payout differs.

Facts for #71's design

  • Signing. NEAR's ML-DSA-65 is pure ML-DSA under the empty FIPS 204 context (nearcore 2.13.4 signs with aws-lc's PqdsaKeyPair::sign). qp-rusty-crystals-dilithium 4.1.1, already in the workspace, produces accepted signatures with ctx = None. It is the opposite of Quantus, where the empty context is refused; the two must never share a code path that picks a context implicitly.
  • Wire format. A transaction is still TransactionV0, and the transaction hash is still the SHA-256 of its borsh encoding. A public key is tag 2 followed by 1952 bytes; a signature is tag 2 followed by 3309 bytes. A signed transaction is about 5.4–5.7 kB, against about 370 B for ed25519. The access key lives in state as ml-dsa-65-hash: + base58(SHA3-256("near:ml-dsa-65-pubkey-hash:v1" ‖ pk)). view_access_key takes that hash form.
  • Gas must be prepaid in native NEAR. A 300 Tgas call needs about 0.30 NEAR in the account at submission, even though the unused part is refunded (NotEnoughBalance at 0.2975 NEAR). Each leg actually cost about 0.001–0.003 NEAR. 250 Tgas was enough for the DCL swap. A PQ account therefore keeps a native NEAR float; the ed25519 path is gasless. #74 has to show that float and top it up, for example by unwrapping wNEAR.
  • Account creation needs a sponsor until protocol 87. The named account had to be created by an existing account (the registrar, with a temporary ed25519 key that was deleted straight away). NEP-655's PQ implicit accounts in protocol 87 should remove that; until then, a new user needs some NEAR from somewhere, or a sponsor.
  • What is out of reach without a classical key. Solver-settled token_diff intents. The route above never needed one.
  • The NEAR-side key is a separate derivation. NEP-649 proposes m/44'/397'/… for ML-DSA-65; the spike key was random. #74 decides the path.

Cost

1.6 NEAR left the operator's intents account. Back: 4.278655 USDC credited to it, 0.2925 NEAR on its implicit account 42d72e44…, and 0.2875 NEAR left on bbspike72.near, kept for development.

The round trip cost the difference: 1 NEAR in, 0.8897 wNEAR out. That covers two 1% pool fees, the bridge's 0.002 QTC withdrawal fee (about 6% at this size), and about 0.0015 QTC left as dust on the throwaway Quantus account.

The spike's code (throwaway) and its ML-DSA key are on the operator's workstation under ~/.config/blackbeard-spike/.

## Verdict: viable. Every leg of the route ran on mainnet from a NEAR account whose only key is ML-DSA-65. Account `bbspike72.near`, key `ml-dsa-65-hash:BGQfipngvvnrNKHEV41FDVPiFy1kEajb9capGbX1uibt`. Every transaction after the third was signed with ML-DSA-65 and nothing else, and none of them needed a signed intent (`execute_intents`). 2026-10-09, all times EEST. | step | how | NEAR tx | result | |---|---|---|---| | fund | `native_withdraw` 1.6 NEAR from the operator's ed25519 intents account to its own implicit account (relay `publish_intent`) | intent `61gCQ6m4…` | 1.6 NEAR on `42d72e44…` | | create | implicit account calls `near.create_account` with a temporary ed25519 key, 1.3 NEAR | `HmueC2ck1f6K3kdWVxfiuzEAPD9BLkJH6Z7t9rpimYkU` | ok | | add PQ key | `AddKey` ML-DSA-65 full access, ed25519-signed | `D7m6P2tc8aumLVdeNbnThfHpdRQhn863oRVzDNVajAFY` | stored as `ml-dsa-65-hash:` | | **drop classical key** | `DeleteKey` ed25519, **ML-DSA-signed** | `9HN51j6VSHfkn7Wd6tZEpUB25b3iFoLvuZru2e9JPW2N` | the account is PQ-only from here | | deposit | `wrap.near`: `storage_deposit` + `near_deposit` 1 NEAR + `ft_transfer_call` to `intents.near` (`msg: ""`), one tx | `FdtcrSKHg3vEzV4EHWLNf7oh5bpCWn5RQ2Dq7p36ED8J` | 1 wNEAR in Intents | | pool buy | direct `intents.near.ft_withdraw` to `dclv2.ref-labs.near` with the `Swap` msg (`client_echo` = own account) | `F6KHGWDffvMkaqPibW77qiV6CvNk88VBgNjPqLvTiLnF` | 1 wNEAR → 0.035923 QTC in Intents | | bridge out | direct `ft_withdraw` of `qtc.omft.near` to itself, memo `WITHDRAW_TO:qzoqjLjG…1ZC` | `4PGj6GetrQyyjoDrkFCHbGDwXR4wDhsJFiduQ7sjwRXm` | 0.033 QTC on Quantus about 60 s later (0.002 fee) | | bridge in | PoA `deposit_address` for the **named** account (`qzm76Xye…kqfn`), then a `quantus send` of 0.0315 QTC | Quantus `0x5751f1f4…fc54` | credited in Intents about 6 min later | | pool sell | direct `ft_withdraw` QTC → DCL pool, `Swap` to wNEAR | `AyBzNK5A5PdZ7zUA5kzqCuQYd9MPyJ7bDfT2pJdYGM49` | 0.032423 QTC → 0.889664 wNEAR | | 1Click swap | live quote wNEAR → USDC, `INTENTS` in and out, **funded by direct `mt_transfer`** to the quote's deposit account | `7AQgvJkCniVtmd38MxLa7DVXAr7PhmbkEYTxNjZMUJBR` | `SUCCESS` in about 10 s, 4.278655 USDC | | cash-out | live quote with `recipientType: DESTINATION_CHAIN`, funded the same way | `B8RavVUVP1i47qpRSP7C4UmiAQt9vMhAuyv6Xv7HamJM` | `SUCCESS`, USDC paid out on chain (`8KrSKv7y…`) | | return | `ft_transfer_call` USDC into `intents.near` with `msg` = the operator's account | `F88bTA1bQbAKefifbwbbiKbp5hXquDwSECmcw1WsbfVV` | credited to `42d72e44…` | The cash-out went to NEAR's own chain, because no EVM address of ours was to hand. From the PQ account's side the mechanism is the same as an Ethereum payout: a 1Click quote funded by `mt_transfer`. Only 1Click's payout differs. ## Facts for #71's design - **Signing.** NEAR's ML-DSA-65 is pure ML-DSA under the **empty** FIPS 204 context (nearcore 2.13.4 signs with aws-lc's `PqdsaKeyPair::sign`). `qp-rusty-crystals-dilithium` 4.1.1, already in the workspace, produces accepted signatures with `ctx = None`. It is the opposite of Quantus, where the empty context is refused; the two must never share a code path that picks a context implicitly. - **Wire format.** A transaction is still `TransactionV0`, and the transaction hash is still the SHA-256 of its borsh encoding. A public key is tag `2` followed by 1952 bytes; a signature is tag `2` followed by 3309 bytes. A signed transaction is about 5.4–5.7 kB, against about 370 B for ed25519. The access key lives in state as `ml-dsa-65-hash:` + base58(SHA3-256(`"near:ml-dsa-65-pubkey-hash:v1"` ‖ pk)). `view_access_key` takes that hash form. - **Gas must be prepaid in native NEAR.** A 300 Tgas call needs about 0.30 NEAR in the account at submission, even though the unused part is refunded (`NotEnoughBalance` at 0.2975 NEAR). Each leg actually cost about 0.001–0.003 NEAR. 250 Tgas was enough for the DCL swap. A PQ account therefore keeps a native NEAR float; the ed25519 path is gasless. #74 has to show that float and top it up, for example by unwrapping wNEAR. - **Account creation needs a sponsor until protocol 87.** The named account had to be created by an existing account (the registrar, with a temporary ed25519 key that was deleted straight away). NEP-655's PQ implicit accounts in protocol 87 should remove that; until then, a new user needs some NEAR from somewhere, or a sponsor. - **What is out of reach without a classical key.** Solver-settled `token_diff` intents. The route above never needed one. - **The NEAR-side key is a separate derivation.** NEP-649 proposes `m/44'/397'/…` for ML-DSA-65; the spike key was random. #74 decides the path. ## Cost 1.6 NEAR left the operator's intents account. Back: 4.278655 USDC credited to it, 0.2925 NEAR on its implicit account `42d72e44…`, and 0.2875 NEAR left on `bbspike72.near`, kept for development. The round trip cost the difference: 1 NEAR in, 0.8897 wNEAR out. That covers two 1% pool fees, the bridge's 0.002 QTC withdrawal fee (about 6% at this size), and about 0.0015 QTC left as dust on the throwaway Quantus account. The spike's code (throwaway) and its ML-DSA key are on the operator's workstation under `~/.config/blackbeard-spike/`.
Author
Owner

Correction (found building #73): view_access_key does not take the ml-dsa-65-hash: form. Nodes refuse it as a parse error (unknown key type 'ml-dsa-65-hash'). They want the full key, ml-dsa-65:<base58 of the 1952-byte key>.

The handle is what state keeps and what view_access_key_list shows. The spike's helper tried the handle first and silently fell back to the full key, which hid this.

A missing key arrives as a result whose error field says "access key … does not exist while viewing", not as an RPC error.

Correction (found building #73): `view_access_key` does **not** take the `ml-dsa-65-hash:` form. Nodes refuse it as a parse error (`unknown key type 'ml-dsa-65-hash'`). They want the full key, `ml-dsa-65:<base58 of the 1952-byte key>`. The handle is what state keeps and what `view_access_key_list` shows. The spike's helper tried the handle first and silently fell back to the full key, which hid this. A missing key arrives as a `result` whose `error` field says "access key … does not exist while viewing", not as an RPC error.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: blackbeard/wallet#72