Kava's lending module divides by how much is left in a market. Its one guard is for a market with exactly nothing in it. On November 14 somebody left two units in a dead stablecoin market, the division ran, and 53.9 million KAVA walked out. This bug has no CVE and never will. It is also the fifth time it has happened, and the code that does it is still deployed all over the place behind a settings page.
Kava Lend Guarded Against Zero. The Attacker Brought Two.
pattern
totalSupply := cash.Add(borrows).Sub(reserves)
if totalSupply.IsZero() {
return sdk.OneDec()
}
return (newInterest.Quo(totalSupply)).Add(sdk.OneDec())That is CalculateSupplyInterestFactor in x/hard/keeper/interest.go, the public source for Kava Lend. Every time interest accrues in a market, every depositor's balance in that market is multiplied by what this function returns: one, plus the new interest divided by the market's net supply.
Read the guard. If the market holds exactly zero, skip the division. If it holds two, divide by two.
The number underneath is one anyone can move
Net supply is cash plus borrows minus reserves. Cash is the module's token balance. Depositing raises it. Withdrawing lowers it. The module keeps a separate record of what depositors are owed, and this function does not use it.
The people who wrote the file knew the number could go bad. Thirty-five lines up, the utilisation function computes the same three-term sum and handles the case where it goes negative. The supply factor got the zero check and nothing else. The last change to the file that was not a dependency upgrade or a reformat was in 2021.
The dead market
BUSD is the Binance-branded dollar stablecoin. Its issuer stopped minting it in 2023. Kava Lend kept the market open and kept counting BUSD deposits as collateral at fifty cents on the dollar.
A dead market has almost no cash, old debt nobody is repaying, and reserves that keep growing on paper, because reserves are booked on interest that was charged, not interest that was paid. Its net supply drifts toward nothing without anyone touching it.
Then Kava started shutting the product down. A governance proposal submitted on September 28, and passed, ended incentives, capped borrowing near what was already outstanding, and told users to close their positions. Depositors left. The collateral setting stayed where it was.
Ninety-eight minutes
What follows is from the on-chain reconstructions by Bitquery and The Block. Kava has confirmed the outline: an accounting flaw inflated BUSD collateral, and KAVA was borrowed against it.
The BUSD market's net supply was brought down to two base units. Interest accrued against it. In three minutes the supply index went from about 2.76 to 671,187. Every BUSD deposit on the books was multiplied by that, including the one the attacker had placed. Bitquery puts its paper value at about 1.26 billion dollars.
A second wallet borrowed KAVA from the main pool against it. There was a cap on each loan. It took 127 loans. The pool went from about 55.33 million KAVA to about 0.19.
About 49.2 million KAVA left for BNB Chain over a bridge and was sold for roughly 2.09 million dollars. It had been worth 3.76 million before the sale started. Dumping fifty million of a token does that.
I read the market's state off Kava's public API on November 16. The index is 671,186.99. Cash is zero. Borrows are zero. Reserves are about 7,618 BUSD, so net supply is now negative. BUSD is still set as collateral at 0.50.
The fix is a number in a settings file
Kava says the vulnerability is blocked. Here is the block. The module has a parameter for the smallest loan it will write. On November 16 that parameter reads 1,000,000,000,000 US dollars. Borrowing is off because the minimum loan is a trillion dollars.
A proposal in voting now sets every borrow cap to zero and puts the minimum back to ten dollars.
The function at the top of this page has not changed in the public repository. The division is still there. What got closed is the cash register.
Four days earlier, the same module lost 23,500 ATOM
Nobody has reported this one.
Kava Lend's ATOM market carried a shortfall of 11.30 ATOM between what it held and what it owed depositors. That figure did not move from at least August until 05:52:31 UTC on November 10.
By 10:26:28 UTC the same morning the market was short by 23,532 ATOM. It settled at 23,492.86 ATOM. It read 23,492.86 before the November 14 drain, after it, and today. The drain everybody wrote about did not touch it.
I read those figures myself, from the chain's state at each block height: the module's ATOM balance, total borrows, reserves, and total booked deposits.
The first block of the gap holds one transaction, 92B6BCBE…748597. It carries 111 messages: 18 deposits, 36 borrows, 18 liquidations, 36 auction bids, two swaps and a transfer. Its memo begins atomctl-seed-.
ATOM's interest index never jumped. This is not the BUSD bug. It is a second way to make this module pay out more than it writes down, through liquidations and auctions, and it ran for four and a half hours on a Tuesday morning during the wind-down. I measured it. I did not take it apart, and I have not tied that address to the wallets from November 14.
So the timeline is not one bad morning. Bitquery and The Block both report activity in the BUSD market from about November 8. The ATOM leak ran on November 10. The KAVA drain was November 14. Somebody worked on this module for most of a week.
This is the fifth time
- April 2023, Hundred Finance, about 7 million dollars. An empty market.
- November 2023, Onyx, about 2.1 million. A market a few days old. Onyx was hit again later through the same bug.
- January 2024, Radiant, about 4.5 million. A market seconds old.
- May 2024, Sonne, about 20 million. A newly added market.
- November 2026, Kava Lend. A dead market.
The code differs each time and the shape does not. A market holds almost nothing. A multiplier for that market is worked out by dividing by how much is in it. Someone makes that number tiny, the multiplier explodes, and the inflated position borrows a different asset that is real.
The first four were new markets, and the industry wrote a rule for new markets: seed them before you list them. Kava's was an old market on its way out. Nobody seeds a market on the way down.
This site has a folder for that: Design Debt Driver. A component whose bug keeps coming back because every fix goes around it. Seventy case files are in it.
The code is still deployed and a setting is holding it shut
After reading Kava I went looking for the same condition elsewhere: an empty or nearly empty market, still counted as collateral, on code with no floor under the division. Roughly two thousand lending reserves across Aave-style forks and about 260 Compound-style comptrollers, read straight off the chains on November 16.
No market I found can be drained today. That is the good news and it is thin.
Radiant is the protocol in the January 2024 line above. On Ethereum, right now, its sUSDe reserve has a supply of zero, is enabled as collateral at 72 percent, is active, and is not frozen. I read that from the pool contract. What stands in front of it is a borrow cap of one token on every asset in the pool that can be borrowed. I read that too. A setting.
That is the pattern in every case I found. The division is live. An empty market still counts as collateral. A borrow cap, a pause flag or a freeze is the only thing in the way. Those are changed by governance votes and admin keys, by people who do not know what the setting is holding shut. Kava's own shutdown vote is the proof.
There is a list. It is not in this post. A list of doors is a list of doors.
And it has been used more than five times. A reserve that has been through this carries a mark: an interest index thousands or billions of times normal, on a few base units of supply. MahaLend's USDC reserve on Ethereum reads about 31.9 billion times normal. Granary's WBTC reserve on Ethereum reads 9,922 times normal. I read both. The sums taken were small because the pools were small. Almost none of it was written up.
How to shut a lending market without getting robbed
The teams that do this well do it in one order. Collateral factor to zero first. Borrowing off. Then tell depositors to leave.
Kava told depositors to leave and left the collateral on.
The next one
The next drain of this kind is a market for a deprecated asset, not a new listing. It is in a protocol that has announced a wind-down or stopped shipping. The collateral factor on the emptied market is above zero on the day it happens. The post-mortem says a cap was in place.
You guarded the division against zero. Nobody was ever going to bring you zero.