# An Optimizer Bug in PositionManager.getPositionIndexesFiltered

Solidity 0.8.14 Yul optimizer strips the mstore that resizes the returned array in PositionManager.getPositionIndexesFiltered, returning wrong-length index arrays.

- Payout: Contest reward
- Severity: medium
- Program: Ajna Protocol
- Credited: sces60107
- Disclosed: 2023-06-29
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2023-05-ajna-findings/issues/306
- Library page: https://bugbountylibrary.com/r/c4%3A2023-05-ajna%3AM-06
- Tags: domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:regression technique:source-review vuln:misconfiguration

**Target:** PositionManager.getPositionIndexesFiltered view function (Solidity inline assembly)
**Root cause:** Solidity 0.8.14's Yul optimizer treats memory writes in the outermost assembly block that are never read within that block as unused and removes them, so the `mstore(filteredIndexes_, filteredIndexesLength)` that sets the returned array length is deleted.
**Steps:**
1. Note PositionManager.sol uses `pragma solidity 0.8.14` (line 3), below the 0.8.15 fix for the inline-assembly memory side-effects bug.
2. Inspect getPositionIndexesFiltered: it builds filteredIndexes_ then ends with `assembly { mstore(filteredIndexes_, filteredIndexesLength) }` to resize the array.
3. The written memory is never read inside the same assembly block, so the optimizer removes the mstore.
4. Compile with 0.8.14 and call getPositionIndexesFiltered; the returned array length is not set to filteredIndexesLength, yielding incorrect/oversized index data.
**How found:** Code review of the assembly block combined with checking the pragma version against the known Solidity 0.8.15 inline-assembly memory side-effects bug advisory.
**Insight:** When auditing contracts pinned to pre-0.8.15 Solidity, grep every inline assembly block for memory writes (mstore) whose result is only consumed outside the block—the optimizer silently deletes them; cross-check pragma against the Solidity security advisories.
