# For extreme ratios, getRatiosFromPriceSwap will return data for which is impossible to converge into a reserve

Stable2LUT1.getRatiosFromPriceSwap returns wide high/low price bounds for extreme ratios, causing calcReserveAtRatioSwap to oscillate and return a reserve far from target.

- Payout: Audit contest
- Severity: medium
- Program: Basin
- Found by: Egis\_Security
- Disclosed: 2024-09-03
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-basin-findings/issues/25
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-basin%3AM-01
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:oracle-manipulation

**Target:** Stable2LUT1 lookup table / calcReserveAtRatioSwap
**Root cause:** For prices in the 0.001083e6–0.213318e6 range, getRatiosFromPriceSwap returns a PriceData struct with a large gap between highPrice and lowPrice, so the max step size exceeds the j reserve and the iterative solver oscillates instead of converging.
**Steps:**
1. Call `calcReserveAtRatioSwap` with reserves `[1e18,1e18]` and ratios `[4202,19811]` (target price ~212104, ratio ~1:4.6).
2. Observe `getRatiosFromPriceSwap` returns highPrice 213318, lowPrice 1083, maxStep 1858346112180059079.
3. Log `pd.currentPrice` each iteration: it jumps 209986→215834→205646→223618→192647... diverging from target.
4. Loop exits returning last computed reserve `3623929482258792273` instead of expected `2421185918213441156` (closest J reserve).
**How found:** Auditor read the Stable2LUT1 lookup table, noticed the wide high/low price gap for the extreme-price branch, hypothesized the step size would exceed the reserve and cause the iterative solver to skip the target, then confirmed via fuzz/PoC logging currentPrice per iteration.
**Insight:** When auditing iterative numeric solvers backed by lookup tables, check that the table's step bounds (highPrice/lowPrice gap) can't exceed the reserve magnitude—otherwise the solver oscillates and silently returns a non-converged value rather than reverting.

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

**Test calling calcReserveAtRatioSwap with extreme ratios**

```
function test_calcReserveAtRatioSwapSkipTarget() public view {
            uint256[] memory reserves = new uint256[](2);
            reserves[0] = 1e18;
            reserves[1] = 1e18;
            uint256[] memory ratios = new uint256[](2);
            ratios[0] = 4202;
            ratios[1] = 19811;

            // 4202 * 1e6 / 19811  = 212104 = 0.212 / 1  = 1 : 4.6
            //                                0.04  / 1  = 1 : 25    

            uint256 reserve1 = _f.calcReserveAtRatioSwap(reserves, 1, ratios, data);
```

