Skip to content
Smart contracts Audit finding Intermediate

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.

zzzitron Follow with RedOneN, unsafesol and 5 others

Originally disclosed on Code4rena

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 High severity, could really harm the protocol.

LSDan (Judge) increased severity to High


The original report as published on Code4rena, by zzzitron. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Deploy a malicious contract that acts as the flash loan receiver.
  2. Call USDO.flashLoan() with the malicious contract as the receiver.
  3. 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.

More by zzzitron

View all

21 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.