LandManager::stakeMunchable allows users to stake up to 11 Munchables instead of the intended maximum of 10. This discrepancy could lead to some strange behavior in other parts of the protocol that assume a strict limit of 10 staked Munchables per user.
The issue is because the check munchablesStaked[mainAccount].length > 10 is performed before adding the new Munchable to the staked list. This allows a user to stake their 11th Munchable before the function reverts.
Consider:
A user with 10 staked Munchables calls stakeMunchable.
The check munchablesStaked[mainAccount].length > 10 passes (10 is not greater than 10).
The function continues and adds the 11th Munchable to munchablesStaked[mainAccount].
The user now has 11 staked Munchables, exceeding the intended limit.
Tools Used
Manual review
Recommended Mitigation Steps
Change this condition in the stakeMunchable function to use >= instead of >:
- if (munchablesStaked[mainAccount].length > 10)
+ if (munchablesStaked[mainAccount].length >= 10)
revert TooManyStakedMunchiesError();
Lines of code
https://github.com/code-423n4/2024-07-munchables/blob/94cf468aaabf526b7a8319f7eba34014ccebe7b9/src/managers/LandManager.sol#L131-L171
Vulnerability details
Impact
LandManager::stakeMunchable
allows users to stake up to11 Munchables
instead of the intended maximum of10
. This discrepancy could lead to some strange behavior in other parts of the protocol that assume a strict limit of 10 staked Munchables per user.Proof of Concept
Take a look at the
stakeMunchable
function: https://github.com/code-423n4/2024-07-munchables/blob/94cf468aaabf526b7a8319f7eba34014ccebe7b9/src/managers/LandManager.sol#L131-L171The issue is because the check
munchablesStaked[mainAccount].length > 10
is performed before adding the new Munchable to the staked list. This allows a user to stake their 11th Munchable before the function reverts.Consider:
stakeMunchable
.munchablesStaked[mainAccount].length > 10
passes (10 is not greater than 10).munchablesStaked[mainAccount]
.Tools Used
Manual review
Recommended Mitigation Steps
Change this condition in the
stakeMunchable
function to use>=
instead of>
:Assessed type
Error