marginfi
A new account transfer function in marginfi's Solana smart contract did not check whether the source account was in a flash loan. An attacker could start a flash loan, borrow funds, transfer the liabilities to a new account, end the loan on the now-empty original account, and keep the borrowed funds without repaying.
blog.asymmetric.re
Published on blog.asymmetric.re
This post details a critical vulnerability and team-implemented solution in the flash loan functionality of marginfi, a popular Solana-based DeFi project. At the time, the platform managed over $160M in deposits.
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
Impact
An attacker could keep the borrowed funds without repaying, potentially draining the protocol's available liquidity; the text does not state a specific amount but notes over $160M in deposits at the time.
What the attacker needed
A Solana transaction; a healthy marginfi account; ability to call marginfi instructions
How it was found
- Start a flash loan on a healthy MarginfiAccount A using lending_account_start_flashloan.
- Borrow the maximum available funds and transfer them to an attacker-controlled address.
- Call transfer_to_new_account to move the outstanding liabilities from A to a new account B.
- End the flash loan on A with lending_account_end_flashloan.
- Never repay the borrowed funds.
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 flash loan is a loan that must be borrowed and repaid within one transaction; if repayment fails, the whole transaction is undone. Marginfi added a way to move an account's balances to a new account, but forgot to block this move while a flash loan was active. This let an attacker move the debt away, end the loan on the emptied account, and walk away with the borrowed money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.