Skip to content
Business logic Audit finding Beginner

MintDebt() and repayDebt() should return assets and not shares

The mintDebt() and repayDebt() functions return the shares value the caller supplied rather than the corresponding assets value, contrary to the ERC4626 convention that minting functions return assets. This could cause integration issues with other smart contracts and confuse users when the shares-to-assets ratio is not 1:1.

sammytm Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#34995 [SC-Low] `mintDebt()` and `repayDebt()` should return `assets` and not `shares`

Submitted on Sep 2nd 2024 at 13:09:27 UTC by @sammytm for Audit Comp | Acre

Description

Brief/Intro

`mintDebt()` and `repayDebt()` are used to mint debt and repay the debt by a user.

Vulnerability Details

`mintDebt()` and `repayDebt()` currently return `shares` inputted by the users and not the corresponding `assets` ```solidity function repayDebt( uint256 shares ) public whenNotPaused returns (uint256 assets) { assets = convertToAssets(shares);

    // Check the current debt of the debtor.
    if (currentDebt[msg.sender] < assets) {
        revert ExcessiveDebtRepayment(
            msg.sender,
            currentDebt[msg.sender],
            assets
        );
    }

    // Decrease the debt of the debtor.
    currentDebt[msg.sender] -= assets;

    emit DebtRepaid(msg.sender, currentDebt[msg.sender], assets, shares);

    // Decrease the total debt.
    totalDebt -= assets;

    // Burn the shares from the debtor.
    super._burn(msg.sender, shares);

    return shares;
}

``` ```solidity function mintDebt( uint256 shares, address receiver ) public whenNotPaused returns (uint256 assets) { assets = convertToAssets(shares);

    // Increase the debt of the debtor.
    currentDebt[msg.sender] += assets;

    // Check the maximum debt allowance of the debtor.
    if (currentDebt[msg.sender] > allowedDebt[msg.sender]) {
        revert InsufficientDebtAllowance(
            msg.sender,
            allowedDebt[msg.sender],
            currentDebt[msg.sender]
        );
    }

    emit DebtMinted(msg.sender, currentDebt[msg.sender], assets, shares);

    // Increase the total debt.
    totalDebt += assets;

    // Mint the shares to the receiver.
    super._mint(receiver, shares);

    return shares;
}

```

Impact Details

The ERC4626 standard states that minting shares must return assets as return value. But this doesn't follow the standard and may cause integration issues with some smart contracts. This can also cause confusion to users, particularly when the shares : assets ratio isn't 1:1

Proof of Concept

Proof of Concept

``` describe.only("POC", () => { beforeAfterSnapshotWrapper()

it("Vault infaltion", async function () {
  let minimumDepositAmount = await stbtc.minimumDepositAmount()
  //await tbtc.connect(depositor1).transfer(stbtc,100);
  await stbtc.connect(governance).updateDebtAllowance(depositor1,10n ** 7n);

 console.log((await stbtc.connect(depositor1).mintDebt(1, depositor1)) + " "+ (await stbtc.balanceOf(depositor1)));
 
})

}) ``` Copy in `stBTC.test.ts` and run `pnpm test`

The original report as published on Immunefi, by sammytm. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 functions compute the correct assets value but return the shares variable instead of assets.

Impact

Integrations relying on the return value may misbehave and users may be confused, but no funds are lost.

What the attacker needed

None

The fix

The functions should return the computed assets value rather than the shares input.

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 contract lets people deposit tokens and receive 'shares' that represent their portion. The ERC4626 standard says that when you mint shares, the function should tell you how many underlying tokens that corresponds to. Here the functions instead return the number of shares you passed in, which is the wrong number and can mislead other contracts that call them.

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 from Acre

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.