#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
Report ID: #35014
Report Type: Smart Contract
Report severity: Low
Target: https://sepolia.etherscan.io/address/0x7e184179b1F95A9ca398E6a16127f06b81Cb37a3
Impacts:
Contract fails to deliver promised returns, but doesn't lose value
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);
} ```
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:
The vault experiences a small loss (e.g., 0.1%).
An attacker calls `mintDebt(1, address(this))`.
Due to rounding, `convertToAssets(1)` returns 0.
The debt allowance check is bypassed since 0 is added to `currentDebt`.
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:
The dilution effect is minimal, requiring many transactions to create a material impact.
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
Create a new forge project, `forge init --no-commit --no-git --vscode`
Create a new test file and paste the below test
Run `forge t --match-contract AcreBoostShortRoundingTest -vv`
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 {
} ```