DeFiHardhatOracleProxyUpdates
100,000 USDC
View results
Submission Details
Severity: low
Invalid

`switchUnderlyingToken` is missing require check for balanceOfUnderlying equals to 0

Summary

The switchUnderlyingToken function within the LibUnripe library lacks a required check to ensure that s.u[unripeToken].balanceOfUnderlying is zero before allowing the underlying token to be switched. This omission could potentially lead to misuse of the function and violate the main invariant.

Impact

The absence of this check increases the risk of unintended behavior and could result in inconsistencies within the application's state. Developers or users may inadvertently call the function without ensuring that the balance of the underlying token is zero, which can lead to unexpected outcomes and compromise the integrity of the system.

PoC

The InitMigrateUnripeBean3CrvToBeanEth.sol[https://github.com/Cyfrin/2024-02-Beanstalk-1/blob/a3658861af8f5126224718af494d02352fbb3ea5/protocol/contracts/beanstalk/init/InitMigrateUnripeBean3CrvToBeanEth.sol#L22-L33] file calls LibUnripe.switchUnderlyingToken(C.UNRIPE_LP, C.BEAN_ETH_WELL); without the required check, despite being out of scope, potentially leading to unintended consequences.

Recommendations

It is recommended to add a require statement within the switchUnderlyingToken function to enforce the condition that s.u[unripeToken].balanceOfUnderlying must be zero before proceeding with the switch.

E.g new code should look like this:

/**
* @dev Switches the underlying token of an unripe token.
* Should only be called if `s.u[unripeToken].balanceOfUnderlying == 0`.
*/
function switchUnderlyingToken(address unripeToken, address newUnderlyingToken) internal {
AppStorage storage s = LibAppStorage.diamondStorage();
+ require(s.u[unripeToken].balanceOfUnderlying == 0, "Unripe: Underlying balance > 0");
s.u[unripeToken].underlyingToken = newUnderlyingToken;
emit SwitchUnderlyingToken(unripeToken, newUnderlyingToken);
}
Updates

Lead Judging Commences

giovannidisiena Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope
Assigned finding tags:

Informational/Invalid

Support

FAQs

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