# `GoodDollarExchangeProvider::mintFromExpansion()` will change the price due to a rounding error in the new ratio

mintFromExpansion computes new supply with 1e18-precision ratio but stores reserveRatio at 1e8, minting excess tokens and shifting the Bancor price.

- Payout: Audit contest
- Severity: medium
- Program: Mento Update
- Found by: 0x73696d616f
- Disclosed: 2024-10-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-10-mento-update-judging/issues/21
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-10-mento-update%3AM-2
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:sherlock sev:medium tech:evm tech:solidity vuln:accounting-error vuln:precision-loss

**Target:** GoodDollarExchangeProvider Solidity contract (mintFromExpansion)
**Root cause:** newRatio is computed at 1e18 precision and used to size the mint, but exchange.reserveRatio is stored downscaled to 1e8 (newRatio/1e10), so supply and ratio are inconsistent and price = reserve/(supply*reserveRatio) drifts.
**Steps:**
1. Call `exchangeProvider.mintFromExpansion(exchangeId, reserveRatioScalar)` as expansion controller.
2. Observe `currentPrice(exchangeId)` before and after; assertEq fails because price changed.
3. Fix: compute `newRatio = unwrap(scaledRatio.mul(wrap(reserveRatioScalar))) / 1e10 * 1e10` to align precision before minting.
**How found:** Code reading of the Bancor invariant: noticed newRatio used at full 1e18 precision for mint amount while reserveRatio is stored at 1e8, hypothesizing a price drift; confirmed with a before/after currentPrice test.
**Insight:** When a formula's output is stored at reduced precision but consumed at full precision elsewhere, the invariant (price = reserve/(supply*ratio)) silently breaks; check every place a scaled value is both stored and reused.

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

**PoC test asserting price unchanged after mintFromExpansion**

```
function test_POC_mintFromExpansion_priceChangeFix() public {
  uint256 priceBefore = exchangeProvider.currentPrice(exchangeId);
  vm.prank(expansionControllerAddress);
  exchangeProvider.mintFromExpansion(exchangeId, reserveRatioScalar);
  uint256 priceAfter = exchangeProvider.currentPrice(exchangeId);
  assertEq(priceBefore, priceAfter, "Price should remain exactly equal");
}
```

