The Standard

The Standard
DeFiHardhat
20,000 USDC
View results
Submission Details
Severity: medium
Valid

Completely swaps can revert due to difference in pricing mehods

Summary

The contract implements a swap function which allows users to swap out some of their collateral tokens to other ones. The calculateMinimumAmountOut calculates the minimum amount that must be expected from the swap in order to stay solvent. We see the issue in the following line.

uint256 collateralValueMinusSwapValue = euroCollateral() -
calculator.tokenToEur(getToken(_inTokenSymbol), _amount);

Here we see the swap value is calculated using the function tokenToEur. However the euroCollateral function is implemented differently as shown.

for (uint256 i = 0; i < acceptedTokens.length; i++) {
ITokenManager.Token memory token = acceptedTokens[i];
euros += calculator.tokenToEurAvg(
token,
getAssetBalance(token.symbol, token.addr)
);
}

Here the price is calculated from a time weighted average. The issue is that if this average price is lower than the current price used in the tokenToEur
function, then the euroCollateral value can be lower than the tokenToEur value, reverting the swap. So users trying to swap out all of their collateral will be facing failed transactions.

Vulnerability Details

Due to the difference in pricing methogs, swpas utilizing the full collateral value can revert.

Impact

Broken swap functionality in the vaults

Tools Used

Manual Review

Recommendations

Either use tokenToEurAvg in both places, or use tokenToEur in both places.

Updates

Lead Judging Commences

hrishibhat Lead Judge almost 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

chainlink-minanswer

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

chainlink-minanswer

carrotsmuggler Submitter
over 1 year ago
hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

avg-spot-price

hrishibhat Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

avg-spot-price

Support

FAQs

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