Possibility to drain SavingsAccount contract assets #41
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Handle
kemmio
Vulnerability details
Impact
A malicious actor can manipulate switchStrategy() function in a way to withdraw tokens that are locked in SavingsAccount contract
(the risk severity should be reviewed)
Proof of Concept
Firstly an attacker need to deploy a rogue strategy contract implementing IYield.getSharesForTokens() and IYield.unlockTokens() functions
and calling switchStrategy() with _currentStrategy = ROGUE_CONTRACT_ADDRESS (_newStrategy can be any valid strategy e.g. NoYield)
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L160
Bypass this check by setting _amount > 0, since it will be overwritten in line
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L162
getSharesForTokens() should be implemented to always return 0, hence to bypass the overflow in lines
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L164-L167
since balanceInShares[msg.sender][_token][_currentStrategy] == 0 and 0-0 will not overflow
The actual amount to be locked is saved in line
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L169
the rouge unlockTokens() can check asset balance of the contract and return the full amount
After that some adjustment are made to set approval for the token or to handle native assets case
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L171-L177
Finally the assets are locked in the locked strategy and shares are allocated on attackers acount
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L179-L181
Proof of Concept
Tools Used
Recommended Mitigation Steps
Add a check for _currentStrategy to be from strategy list like the one in line
https://github.com/code-423n4/2021-12-sublime/blob/main/contracts/SavingsAccount/SavingsAccount.sol#L159
The text was updated successfully, but these errors were encountered: