During stake or deposit, users would not be rewarded the correct Concur token, when MasterChef has under-supply of it
The MasterChef contract's safeConcurTransfer function does not check if it has enough Concur tokens before transferring rewards. If the contract runs out of tokens, users receive zero rewards until it is replenished.
Submitted by hubble, also found by CertoraInc and Czar102
During stake or deposit, users would not be transferred the correct Concur token, when MasterChef has under-supply of it.
There is an assumption that MasterChef contract would own enough Concur tokens so as to distribute to users as reward, during deposit or withdraw. But say, due to excess user activity, MasterChef runs out of Concur tokens. All deposits & withdraws that happen after that, would have zero transfer of Concur token to the user. This will continue until the MasterChef contract is replenished again.
Proof of Concept
Makeshift unit test Note: Temporarily modify the private function MasterChef.safeConcurTransfer to public function, for unit test validation
//Unit Test starts
it("MasterChef - Zero Concur balance", async function() {
await concurToken.mint(masterChef.address, 100);
console.log(await concurToken.balanceOf(masterChef.address), await concurToken.balanceOf(user1.address));
await masterChef.safeConcurTransfer(user1.address, 60); // user1 is rewarded correctly.
console.log(await concurToken.balanceOf(masterChef.address), await concurToken.balanceOf(user1.address));
await masterChef.safeConcurTransfer(user1.address, 60); // user1 is rewarded lesser by 10.
console.log(await concurToken.balanceOf(masterChef.address), await concurToken.balanceOf(user1.address));
await masterChef.safeConcurTransfer(user1.address, 60); // user1 is totally not rewarded.
console.log(await concurToken.balanceOf(masterChef.address), await concurToken.balanceOf(user1.address));
});
//Unit Test ends
Tools Used
Manual review, & makeshift Unit test
Recommended Mitigation Steps
Minimal recommended fix:
To MasterChef.safeConcurTransfer function, add the following require statement. This will at least ensure that, when there is zero balance in MasterChef contract, the safeConcurTransfer function will not succeed.
function safeConcurTransfer(address _to, uint _amount) private {
uint concurBalance = concur.balanceOf(address(this));
require(concurBalance>0, "safeConcurTransfer: balance is zero.");
Alex the Entreprenerd (judge) commented:
The finding is valid as in that depositors could not receive token incentives, am not fully convinced this should be of medium severity as ultimately the contract will eventually run out of tokens and as such this is a situation that has to be handled.
If anything, reverting may cause the tokens to be stuck.
Alex the Entreprenerd (judge) commented:
While I feel like this is a situational finding, it ultimately is a loss of yield finding with a very clear example. For that reason I believe Medium Severity to be appropriate.
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
Likely the safeConcurTransfer function does not verify that the contract has sufficient balance before transferring, so it transfers zero when the balance is insufficient.
Impact
Users could receive less or zero reward tokens when the MasterChef contract has insufficient Concur tokens, and the judge noted that reverting may cause tokens to be stuck.
What the attacker needed
MasterChef contract runs out of Concur tokens
The fix
Add a require statement to safeConcurTransfer to ensure the contract balance is greater than zero before transferring.
How it was found
- Mint 100 Concur tokens to the MasterChef contract.
- Call safeConcurTransfer to send 60 tokens to user1; user1 receives 60.
- Call safeConcurTransfer again to send 60 tokens; user1 receives only 40 (10 less than expected).
- Call safeConcurTransfer a third time to send 60 tokens; user1 receives 0.
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.
This is a smart contract that gives out reward tokens. If the contract's supply of reward tokens runs out, it silently gives zero instead of failing, so users lose their expected rewards.
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.