Skip to content
Business logic Audit finding Intermediate

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.

hickuphh3 Follow

Originally disclosed on Code4rena

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:

  • _yieldSource has a deposit token of WETH (18 decimals)
  • _currentYieldSource has a deposit token of DAI (18 decimals)
  • 1 WETH > 1 DAI (definitely true, I’d be really sad otherwise)

Attacker does the following:

  1. Deposit 100 DAI into the swappable yield source contract

  2. Call transferFunds(_yieldSource, 100 * 1e18)

    • _requireDifferentYieldSource() passes

    • _transferFunds(_yieldSource, 100 * 1e18) is called

      • _yieldSource.redeemToken(_amount); → This will transfer 100 WETH out of the _yieldSource into the contract
      • uint256 currentBalance = IERC20Upgradeable(_yieldSource.depositToken()).balanceOf(address(this)); → This will equate to ≥ 100 WETH.
      • require(_amount <= currentBalance, "SwappableYieldSource/transfer-amount-different"); is true since both are 100 * 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

  3. 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 transferFunds function but now that we have removed it and funds can only be moved by swapYieldSource(), this exploit is no longer possible since we check for the same depositToken in _setYieldSource().

https://github.com/pooltogether/swappable-yield-source/pull/4

0xean (Judge) commented:

Upgrading to 3 considering the potential for loss of funds

The original report as published on Code4rena, by hickuphh3. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Deposit 100 DAI into the swappable yield source contract.
  2. Call transferFunds with the target yield source and the amount.
  3. The function redeems the amount from the target yield source, transferring WETH to the contract.
  4. It then supplies the deposited DAI to the current yield source.
  5. 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.

More by hickuphh3

View all

43 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.