The lockOnBehalf function allows any user to lock tokens on behalf of another user. A bad actor can exploit this function to perpetually extend the unlock time of a legitimate user's locked tokens through repeated small deposits. This action can result in a denial of service (DoS) for two critical functions: unlock and setLockDuration, thereby locking the user's funds indefinitely.
Impact
A malicious actor can repeatedly lock small amounts of tokens (even as small as 1 wei) on behalf of a legitimate user, causing the unlock time of all previously locked tokens to be extended with each new deposit. This malicious activity can effectively prevent the legitimate user from ever accessing their tokens or setting a new lock duration, leading to permanent loss of funds and functionality.
Lines of code
https://github.com/code-423n4/2024-05-munchables/blob/57dff486c3cd905f21b330c2157fe23da2a4807d/src/managers/LockManager.sol#L382 https://github.com/code-423n4/2024-05-munchables/blob/57dff486c3cd905f21b330c2157fe23da2a4807d/src/managers/LockManager.sol#L258 https://github.com/code-423n4/2024-05-munchables/blob/57dff486c3cd905f21b330c2157fe23da2a4807d/src/managers/LockManager.sol#L410
Vulnerability details
Description
The
lockOnBehalf
function allows any user to lock tokens on behalf of another user. A bad actor can exploit this function to perpetually extend the unlock time of a legitimate user's locked tokens through repeated small deposits. This action can result in a denial of service (DoS) for two critical functions:unlock
andsetLockDuration
, thereby locking the user's funds indefinitely.Impact
A malicious actor can repeatedly lock small amounts of tokens (even as small as 1 wei) on behalf of a legitimate user, causing the unlock time of all previously locked tokens to be extended with each new deposit. This malicious activity can effectively prevent the legitimate user from ever accessing their tokens or setting a new lock duration, leading to permanent loss of funds and functionality.
Proof of Concept
Initial lock by a legitimate user:
Attacker's action to extend the lock period:
Resulting state:
The
lockedTokens[target][tokenAddress]
will now aggregate the new quantity.The
unlockTime
is reset based on the current block time plus the lock duration inplayerSettings
.The unlock time for the legitimate user's tokens is now extended indefinitely each time a small deposit is made.
Impact on Critical Functions
Unlock Function:
Set Lock Duration Function:
Tools Used
Recommended Mitigation Steps
Approval Mechanism: Allow users to approve specific addresses that can lock tokens on their behalf, preventing unauthorized locking actions.
Assessed type
Access Control