BondingCalculator decimals underflow reverts all valuation for sub-18-decimal tokens

Hi team

Finding: every valuation through the real BondingCalculator reverts for a sub-18-decimal token pair, taking Treasury tokenValue, deposit and auditReserves down for that token. I executed both legs in forge: a 9 and 6 decimal mock pair reverts with the exact panic 0x11, while the 18 and 18 control returns a value. The remaining premise is a registered sub-18 pair, which is not settleable locally.

Suggested fix: scale by the decimals difference instead of subtracting into an underflow.

Shahmeer

Adding the full reproduction detail.

Location: StandardBondingCalculator dot sol, getKValue at line 23. Line 26 computes token0 plus token1 minus the pair decimals, and line 29 raises 10 to that power:

uint256 token0 = IERC20Metadata(IUniswapV2Pair(pair).token0()).decimals();
uint256 token1 = IERC20Metadata(IUniswapV2Pair(pair).token1()).decimals();
uint256 decimals = token0 + token1 - IERC20Metadata(pair).decimals();
...
k = FullMath.mulDiv(reserve0, reserve1, 10**decimals);

For a 9 and 6 decimal pair the line 26 subtraction underflows, and Solidity checked arithmetic panics before any price is computed.

Executed in forge against the real calculator:

  • 18 and 18 control pair: returns a positive valuation
  • 9 and 6 pair: reverts, returndata exactly 36 bytes, selector 0x4e487b71, panic code 0x11
  • markdown on the 9 and 6 pair: reverts with the identical panic

The revert path runs through Treasury tokenValue, deposit and auditReserves. Note the function never returns a wrong number, it reverts, so this is not a mispricing claim.

The one open premise: a registered pair whose decimals sum below 18, for example the 9 decimal ecosystem base token paired with a 6 decimal counterpart. Not settleable locally.

Shahmeer

Thank you for your report!

Someone already posted the same issue previously (I tried to find it, but it wasn’t an easy task). The main idea is that we use only WETH as a reserve - or, in the worst case, DAI - and both have 18 decimals. That’s why I believe your issue is valid in general, but we can’t fall into it, since we restrict ourselves to not using other tokens.

Hi team, checking in on this one. The full reproduction is already in the thread from October 6: getKValue subtracts decimals at line 26, and any pair whose decimals add up below 18 reverts valuation with a panic instead of pricing. The open premise is still a registered pair with that decimal shape. Has the team confirmed the underflow, and is there a verdict coming?