Skip to content
Business logic Audit finding Advanced

Vault is not compatible with some ERC4626 vaults

rvierdiiev Follow with Brenzee

Originally disclosed on Code4rena

Submitted by rvierdiiev, also found by Brenzee

Depositors can lose funds.

Proof of Concept

Anyone can build Vault with an underlying vault inside, which should earn yields. When a user deposits/withdraws then the _convertToShares function is used to determine amount of shares the user will receive for the provided assets amount. This function calls _currentExchangeRate to find out current rate.

https://github.com/GenerationSoftware/pt-v5-vault/blob/b1deb5d494c25f885c34c83f014c8a855c5e2749/src/Vault.sol#L1168-L1187

  function _currentExchangeRate() internal view returns (uint256) {
    uint256 _totalSupplyAmount = _totalSupply();
    uint256 _totalSupplyToAssets = _convertToAssets(
      _totalSupplyAmount,
      _lastRecordedExchangeRate,
      Math.Rounding.Down
    );

    uint256 _withdrawableAssets = _yieldVault.maxWithdraw(address(this));

    if (_withdrawableAssets > _totalSupplyToAssets) {
      _withdrawableAssets = _withdrawableAssets - (_withdrawableAssets - _totalSupplyToAssets);
    }

    if (_totalSupplyAmount != 0 && _withdrawableAssets != 0) {
      return _withdrawableAssets.mulDiv(_assetUnit, _totalSupplyAmount, Math.Rounding.Down);
    }

    return _assetUnit;
  }

As you can see, in order to find the current exchange rate, function _yieldVault.maxWithdraw(address(this)) is used. In this case, if this value (which is supposed to be a full amount of deposits + yields inside _yieldVault) is less than _totalSupplyAmount (which is the total supply _lastRecordedExchangeRate), then the rate will be decreased. Which means that the vault lost funds and users should receive less when they withdraw. Later, this new _currentExchangeRate will be stored as _lastRecordedExchangeRate.

Now, when I explained how rate is changed, I can also explain the problem with some ERC4626 vaults.

There are some ERC4626 vaults as DnGmxSeniorVault, that collect deposited funds and borrow them. When you call maxWithdraw for such vaults, if not enough funds are present (due to some borrowing percentages on the vault), then the amount returned can be less than real balance of caller.

In case a such wrong value is returned, then depositors of the Pool vault will face losses, as their exchange rate will be less than 1. DnGmxSeniorVault will again have enough balance (when the debt is repaid by jn vault), and the exchange rate will be 1.

Another problem ERC4626 vaults can create are vaults that have a withdraw limit. In that case, if the Pool vault has balance inside the yield vault that is bigger than the borrow limit, depositors will face the same problem, which leads to a loss of funds.

Tools Used

VsCode

Recommended Mitigation Steps

You need to consider cases where some vaults can’t be used as yield vaults and be aware of vault creators for that.

Assessed type

Error

asselstine (PoolTogether) confirmed

asselstine (PoolTogether) commented:

This is more of a general warning about the possible incompatibilities of 4626 vaults.

PoolTogether mitigated:

Fixed undercollateralized redemption while providing an exit. PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/37

Status: Not fully mitigated. Full details in reports from 0xStalin and rvierdiiev, and in the Mitigation Review section below.


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

What is known

A high-severity business logic bug in PoolTogether. Code4rena made it public on 27 September 2023. Found in the 2023-07-pooltogether audit contest (finding H-09), also found by 1 other warden.

About Business logic

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

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 rvierdiiev

View all

72 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.