The _setYieldSource function of SwappableYieldSource calls the safeApprove function to approve the yield sources with the maximum allowance of transferring underlying tokens. However, according to OpenZeppelin's implementation, the safeApprove function succeeds only if the current allowance is zero or the allowance to be set is zero (see the following link).
As a result, a yield source cannot be set twice by the contract. For example, set A -> set B -> set A is not possible since A's allowance is non-zero in the second "set A", causing the transaction to revert.
Handle
shw
Vulnerability details
Impact
The
_setYieldSource
function ofSwappableYieldSource
calls thesafeApprove
function to approve the yield sources with the maximum allowance of transferring underlying tokens. However, according to OpenZeppelin's implementation, thesafeApprove
function succeeds only if the current allowance is zero or the allowance to be set is zero (see the following link).As a result, a yield source cannot be set twice by the contract. For example, set A -> set B -> set A is not possible since A's allowance is non-zero in the second "set A", causing the transaction to revert.
Proof of Concept
Referenced code: SwappableYieldSource.sol#L259
OpenZeppelin - SafeERC20.sol#L52-L55
Recommended Mitigation Steps
Use
safeIncreaseAllowance
to increase the allowance to the maximum instead.