DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: medium
Invalid

Shorts with price difference bigger than 1% can Match

Summary

In the docs it is said that shorts and bids with a price difference greater than 1% from oracle price should revert, however this is not the case.

Vulnerability Details

"price is within 1% of the actual oracle price at that moment. If it's below the oracle price, or over 1% of the oracle price, the transaction will fail."

This mechanism is intended to ensure that the asset maintains its peg. However, upon examination of the code, it becomes apparent that if the only available short is priced greater than the oracle price by 1%, the transaction still proceeds without reversion.

//_updateOracleAndStartingShort
bool startingShortWithinOracleRange = shortPrice
<= oraclePrice.mul(1.01 ether)
&& s.shorts[asset][prevId].price >= oraclePrice;
@> bool isExactStartingShort = shortPrice >= oraclePrice
&& s.shorts[asset][prevId].price < oraclePrice;
bool allShortUnderOraclePrice = shortPrice < oraclePrice
&& s.shorts[asset][shortHintId].nextId == Constants.TAIL;
...
if (startingShortWithinOracleRange || isExactStartingShort) {
//@dev only consider the x% above oraclePrice if there are prev Shorts with price >= oraclePrice
s.asset[asset].startingShortId = shortHintId;
return;

The _updateOracleAndStartingShort function will be called through the updateOracleAndStartingShortViaThreshold while the _createBid function is being executed.

Impact

If minted too high from the oracle price the asset could lose its peg.

Tools Used

Manual review

Recommendations

Implement a mechanism to exclude shorts from being matched if their price deviates by more than 1% from the oracle's price.

bool startingShortWithinOracleRange = shortPrice <= oraclePrice.mul(1.01 ether)
&& s.shorts[asset][prevId].price <= oraclePrice.mul(1.01 ether);
bool isExactStartingShort = shortPrice >= oraclePrice
&& shortPrice <= oraclePrice.mul(1.01 ether)
&& s.shorts[asset][prevId].price >= oraclePrice
&& s.shorts[asset][prevId].price <= oraclePrice.mul(1.01 ether);
Updates

Lead Judging Commences

0xnevi Lead Judge
almost 2 years ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.