diff options
| author | Adam Soltys <[email protected]> | 2026-08-04 08:31:21 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-08-04 08:31:21 -0700 |
| commit | 9fd8887dcdd5e0fc1067a91032bfd18eb25f0202 (patch) | |
| tree | 0ab3da2a80bb69a71139697852da646576f4f23f /src/ark/proto.js | |
| parent | 40c26324c556dc47be7e392391420183a36a6c3d (diff) | |
| download | coinosv3-9fd8887dcdd5e0fc1067a91032bfd18eb25f0202.tar.gz coinosv3-9fd8887dcdd5e0fc1067a91032bfd18eb25f0202.zip | |
Ark gifts go down to 1 sat; negative amounts can't OOM the encoder
Regtest-proven (tools/ark/dust-gift-test.js): the ASP cosigns all-dust
arkoor sends, so a sub-dust bearer vtxo sweeps to its claimer fine, and
dust folds into rounds alongside bigger siblings. The 330-sat gift
floor guarded a failure that can't happen — dropped to 1 sat.
The experiment also caught a live bug: refresh() of a balance smaller
than the round fee computed a negative output amount, and pbWriter's
varint sign-extends negatives into an infinite loop — auto-refresh
would OOM the tab of any wallet too small to renew. varint now throws
on negatives and refresh() refuses cleanly, before marking coins
pending, when balance minus fee is under the server's 330-sat output
minimum.
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015QwAtBSpKvECqp1rHLHjJk
Diffstat (limited to 'src/ark/proto.js')
| -rw-r--r-- | src/ark/proto.js | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/ark/proto.js b/src/ark/proto.js index 6729465..81651ee 100644 --- a/src/ark/proto.js +++ b/src/ark/proto.js @@ -29,6 +29,9 @@ export function pbWriter() { const chunks = []; const varint = (n) => { n = BigInt(n); + // a negative sign-extends under >>= forever — the do/while would push + // bytes until the process dies of memory, so refuse it loudly instead + if (n < 0n) throw new Error(`varint: negative value ${n}`); const bs = []; do { let b = Number(n & 0x7fn); n >>= 7n; if (n) b |= 0x80; bs.push(b); } while (n); chunks.push(Uint8Array.from(bs)); |
