Failure to update dirty flag in transferToUnoccupiedPlot prevents reward accumulation on valid plot
The transferToUnoccupiedPlot function moves a Munchable to a valid plot but fails to clear the dirty flag, so the user continues to earn no rewards. An attacker could exploit this to keep a user unfairly penalised, though the report frames it as a bug affecting legitimate users.
0xCiphky Follow with merlinboii, Abdessamed and 22 others
Originally disclosed on Code4rena
Submitted by 0xCiphky, also found by merlinboii, Abdessamed, dhank, tedox, dontonka, gajiknownnothing, Drynooo, ironside, rudhra, typicalHuman, Tomas0707, stanchev, McToady, joaovwfreire, Heaven, phoenixV110, nnez, forgebyola, 0xrex, santipu_, shaflow2, ke1caM, dimulski, and Bozho
The transferToUnoccupiedPlot function allows a user to transfer their Munchable to another unoccupied plot from the same landlord. This can be used for example by users currently staked in an invalid plot marked as “dirty”, meaning they will not be earning any rewards, to transfer to a valid plot so they can start earning rewards again.
Since the function checks that the transfer is to a valid plot, it should mean users are now eligible to start earning rewards again. However, it doesn’t update the user’s dirty flag back to false, meaning the user will still not be earning any rewards even after they have moved to a valid plot.
function transferToUnoccupiedPlot(uint256 tokenId, uint256 plotId)
external
override
forceFarmPlots(msg.sender)
notPaused
{
(address mainAccount,) = _getMainAccountRequireRegistered(msg.sender);
ToilerState memory _toiler = toilerState[tokenId];
uint256 oldPlotId = _toiler.plotId;
uint256 totalPlotsAvail = _getNumPlots(_toiler.landlord);
if (_toiler.landlord == address(0)) revert NotStakedError();
if (munchableOwner[tokenId] != mainAccount) revert InvalidOwnerError();
if (plotOccupied[_toiler.landlord][plotId].occupied) {
revert OccupiedPlotError(_toiler.landlord, plotId);
}
if (plotId >= totalPlotsAvail) revert PlotTooHighError();
toilerState[tokenId].latestTaxRate = plotMetadata[_toiler.landlord].currentTaxRate;
plotOccupied[_toiler.landlord][oldPlotId] = Plot({occupied: false, tokenId: 0});
plotOccupied[_toiler.landlord][plotId] = Plot({occupied: true, tokenId: tokenId});
emit FarmPlotLeave(_toiler.landlord, tokenId, oldPlotId);
emit FarmPlotTaken(toilerState[tokenId], tokenId);
}
The next time _farmPlots is called, since dirty is still true, it’ll be skipped, accumulating no rewards.
function _farmPlots(address _sender) internal {
...
for (uint8 i = 0; i < staked.length; i++) {
...
if (_toiler.dirty) continue;
...
);
}
accountManager.updatePlayer(mainAccount, renterMetadata);
}
Impact
Since the function does not update the user’s dirty flag back to valid, users who transfer their Munchable to a valid plot and the landlord will still not earn any rewards. This results in a situation where users remain unfairly penalized even after moving to a valid plot
Recommendation
Update the transferToUnoccupiedPlot function to reset the dirty flag to false and update the lastToilDate if it was previously marked as dirty when a user successfully transfers to a valid plot. This will ensure that users start earning rewards again once they are on a valid plot.
function transferToUnoccupiedPlot(uint256 tokenId, uint256 plotId)
external
override
forceFarmPlots(msg.sender)
notPaused
{
(address mainAccount,) = _getMainAccountRequireRegistered(msg.sender);
ToilerState memory _toiler = toilerState[tokenId];
uint256 oldPlotId = _toiler.plotId;
uint256 totalPlotsAvail = _getNumPlots(_toiler.landlord);
if (_toiler.landlord == address(0)) revert NotStakedError();
if (munchableOwner[tokenId] != mainAccount) revert InvalidOwnerError();
if (plotOccupied[_toiler.landlord][plotId].occupied) {
revert OccupiedPlotError(_toiler.landlord, plotId);
}
if (plotId >= totalPlotsAvail) revert PlotTooHighError();
// ADD HERE
if (_toiler.dirty) {
toilerState[tokenId].lastToilDate = block.timestamp;
toilerState[tokenId].dirty = false;
}
//
toilerState[tokenId].latestTaxRate = plotMetadata[_toiler.landlord].currentTaxRate;
plotOccupied[_toiler.landlord][oldPlotId] = Plot({occupied: false, tokenId: 0});
plotOccupied[_toiler.landlord][plotId] = Plot({occupied: true, tokenId: tokenId});
emit FarmPlotLeave(_toiler.landlord, tokenId, oldPlotId);
emit FarmPlotTaken(toilerState[tokenId], tokenId);
}
0xinsanity (Munchables) confirmed via duplicate Issue #89
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 transferToUnoccupiedPlot function does not reset the dirty flag to false when moving to a valid plot.
Impact
Users who transfer to a valid plot will still not earn any rewards, remaining unfairly penalised.
What the attacker needed
A Munchable staked on a dirty plot; a valid unoccupied plot from the same landlord
The fix
The function should reset the dirty flag to false and update lastToilDate when transferring from a dirty plot.
How it was found
- Have a Munchable staked on a dirty plot.
- Call transferToUnoccupiedPlot to move it to a valid unoccupied plot.
- Observe that the dirty flag remains true.
- Call _farmPlots and see that rewards are skipped because dirty is still 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.
In this game, a 'dirty' flag means a plot is invalid and the player earns nothing. When a player moves to a valid plot, the code should clear that flag, but it doesn't, so the player keeps earning nothing. This is a logic bug that unfairly penalises players.
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.