Skip to content
Business logic Audit finding Intermediate

VaultBase is not ERC4626 compliant

The VaultBase contract does not follow several mandatory ERC4626 requirements, such as returning incorrect maximum deposit/mint/withdraw/redeem values and preview functions that round the wrong way or ignore fees. This could break external integrations that rely on these functions.

klau5 Follow with 0xpiken, 0xpiken and 2 others

Originally disclosed on Code4rena

Submitted by klau5, also found by 0xpiken, 0xpiken, shaflow2, and shaflow2

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L188

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L155

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L278

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L337

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L164

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L287

https://github.com/code-423n4/2024-12-bakerfi/blob/0daf8a0547b6245faed5b6cd3f5daf44d2ea7c9a/contracts/core/VaultBase.sol#L346

Finding description and impact

VaultBase is not compliant with the must-have specs in ERC4626. This can break external integrations.

Proof of Concept

The official ERC4626 specifications can be found on this page. Several required specifications are not being followed. Here are the incorrectly implemented functions:

maxDeposit

Maximum amount of the underlying asset that can be deposited into the Vault for the receiver, through a deposit call. MUST return the maximum amount of assets deposit would allow to be deposited for receiver and not cause a revert, which MUST NOT be higher than the actual maximum that would be accepted (it should underestimate if necessary). This assumes that the user has infinite assets, i.e. MUST NOT rely on balanceOf of asset. MUST factor in both global and user-specific limits, like if deposits are entirely disabled (even temporarily) it MUST return 0.

VaultBase.maxDeposit always returns type(uint256).max. However, _depositInternal uses getMaxDeposit to enforce limits. This means VaultBase.maxDeposit returns incorrect values if getMaxDeposit was set. Additionally, it doesn’t return 0 when the contract is paused.

function maxDeposit(address) external pure override returns (uint256 maxAssets) {
@>  return type(uint256).max;
}

function _depositInternal(uint256 assets, address receiver) private returns (uint256 shares) {
    ...
    // Check if deposit exceeds the maximum allowed per wallet
@>  uint256 maxDepositLocal = getMaxDeposit();
    if (maxDepositLocal > 0) {
        uint256 depositInAssets = (balanceOf(msg.sender) * _ONE) / tokenPerAsset();
        uint256 newBalance = assets + depositInAssets;
        if (newBalance > maxDepositLocal) revert MaxDepositReached();
    }
    ...
}

maxMint

Maximum amount of shares that can be minted from the Vault for the receiver, through a mint call. MUST return the maximum amount of shares mint would allow to be deposited to receiver and not cause a revert, which MUST NOT be higher than the actual maximum that would be accepted (it should underestimate if necessary). This assumes that the user has infinite assets, i.e. MUST NOT rely on balanceOf of asset. MUST factor in both global and user-specific limits, like if mints are entirely disabled (even temporarily) it MUST return 0.

VaultBase.maxMint always returns type(uint256).max. However, _depositInternal uses getMaxDeposit to enforce limits. This means VaultBase.maxMint returns incorrect values if getMaxDeposit was set. Additionally, it doesn’t return 0 when the contract is paused.

function maxMint(address) external pure override returns (uint256 maxShares) {
@>  return type(uint256).max;
}

function _depositInternal(uint256 assets, address receiver) private returns (uint256 shares) {
    ...

    // Check if deposit exceeds the maximum allowed per wallet
@>  uint256 maxDepositLocal = getMaxDeposit();
    if (maxDepositLocal > 0) {
        uint256 depositInAssets = (balanceOf(msg.sender) * _ONE) / tokenPerAsset();
        uint256 newBalance = assets + depositInAssets;
        if (newBalance > maxDepositLocal) revert MaxDepositReached();
    }

    ...
}

maxWithdraw

MUST factor in both global and user-specific limits, like if withdrawals are entirely disabled (even temporarily) it MUST return 0.

VaultBase.maxWithdraw doesn’t return 0 when the contract is paused.

function maxWithdraw(address shareHolder) external view override returns (uint256 maxAssets) {
    maxAssets = this.convertToAssets(balanceOf(shareHolder));
}

maxRedeem

MUST factor in both global and user-specific limits, like if redemption is entirely disabled (even temporarily) it MUST return 0.

VaultBase.maxRedeem doesn’t return 0 when the contract is paused.

function maxRedeem(address shareHolder) external view override returns (uint256 maxShares) {
    maxShares = balanceOf(shareHolder);
}

previewMint

MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call in the same transaction. i.e. mint should return the same or fewer assets as previewMint if called in the same transaction.

If (1) it’s calculating the amount of shares a user has to supply to receive a given amount of the underlying tokens or (2) it’s calculating the amount of underlying tokens a user has to provide to receive a certain amount of shares, it should round up.

It is recommended that previewMint rounds up the results. (reference) It should return no less than the amount of assets the user actually should pay. But VaultBase.previewMint rounds down results.

function previewMint(uint256 shares) external view override returns (uint256 assets) {
    assets = this.convertToAssets(shares);
}

previewWithdraw

MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw call in the same transaction. i.e. withdraw should return the same or fewer shares as previewWithdraw if called in the same transaction. MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.

If (1) it’s calculating the amount of shares a user has to supply to receive a given amount of the underlying tokens or (2) it’s calculating the amount of underlying tokens a user has to provide to receive a certain amount of shares, it should round up.

VaultBase takes a fee when you withdraw, but VaultBase.previewWithdraw doesn’t count the fee. previewWithdraw should return the share including the fee. Also, previewWithdraw is recommended to round up the result (reference), but VaultBase.previewWithdraw is rounding down the calculation.

function previewWithdraw(uint256 assets) external view override returns (uint256 shares) {
@>  shares = this.convertToShares(assets);
}

function convertToShares(uint256 assets) external view override returns (uint256 shares) {
    Rebase memory total = Rebase(totalAssets(), totalSupply());
@>  shares = total.toBase(assets, false);
}

function _redeemInternal(
    uint256 shares,
    address receiver,
    address holder,
    bool shouldRedeemETH
) private returns (uint256 retAmount) {
    ...

    // Calculate and handle withdrawal fees
    if (getWithdrawalFee() != 0 && getFeeReceiver() != address(0)) {
@>      fee = amount.mulDivUp(getWithdrawalFee(), PERCENTAGE_PRECISION);

        if (shouldRedeemETH && _asset() == wETHA()) {
            unwrapETH(amount);
@>          payable(receiver).sendValue(amount - fee);
            payable(getFeeReceiver()).sendValue(fee);
        } else {
@>          IERC20Upgradeable(_asset()).transfer(receiver, amount - fee);
            IERC20Upgradeable(_asset()).transfer(getFeeReceiver(), fee);
        }
    } else {
        ...
    }

    emit Withdraw(msg.sender, receiver, holder, amount - fee, shares);
    retAmount = amount - fee;
}

previewRedeem

MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call in the same transaction. i.e. redeem should return the same or more assets as previewRedeem if called in the same transaction. MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.

VaultBase charges withdrawal fees but VaultBase.previewRedeem doesn’t include fees. It should deduct the asset amount paid as fees.

Additionally, when withdrawing from MultiStrategyVault, amounts to undeploy are calculated per Strategy with rounding down. Since previewRedeem’s result shouldn’t exceed actual withdrawal amount, it should simulate multi-Strategy withdrawals to include losses.

function previewRedeem(uint256 shares) external view override returns (uint256 assets) {
    assets = this.convertToAssets(shares);
}

Recommended Mitigation Steps

Modify to comply with the specification of ERC4626. For MultiStrategyVault, override ERC4626 view functions to simulate multi-Strategy deposits/withdrawals and include rounding loss.

chefkenji (BakerFi) confirmed

BakerFi mitigated:

PR-27

Status: Unmitigated. Full details in reports from shaflow2, and also included in the Mitigation Review section below.


The original report as published on Code4rena, by klau5. 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 vault's view functions were implemented as simple conversions without accounting for limits, fees, or rounding directions required by ERC4626.

Impact

External integrations relying on ERC4626 view functions could receive incorrect values, potentially leading to failed transactions or unexpected behaviour.

What the attacker needed

None

The fix

The vault should be modified to comply with the ERC4626 specification, including overriding view functions in MultiStrategyVault to simulate multi-strategy deposits and withdrawals with rounding losses.

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.

ERC4626 is a standard for tokenised vaults that defines how deposits, withdrawals, and previews should behave. This vault breaks several of those rules, so other programs that expect the standard may misbehave when interacting with it.

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 klau5

View all

21 more disclosed reports, best first.

More from BakerFi Invitational

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.