plotId is defined as uint256 and it can start from 0 index to n index. If a landlord have 3 max plot, basicly 0,1,2 indexes are available for plot. We can also see this behaviour from following lines:
uint256 totalPlotsAvail = _getNumPlots(landlord);
if (plotId >= totalPlotsAvail) revert PlotTooHighError();
It uses >= instead of > because index 0 is counted as available plot.
In edge case, players total farm time calculated using lastUpdated time, but normally it's calculated with block.timestamp which generate more reward than edge case.
But in following lines, while deciding the plotId is whether in edge case or not. It uses < operator and it should be <= for correct calculation:
Lines of code
https://github.com/code-423n4/2024-07-munchables/blob/94cf468aaabf526b7a8319f7eba34014ccebe7b9/src/managers/LandManager.sol#L258-L261
Vulnerability details
Description
plotId is defined as uint256 and it can start from 0 index to n index. If a landlord have 3 max plot, basicly 0,1,2 indexes are available for plot. We can also see this behaviour from following lines:
It uses
>=
instead of>
because index 0 is counted as available plot. In edge case, players total farm time calculated using lastUpdated time, but normally it's calculated with block.timestamp which generate more reward than edge case. But in following lines, while deciding the plotId is whether in edge case or not. It uses<
operator and it should be<=
for correct calculation:Impact
plotId == maxPlot
case calculated wrongly and player can farm more reward.Proof of Concept
In order to illustrate this, we can use following scenario:
Tools Used
Manual Review
Recommended Mitigation Steps
Changing
<
operator to<=
will solve the problemAssessed type
Other