Skip to content
Business logic Audit finding Intermediate

Mismatch in withdraw() between Yearn and other protocols can prevent Users from redeeming zcTokens and permanently lock funds

The withdraw function in Swivel.sol treats the amount parameter as underlying assets, but Yearn's withdraw expects shares, causing either a revert or excess assets being withdrawn and permanently locked. An attacker could exploit this to prevent users from redeeming zcTokens or lock funds in the contract.

scaraven Follow

Originally disclosed on Code4rena

Submitted by scaraven, also found by Franfran

As defined in the docs for Euler, ERC4626, Compound and Aave, when withdrawing and depositing funds the amount specified corresponds excactly to how many of the underlying assets are deposited or withdrawn.

However, as specified by Yearn, the yearn withdraw amount parameter specifies how many shares are burnt instead of underlying assets retrieved. Two scenarios can occur from then on, if there are not enough shares then the transaction will revert and users will not be able to redeem the underlying assets from Yearn. If there are enough shares, then a higher number of assets will be withdrawn then expected (as assets per share will only increase). This means that once the user receives their underlying assets at a 1:1 peg the excess amounts will be permanently locked in the vault contract.

Proof of Concept

All scenarios use Yearn finance as the protocol, the other protocols are unaffected.

Scenario #1

  1. A yearn finance vault contains 50 shares and 200 uTokens all owned by Swivel.sol
  2. A user opens a zcToken position and deposits 100 uTokens into yearn receiving 100 zcTokens (and possibly a premium)
  3. 100 / 200 * 50 = 25 shares are minted for the vault so we now have 75 shares and 300 uTokens in the yearn vault
  4. After maturity is achieved, the user tries to redeem their 100 zcTokens for uTokens
  5. The swivel.sol contract tries to withdraw the 100 uTokens, it instead withdraws 100 shares which is less than available so the transaction reverts and the user cannot withdraw all of their 100 uTokens and instead can only withdraw 75 uTokens.

Scenario #2

  1. A yearn finance vault contains 50 shares and 100 uTokens all owned by Swivel.sol
  2. A user opens a zcToken position and deposits 100 uTokens into yearn receiving 100 zcTokens (and possibly a premium)
  3. 100 / 100 * 50 = 50 shares are minted for the vault so we now have 100 shares and 200 uTokens in the yearn vault
  4. After maturity is achieved, the user tries to redeem their 100 zcTokens for uTokens
  5. The contract tries to retrieve 100 uTokens but instead withdraws 100 shares which corresponds to 200 uTokens
  6. User receives their 100 uTokens causing 100 uTokens to be left in the Swivel.sol contract which are now irretrievable
  7. If any user tries to withdraw their funds then the transaction will fail as no shares are left in the yearn vault

Tools Used

VS Code

Recommended Mitigation Steps

In the withdraw() function in Swivel.sol, calculating the price per share and use that to retrieve the correct number of underlying assets e.g.

uint256 pricePerShare = IYearnVault(c).pricePerShare();
return IYearnVault(c).withdraw(a / pricePerShare) >= 0;

JTraversa (Swivel) commented:

Duplicate of #30.

scaraven (warden) commented:

I do not understand how this is a duplicate of #30, #30 talks about a problem with redeemUnderlying() in Compound while this issue talks about a problem with withdraw() when using yearn.

JTraversa (Swivel) commented:

They both cannot be true at once however. Either the lib expects shares, or the lib expects assets. His suggestion notes inconsistency and recommends changing the compound redeem to align with yearn, while you note the inconsistency and recommend fixing the yearn math. At the end of the day the issue is the “mismatch”.

scaraven (warden) commented:

Fair enough, that makes sense. I would still disagree with their interpretation of the issue, it is clear from the code that a represents the underlying assets. If a does represent the number of shares then other functions such as authRedeemzcTokens would be plain wrong because it would be redeeming each zcToken as if it was one share not one underlying asset.

JTraversa (Swivel) commented:

Yeah I actually kind of agree with you. We intended the implementation to align more with your finding.

That said it might be worth a judge’s input.

If they think they’re different, the other finding is invalid/should be disputed and this one is correct.

bghughes (judge) commented:

Confirmed, good issue and marked #30 as a duplicate.

robrobbins (Swivel) resolved:

Addressed: https://github.com/Swivel-Finance/gost/pull/437.


The original report as published on Code4rena, by scaraven. 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 withdraw function in Swivel.sol passes the underlying asset amount directly to Yearn's withdraw, which expects a share amount, causing a mismatch.

Impact

Users may be unable to redeem their zcTokens fully, and excess assets could be permanently locked in the contract, potentially blocking all withdrawals if shares are exhausted.

What the attacker needed

Yearn vault used as underlying; User has zcTokens to redeem

The fix

The withdraw function should calculate the price per share and use that to retrieve the correct number of underlying assets.

How it was found

  1. A Yearn vault contains 50 shares and 200 uTokens owned by Swivel.sol.
  2. A user deposits 100 uTokens into Yearn and receives 100 zcTokens.
  3. 25 shares are minted for the vault, resulting in 75 shares and 300 uTokens.
  4. After maturity, the user tries to redeem 100 zcTokens for uTokens.
  5. Swivel.sol tries to withdraw 100 uTokens but instead withdraws 100 shares, which is less than available, so the transaction reverts and the user can only withdraw 75 uTokens.

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.

When you withdraw from a savings account, you usually say how much money you want back. But some savings accounts (like Yearn) ask how many 'shares' of the account you want to burn instead. Swivel's code assumed the first way, so it asked for the wrong thing. This could make withdrawals fail or take too much, leaving extra money stuck forever.

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 scaraven

View all

6 more disclosed reports, best first.

More from Swivel v3 contest

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.