Infinite Leverage — Python Bug Hunt
Inspired by the 2019 "infinite money" exploit where a brokerage's margin math counted borrowed money as collateral for borrowing more.
- Language: Python
- Layer: Backend
- Difficulty: Hard
- Concepts: Finance, Validation
- Modelled on: Robinhood · 2019
- Visible tests: settled cash gets 2x leverage; pending deposits add nothing; borrowed funds reduce buying power
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2
- Time to fix: 35 minutes, the target for a hard incident
Failing checks on the shipped build
- pending deposits add nothing — expected 4000 but got 104000
- borrowed funds reduce buying power — expected 3000 but got 6000
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the 2019 "infinite money" exploit where a brokerage's margin math counted borrowed money as collateral for borrowing more. Users looped it into six-figure positions on a $2,000 deposit.
margin.py computes buying power. Three inputs, one rule each — all three are wrong.
Bug report
BUG-∞-LEV · Priority: Existential · Reported by: clearing
buying_power(account) with 2x leverage:
- settled_cash counts at 2x
- pending deposits count at ZERO (not settled!)
- borrowed funds SUBTRACT from buying power, never add
account = {"settled_cash": c, "pending": p, "borrowed": b}
Observed: pending and borrowed both counted at 2x — deposit, borrow, repeat.
Logs
[margin] settled=2000 pending=50000 borrowed=48000 -> power=200000 (!!)The code as shipped
src/broker/margin.py (editable)
# Computes buying power for a margin account.
LEVERAGE = 2
def buying_power(account):
total = account["settled_cash"] + account["pending"] + account["borrowed"]
return total * LEVERAGE
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.