From b23b02bdaae233f51b543bc60fa38a025e07a743 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 25 Nov 2026 08:33:00 -0700 Subject: Ark sends follow server-0.9.0's dust rule, and a renewal checks its new coins before forfeiting for them. "yes go ahead" (Adam, 2026-11-25, on fixing the send code and the refresh check before rehearsing captaind 0.9.0). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dust: 0.9.0 (!2822) refuses a cosign whose checkpoint carries an output under 330 sat unless the input itself is dust. Our split, a port of bark ≤0.8's new_isolate_dust, "accepted the mix" in two cases 0.9.0 now isolates: every output dust (100 sent from a 400-sat coin, 300 change), and dust no output can pad (100 from 500, the 400 change isolated whole). isolateDust now matches 0.9.0 case for case (upstream's eight isolate_dust tests ported). 0.8.0 refuses exactly those two new shapes instead ("At least one output is required"), so the split follows the server it talks to: a server advertising ArkInfo field 23 (max_round_participation_outputs, new in 0.9.0 and never 0 there) gets the new rule, any other the old one. Every arkoor build (sends, Lightning HTLC sends, refunds, sweeps, claims) passes it through. Renewals: bark !2803 (reported by MrHodl) — bark didn't check that the unlock hash of its forfeits matched the one locking its new round coins; neither did we. A round's coins are now checked before the leaf cosign and the forfeit: a hash-locked round leaf locked by our unlock hash, anchored in this round's funding transaction, paid to our output key, worth at least what we asked for. On any mismatch nothing is signed, and the action keeps the reason. Regtest: new dust-shapes-test sends all four shapes (all dust, isolate whole, pad, dust input) from single-coin wallets, delivers them and spends the change onward — passes on captaind 0.8.0 and on 0.9.0 (master's code fails the two new shapes on 0.9.0). manager, dust-gift, refresh-reprice, rescue-claimed, expired-dust, send-failure, custody, offboard-split and board tests pass on 0.9.0; ln-test and ln-e2e (25-sat zap-size sends, receives) pass on 0.9.0 with CLN v26.06.9; manager and dust-gift pass on 0.8.0. send, refresh, receive, scheduled-refresh and ln-pending-history fail the same way on master (stale fixtures). New isolate-dust-test (upstream vectors, 200k random payments against both servers' ported checks) and round-outputs-check-test pass; rescue-claimed-test stubs the new check (its fake rounds carry no coins). features-smoke and feature-registry-check pass. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg --- src/ark/refresh.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/ark/refresh.js') diff --git a/src/ark/refresh.js b/src/ark/refresh.js index 6e4453d..44c8321 100644 --- a/src/ark/refresh.js +++ b/src/ark/refresh.js @@ -355,6 +355,32 @@ export async function roundParticipationStatus(ark, unlockHash) { return out; } +// The round's new coins, checked before we cosign their leaves and forfeit +// our inputs. The forfeits hand the server our inputs in exchange for the +// preimage of OUR unlock hash, so a new coin locked by any other hash could +// never be unlocked: forfeiting for it gives the money away. Port of bark +// !2803 (server-0.9.0's client fix, reported by MrHodl: "Bark didn't check +// that the unlock hash of its forfeits matched the one locking its new +// VTXOs"), plus what bark's check_round_matches_participation also asks: +// every coin a hark leaf anchored in this round's transaction and paid to +// our key, and together at least what we asked for. Throws on the first +// mismatch; nothing is signed then. +export function checkRoundOutputs(vtxos, { unlockHash, fundingTxid, ownerPubkey, minTotalSat = 0 }) { + if (!vtxos.length) throw new Error('the round returned no coins for this participation'); + let total = 0; + for (const v of vtxos) { + const last = v.genesis[v.genesis.length - 1]; + const t = last && last.transition; + if (!t || !['hashLockedCosigned', 'hashLockedCosigned_v0'].includes(t.type)) throw new Error(`new coin ${v.id} is not a hash-locked round leaf`); + const lockedBy = t.unlock && (t.unlock.hash ?? (t.unlock.preimage != null ? sha256Hex(t.unlock.preimage) : null)); + if (lockedBy !== unlockHash) throw new Error(`new coin ${v.id} is locked by unlock hash ${lockedBy}, expected ${unlockHash}`); + if (v.anchorPoint.txid !== fundingTxid) throw new Error(`new coin ${v.id} is anchored in ${v.anchorPoint.txid}, not this round's ${fundingTxid}`); + if (v.policy.type !== 'pubkey' || v.policy.userPubkey !== ownerPubkey) throw new Error(`new coin ${v.id} is not paid to our key`); + total += v.amountSat; + } + if (total < minTotalSat) throw new Error(`the round's new coins hold ${total} sat, ${minTotalSat} were asked for`); +} + // MuSig2 script-spend cosign of the hash-locked leaf (NO taptweak) export async function cosignHarkLeaf(ark, vtxo, fundingTx, vtxoKeys, serverPub) { const last = vtxo.genesis[vtxo.genesis.length - 1]; -- cgit v1.2.3