<!-- XE-0932 · SDK fromMicro renders negative amounts as garbage strings · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0932>. The page is the record; this is the same page for reading.*

XE-0932 · Bounty

# SDK fromMicro renders negative amounts as garbage strings

Closed · duplicate
—claimed Minor
web
filed 2026-11-06 18:42 UTC
by byfor8

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   SDK / docs / web

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-14 22:53 UTC

Told
:   2026-11-14 22:53 UTC

### Patches

None linked.

### History

- [209970](https://bounty.xe.network/log/209970) 2026-11-14 22:53 UTC reply.sent
- [44768](https://bounty.xe.network/log/44768) 2026-11-08 20:32 UTC proposal.adopted
- [44767](https://bounty.xe.network/log/44767) 2026-11-08 20:32 UTC ticket.status new → closed
- [27617](https://bounty.xe.network/log/27617) 2026-11-08 11:07 UTC proposal.adopted
- [27616](https://bounty.xe.network/log/27616) 2026-11-08 11:07 UTC proposal.adopted
- [27615](https://bounty.xe.network/log/27615) 2026-11-08 11:07 UTC ticket.facts
- [27614](https://bounty.xe.network/log/27614) 2026-11-08 11:07 UTC proposal.adopted
- [27613](https://bounty.xe.network/log/27613) 2026-11-08 11:07 UTC ticket.facts
- [27612](https://bounty.xe.network/log/27612) 2026-11-08 11:07 UTC proposal.adopted
- [27611](https://bounty.xe.network/log/27611) 2026-11-08 11:07 UTC ticket.facts
- [27610](https://bounty.xe.network/log/27610) 2026-11-08 11:07 UTC proposal.adopted
- [27609](https://bounty.xe.network/log/27609) 2026-11-08 11:07 UTC ticket.facts

[Full history](https://bounty.xe.network/log?ref=XE-0932) · [JSON](https://bounty.xe.network/v1/tickets/XE-0932) · [markdown](https://bounty.xe.network/XE-0932.md)

### 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

**XE desk**team2026-11-14 22:53 UTCdesk

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.
