Skip to content
Business logic Audit finding Advanced

The _currentExchangeRate of the Vault contract can’t increase and will always be lower than or equal to _assetUnit

The vault's exchange rate calculation caps withdrawable assets at the recorded supply-to-assets value, so the rate can never rise above the asset unit and cannot recover after a temporary under-collateralisation. This prevents further deposits when the vault is under-collateralised, though the team later stated the cap is intentional to stop users claiming accrued yield.

KIntern_NA Follow with KupiaSec

Originally disclosed on Code4rena

Submitted by KIntern_NA, also found by KupiaSec

The _currentExchangeRate of the Vault contract can not increase and will always be lower than or equal to _assetUnit. Therefore, when the vault is under-collateralized (_currentExchangeRate < _assetUnit), it can’t be further collateralized.

Proof of concept

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;
  }

The _totalSupplyAmount != 0 && _withdrawableAssets != 0, _currentExchangeRate function will return a value _withdrawableAssets * _assetUnit / _totalSupplyAmount. However, _withdrawableAssets can not exceed _totalSupplyToAssets, which is equal to _totalSupplyAmount * _lastRecordedExchangeRate / _assetUnit. Therefore, _currentExchangeRate will always be lower than or equal to _lastRecordedExchangeRate.

Add this assert line and run forge test; all tests will pass.

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

Recommended Mitigation Steps

Remove the lines of code that limit the _withdrawableAssets:

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

Assessed type

Context

asselstine (PoolTogether) confirmed and commented:

Hmm, I’m not sure about this one. Will mark as confirmed and figure it out later.

Picodes (judge) commented:

@asselstine - did you figure it out?

It seems to me that because of if (_withdrawableAssets > _convertToAssets(_totalSupplyAmount, _lastRecordedExchangeRate, Math.Rounding.Down)), the rate indeed can’t increase; which is a huge issue in case of a momentary undercollateralization.

PierrickGT (PoolTogether) commented:

@Picodes - Indeed, the exchange rate should not be greater than 1 because users should not be able to claim the yield that has accrued in the YieldVault.

That’s why we have the following condition:

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

We subtract the yield from the total amount, with the yield being the difference between _withdrawableAssets and _totalSupplyToAssets.

If the YieldVault becomes under-collateralized, users won’t be able to deposit anymore, but will be able to withdraw their share of the deposit. Any yield that as accrued and has not been claimed yet will be shared proportionally amongst users.

PierrickGT (PoolTogether) commented:

The code has been improved and clarified in the following PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/13.

Picodes (judge) commented:

Keeping high severity here because of the issue in case of temporary undercollateralization.

PoolTogether mitigated:

The issue turned out not to be the case; the exchange rate is always <= 1 (yield is liquidated). However, comments were added to clarify the behaviour. PR: https://github.com/GenerationSoftware/pt-v5-vault/pull/13

Status: Mitigation confirmed. Full details in reports from 0xStalin, dirk_y and rvierdiiev.


The original report as published on Code4rena, by KIntern_NA. 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 code clamps withdrawable assets to the previously recorded supply-to-assets value, so the computed exchange rate can never exceed the last recorded rate.

Impact

During a temporary under-collateralisation the vault cannot be re-collateralised because deposits are blocked, although the team says the cap is intentional to prevent users claiming accrued yield.

What the attacker needed

Vault becomes temporarily under-collateralised

The fix

The team said the behaviour was intentional and only added comments to clarify it, so no functional fix was applied.

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 vault tracks how much each share is worth using an exchange rate. The code deliberately caps the amount of assets counted so the rate can never go above one, which means if the vault briefly holds less than it should, it can never build back up and new deposits are blocked. The team said this cap is on purpose so people cannot take yield that has built up.

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 KIntern_NA

View all

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