Skip to content
Business logic Audit finding Intermediate

Flash attack mitigation does not work as intended in USDV.sol

The USDV contract's flash attack mitigation relies on a blockDelay variable that is not initialised, defaulting to zero. This allows multiple calls within the same block, enabling flash loan attacks that the modifier was meant to prevent.

Vader Protocol contest

Originally disclosed on Code4rena

One of the stated protocol (review) goals is to detect susceptibility to “Any attack vectors using flash loans on Anchor price, synths or lending.” As such, USDV contract aims to protect against flash attacks using flashProof() modifier which uses the following check in isMature() to determine if currently executing contract context is at least blockDelay duration ahead of the previous context: lastBlock[tx.origin] + blockDelay <= block.number

However, blockDelay state variable is not initialized which means it has a default uint value of 0. So unless it is set to >= 1 by setParams() which can be called only by the DAO (which currently does not have the capability to call setParams() function), blockDelay will be 0, which allows current executing context (block.number) to be the same as the previous one (lastBlock[tx.origin]). This effectively allows multiple calls on this contract to be executed in the same transaction of a block which enables flash attacks as opposed to what is expected as commented on L41: ”// Stops an EOA from doing a flash attack in the same block”

Even if the DAO can call setParams() to change blockDelay to >= 1, there is a big window of opportunity for flash attacks until the DAO votes, finalizes and approves such a proposal. Moreover, such proposals can be cancelled by a DAO minority or replaced by a malicious DAO minority to launch flash attacks.

Recommend initalizing blockDelay to >= 1 at declaration or in constructor.

strictly-scarce (vader) confirmed:

The actual issue is simply:

blockDelay state variable is not initialized

It is intended to be initialised to 1, so this is a bug. Severity: 2

The original report as published on Code4rena. 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

Impact

This could allow flash loan attacks because multiple calls can be executed in the same block, bypassing the intended protection.

What the attacker needed

None

The fix

The blockDelay variable should be initialised to at least 1 at declaration or in the constructor.

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 smart contract has a safety check that is supposed to stop someone from making multiple transactions in the same block. But the setting that controls this check was never given a value, so it defaults to zero and the check does nothing. This means an attacker can use a flash loan to do several things in one transaction, which the contract was trying to block.

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.

More from Vader Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.