code-423n4 / 2024-05-munchables-validation

0 stars 0 forks source link

Player can set a very small lockup time of 1 second depending on a frontrunning condition #567

Open c4-bot-2 opened 6 months ago

c4-bot-2 commented 6 months ago

Lines of code

https://github.com/code-423n4/2024-05-munchables/blob/main/src/managers/LockManager.sol#L249-L269 https://github.com/code-423n4/2024-05-munchables/blob/main/src/managers/LockManager.sol#L347 https://github.com/code-423n4/2024-05-munchables/blob/main/src/managers/LockManager.sol#L382-L384

Vulnerability details

If the player manages to call setLockDuration() before a token is configurated, he can set 1 second of lockup time and unlock almost immediately everytime he locks during a non lockdrop period. These's also another scenario which he can set 1 second if he doesn't have any locked tokens.

Proof of Concept

This is possible because setLockDuration() won't interate the configurateTokens loop, and the lockup time only reverts when _lockDuration is smaller than configurated minimum during lockup periods in lock().

There's also another scenario which would be for the player to call setLockDuration() with _duration = 1 without having any lock tokens (meaning revert check won't be executed). With this approach, his lockToken.unlockTime will also be very small when evaluated in lock().

Impact

This would allow players to harvest the rewards almost immediately without having to wait for lockup times, and call unlock() right after calling lock().

Tools Used

Manual review.

Recommented Mitigation Steps

One approach could be to check if _duration is not smaller than a default min value in setLockDuration().

Another approach could be to update _lockDuration in lock() to be the value of lockdrop.minLockDuration when _lockDuration is smaller then lockdrop.minLockDuration, because currently it updates if _lockDuration is zero.

Assessed type

Invalid Validation