Reentrancy in USDO.flashLoan() , enabling an attacker to borrow unlimited USDO exceeding the max borrow limit
The USDO flashLoan function lacked reentrancy protection, so a malicious receiver contract could re-enter it through the onFlashLoan callback. This let an attacker borrow an unlimited amount of USDO, exceeding the maximum borrow limit.
Submitted by zzzitron, also found by RedOneN, unsafesol, GalloDaSballo, kodyvim, ayeslick, andy, and dirk_y
Due to an reentrancy attack vector, an attacker can flashLoan an unlimited amount of USDO. For example the attacker can create a malicious contract as the receiver, to execute the attack via the onFlashLoan callback (line 94 USDO.sol).
The exploit works because USDO.flashLoan() is missing a reentrancy protection (modifier).
As a result an unlimited amount of USDO can be borrowed by an attacker via the flashLoan exploit described above.
Proof of Concept
Here is a POC that shows an exploit:
https://gist.github.com/zzzitron/a121bc1ba8cc947d927d4629a90f7991
To run the exploit add this malicious contract into the contracts folder:
https://gist.github.com/zzzitron/8de3be7ddf674cc19a6272b59cfccde1
Recommended Mitigation Steps
Consider adding some reentrancy protection modifier to USDO.flashLoan().
0xRektora (Tapioca) confirmed, but disagreed with severity and commented:
Should be
Highseverity, could really harm the protocol.
LSDan (Judge) increased severity to High
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the flashLoan function updates state or checks limits after invoking the receiver's callback, and no reentrancy guard prevents the callback from calling flashLoan again.
Impact
An attacker could borrow an unlimited amount of USDO, exceeding the maximum borrow limit, which the project confirmed could really harm the protocol.
What the attacker needed
Ability to deploy a malicious contract; USDO flashLoan callable
The fix
A reentrancy protection modifier should be added to USDO.flashLoan().
How it was found
- Deploy a malicious contract that acts as the flash loan receiver.
- Call USDO.flashLoan() with the malicious contract as the receiver.
- In the onFlashLoan callback, call flashLoan again to borrow beyond the limit.
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 report has not been written yet. The Original tab links to the source.
A flash loan is a loan that must be repaid within the same transaction. Here the loan function called back into the borrower's contract before finishing its own bookkeeping, and that contract could call the loan function again, so the limit was never properly enforced.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.