Previous `beneficiary` will not be able to claim `beneficiaryFees` if current beneficiary is a pool
The claim function checks a global flag indicating whether the current beneficiary is a pool, rather than checking the specific beneficiary being claimed for. If the beneficiary is changed to a pool, the previous beneficiary can no longer claim the fees they earned while they were the beneficiary.
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/101
Found by
Ragnarok, araj, cawfree, dany.armstrong90, g, h2134, utsav
Summary
Previous beneficiary will not be able to claim beneficiaryFees if current beneficiary is a pool
Vulnerability Detail
Beneficiary can claim their fees using claim(), which checks if the beneficiaryIsPool and if its true, it reverts
function claim(address _beneficiary) public nonReentrant {
// Ensure that the beneficiary has an amount available to claim. We don't revert
// at this point as it could open an external protocol to DoS.
uint amount = beneficiaryFees[_beneficiary];
if (amount == 0) return;
// We cannot make a direct claim if the beneficiary is a pool
@> if (beneficiaryIsPool) revert BeneficiaryPoolCannotClaim();
...
}
Above pointed check is a problem because it checks beneficiaryIsPool regardless of _beneficiary is current beneficiary or previous beneficiary.
As result, if current beneficiary is a pool but previous beneficiary was not, then previous beneficiary will not be able to withdraw the fees as above check will revert because beneficiaryIsPool represents the status of current beneficiary.
//How this works
- Suppose the current beneficiaryA is not a pool ie beneficiaryIsPool = false & receives a fees of 100e18
- Owner changed the beneficiary using
setBeneficiary()to beneficiaryB, which is a pool ie beneficiaryIsPool = true - Natspecs of the
setBeneficiary()clearly says previous beneficiary should claim their fees, but they will not be able to claim because now beneficiaryIsPool = true, which will revert the transaction
/**
@> * Allows our beneficiary address to be updated, changing the address that will
* be allocated fees moving forward. The old beneficiary will still have access
* to `claim` any fees that were generated whilst they were set.
*
* @param _beneficiary The new fee beneficiary
* @param _isPool If the beneficiary is a Flayer pool
*/
function setBeneficiary(address _beneficiary, bool _isPool) public onlyOwner {
beneficiary = _beneficiary;
beneficiaryIsPool = _isPool;
// If we are setting the beneficiary to be a Flayer pool, then we want to
// run some additional logic to confirm that this is a valid pool by checking
// if we can match it to a corresponding {CollectionToken}.
if (_isPool && address(locker.collectionToken(_beneficiary)) == address(0)) {
revert BeneficiaryIsNotPool();
}
emit BeneficiaryUpdated(_beneficiary, _isPool);
}
This issue is arising because beneficiaryIsPool is the status of the current beneficiary, but claim() can be used to claim fee by previous beneficiary also
Impact
Previous beneficiary will not be able to claim their fees
Code Snippet
https://github.com/sherlock-audit/2024-08-flayer/blob/main/flayer/src/contracts/implementation/BaseImplementation.sol#L171 https://github.com/sherlock-audit/2024-08-flayer/blob/main/flayer/src/contracts/implementation/BaseImplementation.sol#L203C4-L223C6
Tool used
Manual Review
Recommendation
Remove the above check because if the beneficiary is a pool then their fees are store in a different mapping _poolFee not beneficiaryFees, which means any beneficiary which is a pool, will try to claim then it will revert as there beneficiaryFee will be 0(zero)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The claim function uses a single global boolean that reflects only the current beneficiary's pool status, instead of checking the status of the specific address claiming fees.
Impact
The previous beneficiary cannot claim the fees they earned, leaving those funds stuck in the contract.
What the attacker needed
Beneficiary changed from non-pool to pool; previous beneficiary has unclaimed fees
The fix
The check should be removed because pool beneficiaries store fees in a different mapping, so a pool's beneficiaryFees would be zero and the claim would return early anyway.
How it was found
- Set the beneficiary to a non-pool address, which accrues fees.
- Change the beneficiary to a pool address using setBeneficiary.
- The previous non-pool beneficiary tries to claim their accrued fees.
- The claim reverts because the global beneficiaryIsPool flag is now true.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract can have a 'beneficiary' who receives fees. The contract stores a flag saying whether the current beneficiary is a special kind of address called a pool. When someone tries to claim fees, the contract checks this flag and blocks the claim if it is true, even if the person claiming is an old beneficiary who is not a pool. So the old beneficiary's fees get stuck.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.