Satoshis, Not Doubles — Java Bug Hunt
Inspired by the precision bugs that plague crypto exchanges: parse "0.29" of a coin through a double, multiply by 10^8, truncate — and you just destroyed…
- Language: Java
- Layer: Database
- Difficulty: Medium
- Concepts: Floating Point, Money
- Modelled on: Crypto exchanges
- Visible tests: the classic drift case is exact; whole coins are exact; full 8-decimal precision survives
- Reward: 50 XP for a complete fix
Briefing
Inspired by the precision bugs that plague crypto exchanges: parse "0.29" of a coin through a double, multiply by 10^8, truncate — and you just destroyed one satoshi. Multiply that by a million trades a day.
AmountParser.java converts a decimal string into satoshis (8 decimal places). It must use integer math end to end.
Bug report
BUG-1SAT · Priority: High · Reported by: reconciliation
parseToSatoshis(amount) — up to 8 decimal places:
- "0.29" -> 29000000
- "1" -> 100000000
- "123.45678901"-> 12345678901
Observed: "0.29" parses to 28999999. The books never balance.
Logs
[ledger] daily reconciliation drift: -412 satThe code as shipped
AmountParser.java (editable)
class AmountParser {
// Parses a decimal coin amount (max 8 dp) into satoshis.
static long parseToSatoshis(String amount) {
double value = Double.parseDouble(amount);
return (long) (value * 100000000);
}
}Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More Java bug hunts.