SDK fromMicro renders negative amounts as garbage strings
Report
Summary
fromMicro is the SDK display helper that turns a micro-unit bigint into a six-decimal XE or XUSD string for wallets, quotes, and refunds. At sdk/src/types.ts:144-147 it splits the bigint with JS remainder into whole and frac, then concatenates them as ${whole}.${frac}, and JS remainder keeps the sign of the dividend so minus 100n modulo 1000000n is minus 100n. The minus therefore lands inside the decimal string: fromMicro(-100n) is 0.00-100 and fromMicro(-100500000n) is minus 100.-500000, while a positive 1500000n still formats as 1.500000. Any SDK caller that prints a signed settlement, refund, or negative quote hits this formatter. GitHub #43 is swap unwind; this is display-only corruption in the SDK formatter.
Affected components
sdk/src/types.ts:144-147 fromMicro (JS remainder sign on frac, then whole.frac concatenate) at sdk 0dbc92ecff709bee79768e4e37788c682a0f4525.
Impact
Any negative XE or XUSD amount the SDK prints is unreadable (0.00-100 and minus 100.-500000). Positive amounts still format as 1.500000. Display integrity only; on-chain amounts are unaffected, but a user reading a negative settlement or refund cannot recover the true value from the string.
PoC
#!/usr/bin/env node
/** A3 — fromMicro corrupts negative amounts. */
import { fromMicro, toMicro } from './sdk.mjs'
const PIN = '0dbc92ecff709bee79768e4e37788c682a0f4525'
console.log(`PROVENANCE: sdk=${PIN} file=poc/round3/a3_frommicro.mjs`)
const ctrl = fromMicro(1_500_000n)
console.log(`CONTROL fromMicro(1500000n)=${ctrl}`)
const roundTrip = fromMicro(toMicro('1.500000'))
console.log(`CONTROL toMicro/fromMicro('1.500000')=${roundTrip}`)
const cases = [-100n, -100_500_000n, -1n, -1_000_000n]
for (const n of cases) {
const s = fromMicro(n)
const looksDecimal = /^-?\d+\.\d{6}$/.test(s) && !s.includes('-', 1)
console.log(`ATTACK fromMicro(${n})=${JSON.stringify(s)} well_formed=${looksDecimal}`)
}
const a = fromMicro(-100n)
const b = fromMicro(-100_500_000n)
const aBad = a.includes('-', 1) || a.startsWith('0.-') || /[.]-/.test(a) || !/^-?\d+\.\d+$/.test(a)
const bBad = b.includes('-', 1) || /[.]-/.test(b) || b.split('.').length !== 2 || (b.startsWith('-') && b.indexOf('-', 1) >= 0)
const corrupted = aBad || bBad || a === '0.00-100' || a.includes('00-') || b.includes('.-')
if (ctrl === '1.500000' && corrupted) {
console.log(`PASS: fromMicro(-100n)=${JSON.stringify(a)} fromMicro(-100500000n)=${JSON.stringify(b)} CONTROL=${ctrl}`)
console.log('VERDICT=CONFIRMED')
process.exit(0)
}
console.log(`KILL: ctrl=${ctrl} a=${a} b=${b} corrupted=${corrupted}`)
console.log('VERDICT=KILLED')
process.exit(0)
ATTACK fromMicro(-100)="0.00-100" well_formed=false
ATTACK fromMicro(-100500000)="-100.-500000" well_formed=false
PASS: fromMicro(-100n)="0.00-100" fromMicro(-100500000n)="-100.-500000"
Suggested fix
Take the sign once from the whole amount, format abs(whole) and abs(frac) as six-decimal digits, and prefix a single minus when the input is negative.
Thread
Thanks. This is the same finding as an earlier report that is not public, 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-0932 and says what differs; it is read like any other.