`escrowedReward` will be frozen in the contract if `escrowPool == address(0)` but `escrowPortion > 0`
The contract allows setting the escrow pool to the zero address while keeping a non-zero escrow portion. When a user claims rewards, the escrowed part is not transferred anywhere and remains stuck in the contract, with no way for users or the admin to recover it.
Source: https://github.com/sherlock-audit/2022-10-merit-circle-judging/issues/107
Found by
bin2chen, hickuphh3, saian, Jeiwan, WATCHPUG, ctf_sec, berndartmueller
Summary
A portion of users' reward, which is expected to be "escrowed", will be frozen in the pool contract if escrowPool == address(0) but escrowPortion > 0.
Vulnerability Detail
Setting _escrowPool to address(0) is allowed in __BasePool_init():
However, when escrowPortion > 0, if escrowPool == address(0), claimRewards() will still only transferring nonEscrowedRewardAmount to the _receiver and left the escrowedRewardAmount in the contract.
Impact
As a result, a portion (escrowPortion) of the rewards will be frozen in the contract, and there is no way for the users or even the admin to retrieve these rewards.
Code Snippet
Tool used
Manual Review
Recommendation
Change to:
function claimRewards(address _receiver) external {
uint256 rewardAmount = _prepareCollect(_msgSender());
uint256 escrowedRewardAmount = 0;
if(escrowPortion != 0 && address(escrowPool) != address(0)) {
escrowedRewardAmount = rewardAmount * escrowPortion / 1e18;
if (escrowedRewardAmount != 0) {
escrowPool.deposit(escrowedRewardAmount, escrowDuration, _receiver);
rewardAmount -= escrowedRewardAmount;
}
}
// ignore dust
if(rewardAmount > 1) {
rewardToken.safeTransfer(_receiver, rewardAmount);
}
emit RewardsClaimed(_msgSender(), _receiver, escrowedRewardAmount, rewardAmount);
}
Discussion
federava
Conditions stablished in this issue, that is, escrowPool == address(0) and escrowPortion > 0 will never be met because pools are deployed with:
escrowPool != address(0) and escrowPortion > 0
or
escrowPool == address(0) and escrowPortion > 0
As a priority we could check on deployment that such conditions are not met.
federava
PR from this issue
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 does not check that the escrow pool address is non-zero before deducting the escrowed portion from the amount transferred to the user.
Impact
A portion of the rewards could be permanently frozen in the contract, with no recovery path for users or the admin.
What the attacker needed
EscrowPool set to the zero address; escrowPortion greater than zero; a user claims rewards
The fix
The claim function should only deduct an escrowed amount when both the escrow portion is non-zero and the escrow pool address is non-zero; the project opened a pull request to address this.
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 holds users' rewards. Part of each reward is meant to be sent to a separate 'escrow' contract for safekeeping. If that escrow address is left empty (the zero address) but the code still calculates an escrow amount, that amount is simply never sent anywhere and stays locked in the main contract forever.
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.