Skip to content
Business logic Audit finding Intermediate

Lack of slippage check while interacting with ERC4626 Vault in PositionAction4626 could lead to users’ fund loss

The PositionAction4626 contract deposits into or redeems from an ERC4626 vault without checking the exchange rate, so users could receive fewer shares or assets than expected if the rate changes or is manipulated while their transaction is pending. This could lead to fund loss.

nnez Follow

Originally disclosed on Code4rena

Submitted by nnez

Users’ funds loss from ERC4626 exchange rate change or manipulated.

Proof of Concept

If users specify collateralParams.targetToken as ERC4626’s underlying token, PositionAction4626 will attempt to deposit the targetToken to ERC4626 vault in order to retrieve the collateral token corresponding to the CDP Vault.

The execution flow:

See PositionAction._deposit

    PositionAction.deposit --> PositionAction._deposit --> PositionAction4626._onDeposit

Here is the implementation used to convert from ERC4626’s underlying to ERC4626 token:

See PositionAction4626._onDeposit

    function _onDeposit(address vault, address /*position*/, address src, uint256 amount) internal override returns (uint256) {
        address collateral = address(ICDPVault(vault).token());

        // if the src is not the collateralToken, we need to deposit the underlying into the ERC4626 vault
        if (src != collateral) {
            address underlying = IERC4626(collateral).asset();
            IERC20(underlying).forceApprove(collateral, amount);
            amount = IERC4626(collateral).deposit(amount, address(this)); <-- No slippage check
        }

        IERC20(collateral).forceApprove(vault, amount);
        return ICDPVault(vault).deposit(address(this), amount);
    }

In this implementation, there is no slippage check when performing a deposit on target ERC4626’s vault. This could leads to users’ fund loss from slippage as ERC4626’s exchange rate can change or be manipulated while users’ transaction is pending.

This also happens in withdraw execution flow:

    PositionAction.withdraw --> PositionAction._withdraw --> PositionAction4626._onWithdraw

If users specify a different dst (destination) token, it attempts to redeem that token from ERC4626 vault.

    function _onWithdraw(address vault, address /*position*/, address dst, uint256 amount) internal override returns (uint256) {
        uint256 collateralWithdrawn = ICDPVault(vault).withdraw(address(this), amount);

        // if collateral is not the dst token, we need to withdraw the underlying from the ERC4626 vault
        address collateral = address(ICDPVault(vault).token());
        if (dst != collateral) {
            collateralWithdrawn = IERC4626(collateral).redeem(collateralWithdrawn, address(this), address(this)); <-- No slippage check
        }

        return collateralWithdrawn;
    }

Recommended Mitigations

Allow users to specify their slippage tolerance when interacting with PositionAction4626.

References

EIPS

Assessed type

ERC4626

amarcu (LoopFi) confirmed and commented:

Adding the splippage check will help but the funds are not directly at risk and cannot be stolen. We suggest this issue be a medium and not a high.

Koolex (judge) decreased severity to Medium

Infect3d (warden) commented:

As said by the sponsor, the funds are not at risk. I cannot think a case where slippage when depositing/withdrawing in a 4626 vault could cause a loss of fund. User depositing in a Vault simply get shares representing how much of the total vault he deposited.

If he redeem, he will get back his assets, or more if vault yielded in between. All issues about slippage when depositing/withdrawing from a 4626 vaults are invalid.

nnez (warden) commented:

Firstly, sponsors said that funds are not directly at risk. That doesn’t mean there are no funds at risk. There is always some degree of slippage loss when depositing or minting in an ERC4626 vault, and this loss is directly tied to the ERC4626 exchange rate.

As noted in OpenZeppelin’s documentation, the exchange rate can fluctuate, leading to discrepancies between the amount deposited and the corresponding shares received. A log-scale graph of this relationship highlights that the shares received may not accurately reflect the deposited amount due to these exchange rate changes.

ERC4626 is inherently prone to this issue because it was designed to be called by smart contract account not by EOA. It assumes that any integrating smart contract will implement slippage protection, ensuring that the shares received can be redeemed within an allowed slippage range. Without such protection, EOAs are more vulnerable to losses from exchange rate fluctuations. This concern is further discussed in detail by the Ethereum Magicians community in their proposal for EIP-5143 (Slippage Protection for Tokenized Vaults).

Additionally, Zellic’s analysis of ERC4626 vaults highlights the risks for EOAs when interacting directly with these vaults, specifically mentioning that “what you give is not necessarily what you get” due to slippage and exchange rate variability (source 1, source 2).

The ERC4626 standard contract of OZ acknowledges slippage concerns, as shown in the comments IERC4626 interface.

Moreover, the audit information do not specify which ERC4626 vault will be integrated. As a result, we must assume the contract should be compatible with any vault adhering to the ERC4626 standard, including those susceptible to exchange rate manipulation. Without slippage protection in place, slippage losses could be as high as 100%. (exchange rate manipulation in ERC4626 vaults).

Technical aside, if slippage during interactions with ERC4626 vaults were not a significant issue, it wouldn’t be such a widely discussed topic. The prevalence of discussions around slippage highlights the importance of addressing this concern.

Infect3d (warden) commented:

@nnez - The OZ source discuss about rounding error, here’s what they say:

This rounding is often negligible because of the amount at stake. If you deposit 1e9 shares worth of tokens, the rounding will have you lose at most 0.0000001% of your deposit. However if you deposit 10 shares worth of tokens, you could lose 10% of your deposit Tokens have at least 6 decimals, so the rounding error is at most 0.0001%, which is negligible.

The Zellic source is referring to “slippage” due to:

  1. Rounding error, we already shown that this is negligible, unless the exchange rate are so high and close to the token decimals that it is not considered dust.
  2. Vault deposit/withdraw fees. But vault fees are known in advance so user should be able to carefully select the values he will input when calling the vault functions to take into account the fees.

Zellic examples doesn’t seems to relate with what is referred as slippage in the submissions: they discuss about the difference of asset taken from user them when he calls mint, and asset given to user them when he calls redeem.

The amount of underlying assets a user may receive through redeeming their shares in the vault (previewRedeem) can be significantly different than the amount that would be taken from them when minting the same quantity of shares (previewMint). The differences may be small (e.g., if due to rounding error) or significant (e.g., if a vault implements withdrawal or deposit fees)

In those conditions don’t see how adding a slippage parameter will prevent this, if we consider user is aware of the fees, and of the exchange rate ? If the Vault sees his assets increasing due to yield before user “redeem” tx is executed, then he will get more asset than expected before the yield. Same logic can apply for deposit, if vault yielded, he will have at least a better position.

About the exchange rate manipulation in Euler article, all of these manipulation goals are to increase the exchange rate by sending assets into the vault without minting the expected number of equivalent shares (the idea being to increase share price and use the inflated shares to borrow in another protocol, and the attack is usually executed in 1 tx.

Also, an increased exchange rate would be beneficial for someone withdrawing from the vault, as his shares would allow him to withdraw more assets.

To finish, I agree there are situations where a harmful slippage could occur:

  1. When the vault incur a loss right before user tx is executed (how ?);
  2. If user is subject to first depositor attack.

But in my opinion, 1 shouldn’t occur in a vault meant to generate yield and 2 too, as far as the vault implement recent ERC4626 contracts or follows well known practices to avoid it.

nnez (warden) commented:

No problem @Infect3d. My answer was also long and I do appreciate you taking the time and sorry if you find some of the examples not quite relevant.

However, your answer actually sent me into the rabbit hole, searching for my answer on the topic.

  1. The exchange rate of ERC4626 vault depends on how the vault utilize its assets (its strategy), the yield-bearing notion doesn’t necessitate that the exchange rate is an ever-growing rate.

The example is actually the StakingLPEth contract itself. When the protocol implements a mechanism to distribute loss from bad debt among shareholders (#186), this can be a great example to answer your question.

“A liquidation transaction that realizes the bad debt for the vault is executed before users’ withdrawal transaction”.

This can be problematic as users might want to exit as fast as possible before the loss is realized but if they fail to do so they might want to hold on to those shares and decide not to realize the loss right away (as they can choose wait for the interest rate or protocol reserve to catch up). A slippage protection mechanism can definitely help with this situation.

  1. I agree that the first depositor attack should practically be mitigated if the vault owner follows a proper security practice.

However, we’re dealing with a generic ERC4626 here as the audit information doesn’t specify which vault is going to be integrate into the protocol. An integrating vault might not use OZ ERC4626 as the base contract and the mitigating mechanism (which ERC4626 also doesn’t dictate this) might not be there.

In conclusion,

  1. Can happen under certain situations and it can cause unexpected loss.
  2. Can happen but the likelihood depends on how you view the burden of implementing mitigation of the integrating vault as the standard doesn’t dictate it. I found this while I was digging around the topic:
  3. https://forum.openzeppelin.com/t/erc4626-inflation-attack-discussion/41643/9
  4. https://github.com/OpenZeppelin/openzeppelin-contracts/issues/5223

It seems like _decimalsOffset might not be effective against inflation attack on an empty vault in some cases

Infect3d (warden) commented:

@nnez, thank you again, really appreciated these insightful information you provided.

  1. You are right here, forgot that PoolV3 had that peculiarity (all these escalations I’ve created come from notes I’ve taken ~ 2 months ago).
  2. Very interesting situation here, risky but well thought. Never seen this used until today, thanks for sharing. I don’t have much to add to this conversation, what you say make sense.

Koolex (judge) commented:

Thanks everyone. This stays as-is.


The original report as published on Code4rena, by nnez. 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

The contract calls deposit and redeem on the ERC4626 vault without specifying a minimum output amount, so it accepts whatever exchange rate is current at execution time.

Impact

Users could lose funds due to slippage when the ERC4626 exchange rate changes or is manipulated, though the sponsor notes funds are not directly at risk and cannot be stolen.

What the attacker needed

User interacts with PositionAction4626; ERC4626 exchange rate changes or is manipulated

The fix

Allow users to specify their slippage tolerance when interacting with PositionAction4626.

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.

An ERC4626 vault is like a savings account where you deposit one token and get shares in return. The number of shares you get depends on the vault's exchange rate, which can change. If the rate changes between when you send your transaction and when it is processed, you might get fewer shares than you expected, and the code does not check for this.

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 nnez

View all

32 more disclosed reports, best first.

More from LoopFi

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.