aboutsummaryrefslogtreecommitdiffstats
path: root/tools/ark/round-outputs-check-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-25 08:33:00 -0700
committerAdam Soltys <[email protected]>2026-11-25 08:33:00 -0700
commitb23b02bdaae233f51b543bc60fa38a025e07a743 (patch)
tree10e20e92b97d4942663007b6365e995b3f856d42 /tools/ark/round-outputs-check-test.js
parent2cd42f811d33a74c3ca28094176c009c0388da9b (diff)
downloadcoinosv3-b23b02bdaae233f51b543bc60fa38a025e07a743.tar.gz
coinosv3-b23b02bdaae233f51b543bc60fa38a025e07a743.zip
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).HEADmaster
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 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
Diffstat (limited to 'tools/ark/round-outputs-check-test.js')
-rw-r--r--tools/ark/round-outputs-check-test.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/ark/round-outputs-check-test.js b/tools/ark/round-outputs-check-test.js
new file mode 100644
index 0000000..da2dbbb
--- /dev/null
+++ b/tools/ark/round-outputs-check-test.js
@@ -0,0 +1,33 @@
+// A round's new coins are checked before we forfeit for them (bark !2803):
+// locked by our unlock hash, anchored in this round's transaction, paid to
+// our key, worth what we asked for. Any mismatch throws, so nothing is signed.
+// Run: bun tools/ark/round-outputs-check-test.js
+import assert from 'node:assert/strict';
+import { hex } from '@scure/base';
+import { sha256 } from '@noble/hashes/sha256';
+import { checkRoundOutputs } from '../../src/ark/refresh.js';
+
+const check = (name, ok, detail = '') => { assert(ok, name + (detail ? ' — ' + detail : '')); console.log(' ✓ ' + name); };
+const preimage = 'ab'.repeat(32), other = 'cd'.repeat(32);
+const ours = hex.encode(sha256(hex.decode(preimage)));
+const theirs = hex.encode(sha256(hex.decode(other)));
+const me = '02' + '11'.repeat(32), funding = 'f0'.repeat(32);
+const coin = ({ hash = ours, type = 'hashLockedCosigned', txid = funding, owner = me, sat = 50_000, unlock } = {}) => ({
+ id: 'c' + Math.random().toString(16).slice(2, 8) + ':0', amountSat: sat,
+ anchorPoint: { txid, vout: 0 }, policy: { type: 'pubkey', userPubkey: owner },
+ genesis: [{ transition: { type: 'cosigned' } }, { transition: { type, unlock: unlock || { hash } } }],
+});
+const opts = { unlockHash: ours, fundingTxid: funding, ownerPubkey: me, minTotalSat: 50_000 };
+const refuses = (vtxos, o, re) => { try { checkRoundOutputs(vtxos, o); return false; } catch (e) { return re.test(e.message); } };
+
+check('coins locked by our hash, in this round, to our key, as asked: accepted', (() => { checkRoundOutputs([coin()], opts); return true; })());
+check('...v0 leaves too, and two coins that add up', (() => { checkRoundOutputs([coin({ type: 'hashLockedCosigned_v0', sat: 20_000 }), coin({ sat: 30_000 })], opts); return true; })());
+check('...and a coin already carrying our preimage', (() => { checkRoundOutputs([coin({ unlock: { preimage } })], opts); return true; })());
+check('a coin locked by ANOTHER unlock hash: refused (the !2803 attack)', refuses([coin({ hash: theirs })], opts, /locked by unlock hash/));
+check('...even beside a good one', refuses([coin(), coin({ hash: theirs, sat: 1 })], opts, /locked by unlock hash/));
+check('a coin anchored in another transaction: refused', refuses([coin({ txid: 'ee'.repeat(32) })], opts, /anchored in/));
+check('a coin paid to someone else: refused', refuses([coin({ owner: '03' + '22'.repeat(32) })], opts, /not paid to our key/));
+check('less than we asked for: refused', refuses([coin({ sat: 49_999 })], opts, /49999 sat, 50000 were asked/));
+check('not a round leaf: refused', refuses([coin({ type: 'arkoor' })], opts, /not a hash-locked round leaf/));
+check('no coins at all: refused', refuses([], opts, /no coins/));
+console.log('\n✅ a round\'s coins are checked before we forfeit for them');