Hack Analysis The Hundred Finance Heist March 2022
Hundred Finance, a Compound fork on Gnosis Chain, sent borrowed tokens before updating the borrower's debt, and the bridged tokens triggered a callback on transfer. An attacker used that callback to reenter the protocol and borrow again before the first debt was recorded, draining about $6m of liquidity.
immunefi.com
Published on immunefi.com
Hundred Finance and Agave, lending protocols on the Gnosis Chain, were hit by reentrancy attacks on March 15 this year. These attacks drained the protocols of all collateral.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The protocol transferred borrowed tokens before updating the borrower's debt, and the non-standard bridged token invoked a callback on the recipient during that transfer, allowing reentrancy.
Impact
The attacker drained about $6m of available liquidity from Hundred Finance's Gnosis deployment, as the text states the attack drained the protocols of all collateral.
What the attacker needed
Gnosis Chain deployment; bridged tokens with transfer callback; flash loan capital available
The fix
The text does not state a specific fix but implies that following the checks-effects-interactions pattern and using reentrancy guards would prevent the issue.
How it was found
- Take a flash loan of USDC from a SushiSwap pair.
- Deposit the borrowed USDC as collateral in Hundred Finance's USDC market.
- Borrow USDC against that collateral.
- When the borrowed USDC transfer triggers the token callback, reenter and borrow xDai from another market before the debt is recorded.
- Swap the xDai for USDC on Curve.
- Repay the flash loan with its fee and keep the remaining USDC as profit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A lending protocol lets you deposit collateral and borrow other tokens against it. Here, the protocol handed over the borrowed tokens before writing down that you owed them, and the token itself called back into the attacker's contract during that handover. The attacker used that moment to borrow again, so the protocol lost track of how much was owed and was drained.