Skip to content
Business logic Audit finding Intermediate

Total assets of yearn vault are not correct

The YearnAdapter contract calculates the total assets of a Yearn vault by adding the vault's token balance to its total debt, but the Yearn vault itself uses an internal tracked value (totalIdle) instead of the live balance. This can cause the adapter to overstate total assets if the vault's balance is inflated, leading to incorrect share price calculations.

hansfriese Follow with rbserver

Originally disclosed on Code4rena

Submitted by hansfriese, also found by rbserver

Total assets of yearn vault are not correct so the calculation between the asset and the shares will be wrong.

Proof of Concept

In YearnAdapter the total assets of current yValut are extracted using _yTotalAssets.

    function _yTotalAssets() internal view returns (uint256) {
        return IERC20(asset()).balanceOf(address(yVault)) + yVault.totalDebt(); //@audit
    }

But in the yearn vault implementation, self.totalIdle is used instead of current balance.

def _totalAssets() -> uint256:
    # See note on `totalAssets()`.
    return self.totalIdle + self.totalDebt

In yearn valut, totalIdle is the tracked value of tokens, so it is same as vault’s balance in most cases, but the balance can be larger due to an attack or other’s fault. Even sweep is implemented for the case in the vault implementation.

    if token == self.token.address:
        value = self.token.balanceOf(self) - self.totalIdle

    log Sweep(token, value)
    self.erc20_safe_transfer(token, self.governance, value)

So the result of _yTotalAssets can be inflated than the correct total assets and the calculation between the asset and the shares will be incorrect.

Recommended Mitigation Steps

Use yVault.totalIdle instead of balance.

RedVeil (Popcorn) confirmed


The original report as published on Code4rena, by hansfriese. 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 adapter uses the vault's live token balance instead of the vault's internal totalIdle value, which can diverge if tokens are sent directly to the vault.

What the attacker needed

Tokens sent directly to the Yearn vault

The fix

The adapter should use the vault's totalIdle value instead of the token balance.

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 Yearn vault is a smart contract that holds tokens and tracks how many tokens it has internally. The adapter contract here reads the vault's actual token balance from the blockchain instead of the vault's own internal record. If someone sends extra tokens directly to the vault, the balance becomes larger than the internal record, so the adapter thinks the vault has more assets than it really does, which can mess up share pricing.

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 hansfriese

View all

65 more disclosed reports, best first.

More from Popcorn 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.