DeFiHardhat
35,000 USDC
View results
Submission Details
Severity: medium
Valid

Lack of else condition in `getWstethEthPrice`, no value will be return

Summary

There is an issue in the getWstethEthPrice function, the absence of an else condition at the end of the if statement block will lead to returning nothing at the end. In simple words, this means that if the condition within the if statement (LibOracleHelpers.getPercentDifference(chainlinkPrice, uniswapPrice) < MAX_DIFFERENCE) evaluates to false, the function will exit without returning a value.

Impact

Without an else condition, the function may terminate abruptly without providing any meaningful output if the condition in the if statement is not met. This can lead to unpredictable behavior, making it difficult to determine why the function failed to produce a result.

For example if someone calls getWstethEthPrice or this is called internally in a function for returning the wstETH/USD price with the option of using a TWA lookback. And the if condition fails so this will return no value to the user or any function calling it will get no value in return.

Recommendation

Add an else condition at the end of the if statement block to handle cases where the condition is not met. This could involve returning a default value or triggering an error to indicate that the function was unable to compute a valid price.

For example, new code will look like this:

if (LibOracleHelpers.getPercentDifference(chainlinkPrice, uniswapPrice) < MAX_DIFFERENCE) {
// Calculation logic...
} else {
// Handle case where condition is not met
// For example, return a default value or trigger an error
return 0; // Or trigger a revert with an error message
}
Updates

Lead Judging Commences

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

wstETH:ETH price max difference

Support

FAQs

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