Users Might Not Be Able To Purchase Or Redeem SetToken
The SetToken's issue and redeem hooks call a function that redeems all matured fCash positions, and if any single redemption fails, the whole function reverts. This would block all issuance and redemption of the SetToken, leaving user funds stuck.
Originally disclosed on Code4rena
Submitted by xiaoming90, also found by berndartmueller
Proof of Concept
Whenever a setToken is issued or redeemed, the moduleIssueHook and moduleRedeemHook will be triggered. These two hooks will in turn call the _redeemMaturedPositions function to ensure that no matured fCash positions remain in the Set by redeeming any matured fCash position.
/**
* @dev Hook called once before setToken issuance
* @dev Ensures that no matured fCash positions are in the set when it is issued
*/
function moduleIssueHook(ISetToken _setToken, uint256 /* _setTokenAmount */) external override onlyModule(_setToken) {
_redeemMaturedPositions(_setToken);
}
/**
* @dev Hook called once before setToken redemption
* @dev Ensures that no matured fCash positions are in the set when it is redeemed
*/
function moduleRedeemHook(ISetToken _setToken, uint256 /* _setTokenAmount */) external override onlyModule(_setToken) {
_redeemMaturedPositions(_setToken);
}
The _redeemMaturedPositions will loop through all its fCash positions and attempts to redeem any fCash position that has already matured. However, if one of the fCash redemptions fails, it will cause the entire function to revert. If this happens, no one could purchase or redeem the setToken because moduleIssueHook and modileRedeemHook hooks will revert every single time. Thus, the setToken issuance and redemption will stop working entirely and this setToken can be considered “bricked”.
/**
* @dev Redeem all matured fCash positions for the given SetToken
*/
function _redeemMaturedPositions(ISetToken _setToken)
internal
{
ISetToken.Position[] memory positions = _setToken.getPositions();
uint positionsLength = positions.length;
bool toUnderlying = redeemToUnderlying[_setToken];
for(uint256 i = 0; i < positionsLength; i++) {
// Check that the given position is an equity position
if(positions[i].unit > 0) {
address component = positions[i].component;
if(_isWrappedFCash(component)) {
IWrappedfCashComplete fCashPosition = IWrappedfCashComplete(component);
if(fCashPosition.hasMatured()) {
(IERC20 receiveToken,) = fCashPosition.getToken(toUnderlying);
if(address(receiveToken) == ETH_ADDRESS) {
receiveToken = weth;
}
uint256 fCashBalance = fCashPosition.balanceOf(address(_setToken));
_redeemFCashPosition(_setToken, fCashPosition, receiveToken, fCashBalance, 0);
}
}
}
}
}
Impact
User will not be able to purchase or redeem the setToken. User’s fund will be stuck in the SetToken Contract. Unable to remove matured fCash positions from SetToken and update positions of its asset token.
Recommended Mitigation Steps
This is a problem commonly encountered whenever a method of a smart contract calls another contract – you cannot rely on the other contract to work 100% of the time, and it is dangerous to assume that the external call will always be successful.
It is recommended to:
- Consider alternate method of updating the asset position so that the SetToken’s core functions (e.g. issuance and redemption) will not be locked if one of the matured fCash redemptions fails.
- Evaluate if
_redeemMaturedPositionsreally need to be called during SetToken’s issuance and redemption. If not, consider removing them from the hooks, so that any issue or revert within_redeemMaturedPositionswon’t cause the SetToken’s issuance and redemption functions to stop working entirely. - Consider implementing additional function to give manager/user an option to specify a list of matured fCash positions to redeem instead of forcing them to redeem all matured fCash positions at one go.
ckoopmann (Index Coop) acknowledged, but disagreed with severity and commented:
The
_isWrappedFCash(component)should make sure that these calls are only executed on valid wrappedfCash instances deployed from the configured factory.The issue does not outline a practical scenario / test case where this issue would actually arise. If it did the manager could probably still remove / redeem the component either via this module, or one of the other Trade modules.
However I’ll have to look into this if I can find a scenario where this would actually arise. I will also consider making this redeem step optional, but I will have to think more about this as this might introduce other more serious issues.
@jeffywu Do you see any scenario where the redemption of a matured fCash position might fail in this context`?
EDIT: Just noticed that https://github.com/code-423n4/2022-06-notional-coop-findings/issues/226 mentions (among others) the scenario of USDC tokens being blocked which I guess is unlikely but outside of our control. This makes me think we might want to make the redemption of matured tokens during issuance / redemption optional.
ckoopmann (Index Coop) confirmed and commented:
Changed label from acknowledged to confirmed, since on second thought I think we likely want to adopt some kind of mitigation strategy for this. However still tentative / unclear which strategy we want to adopt.
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
Root cause
Likely the code assumes that an external call to redeem a matured fCash position will always succeed, and does not handle failures gracefully, causing the entire issuance/redemption to revert.
Impact
Users could be unable to purchase or redeem the SetToken, and their funds could become stuck in the contract.
What the attacker needed
A matured fCash position exists; redemption of that position fails
The fix
The report recommends making the redemption of matured fCash positions optional or removing it from the hooks, so that a failure does not block issuance and redemption.
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 called SetToken lets people buy (issue) and sell (redeem) shares. Before each buy or sell, it tries to clean up some expired positions, but if that cleanup fails for any reason, the whole buy or sell is cancelled. This means nobody can buy or sell, and their money is trapped.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.