SwappableYieldSource : Missing same deposit token check in transferFunds()
The transferFunds function did not verify that the source and destination yield sources used the same deposit token, allowing a privileged user to redeem a more valuable token from one source and supply a less valuable token to the other, pocketing the difference. An attacker with owner or asset manager privileges could exploit this to steal funds.
Submitted by hickuphh3, also found by 0xRajeev
transferFunds() will transfer funds from a specified yield source _yieldSource to the current yield source set in the contract _currentYieldSource. However, it fails to check that the deposit tokens are the same. If the specified yield source’s assets are of a higher valuation, then a malicious owner or asset manager will be able to exploit and pocket the difference.
Assumptions:
_yieldSourcehas a deposit token of WETH (18 decimals)_currentYieldSourcehas a deposit token of DAI (18 decimals)- 1 WETH > 1 DAI (definitely true, I’d be really sad otherwise)
Attacker does the following:
-
Deposit 100 DAI into the swappable yield source contract
-
Call
transferFunds(_yieldSource, 100 * 1e18)-
_requireDifferentYieldSource()passes -
_transferFunds(_yieldSource, 100 * 1e18)is called_yieldSource.redeemToken(_amount);→ This will transfer 100 WETH out of the_yieldSourceinto the contractuint256 currentBalance = IERC20Upgradeable(_yieldSource.depositToken()).balanceOf(address(this));→ This will equate to ≥ 100 WETH.require(_amount <= currentBalance, "SwappableYieldSource/transfer-amount-different");is true since both are100 * 1e18_currentYieldSource.supplyTokenTo(currentBalance, address(this));→ This supplies the transferred 100 DAI from step 1 to the current yield source
-
We now have 100 WETH in the swappable yield source contract
-
-
Call
transferERC20(WETH, attackerAddress, 100 * 1e18)to withdraw 100 WETH out of the contract to the attacker’s desired address.
_requireDifferentYieldSource() should also verify that the yield sources’ deposit token addresses are the same.
function _requireDifferentYieldSource(IYieldSource _yieldSource) internal view {
require(address(_yieldSource) != address(yieldSource), "SwappableYieldSource/same-yield-source");
require(_newYieldSource.depositToken() == yieldSource.depositToken(), "SwappableYieldSource/different-deposit-token");
}
PierrickGT (PoolTogether) acknowledged:
This exploit was indeed possible when we had the
transferFundsfunction but now that we have removed it and funds can only be moved byswapYieldSource(), this exploit is no longer possible since we check for the samedepositTokenin_setYieldSource().https://github.com/pooltogether/swappable-yield-source/pull/4
Upgrading to 3 considering the potential for loss of funds
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 function _requireDifferentYieldSource only checked that the two yield sources were different addresses, not that their deposit tokens matched.
Impact
A malicious owner or asset manager could steal funds by exploiting the token value difference; the function was later removed, eliminating the vulnerability.
What the attacker needed
Attacker is owner or asset manager; two yield sources with different tokens
The fix
The function was removed and replaced with swapYieldSource, which checks for the same deposit token.
How it was found
- Deposit 100 DAI into the swappable yield source contract.
- Call transferFunds with the target yield source and the amount.
- The function redeems the amount from the target yield source, transferring WETH to the contract.
- It then supplies the deposited DAI to the current yield source.
- Finally, withdraw the WETH from the contract to the attacker's address.
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 yield source is like a savings account that holds a specific type of token. The contract allowed moving funds between two such accounts without checking they held the same token, so someone with special permissions could take valuable tokens from one account and replace them with less valuable ones, keeping the difference.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.