# There is a logical error in the _distributeFees() function, resulting in an unfair distribution of fees.

Flayer's _distributeFees self-references the beneficiary pool, leaving 5% of fees unallocated so new LPs unfairly capture them.

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

**Target:** UniswapImplementation.sol _distributeFees fee distribution
**Root cause:** When the beneficiary is the Flayer protocol's own collection pool, _poolKeys[beneficiary].toId() equals the current poolId, so the 5% beneficiaryFee is credited back to the same pool's _poolFees instead of being distributed, leaving it claimable by future LPs.
**Steps:**
1. Set beneficiary to Flayer's NFT collection pool via setBeneficiary(_beneficiary, true)
2. Accumulate fees in the Flayer collection pool above donateThresholdMin
3. Call _distributeFees(_poolKey) for the Flayer pool's PoolKey
4. Observe feeSplit returns poolFee=95%, beneficiaryFee=5%
5. beneficiaryIsPool branch adds beneficiaryFee back to _poolFees[_poolKeys[beneficiary].toId()].amount0, which is the same poolId
6. Result: 5% remains in _poolFees rather than being donated, later captured by new LPs
**How found:** Code reading of _distributeFees and setBeneficiary: noticed the beneficiary pool branch writes back to _poolFees keyed by _poolKeys[beneficiary].toId(), and reasoned that when beneficiary is the Flayer pool itself this equals the current poolId, so the split is self-referential.
**Exploitation:** A new LP joins the Flayer collection pool after fees accumulate; the stranded 5% beneficiaryFee sitting in _poolFees is shared with them, diluting original LPs' earnings.
**Insight:** When a fee-split routes a portion to a 'beneficiary' that can be the same entity as the current pool, check whether the destination key can equal the source key — self-referential accounting silently strands funds for future LPs.

