Munchables - steadyman's results

A web3 point farming game in which Keepers nurture creatures to help them evolve, deploying strategies to earn them rewards in competition with other players.

General Information

Platform: Code4rena

Start Date: 22/05/2024

Pot Size: $20,000 USDC

Total HM: 6

Participants: 126

Period: 5 days

Judge: 0xsomeone

Total Solo HM: 1

Id: 379

League: ETH

Munchables

Findings Distribution

Researcher Performance

Rank: 87/126

Findings: 1

Award: $0.01

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2024-05-munchables/blob/57dff486c3cd905f21b330c2157fe23da2a4807d/src/managers/LockManager.sol#L257 https://github.com/code-423n4/2024-05-munchables/blob/57dff486c3cd905f21b330c2157fe23da2a4807d/src/managers/LockManager.sol#L258

Vulnerability details

Impact

The logic check in the setLockDuration function of the LockManager contract has a problem, which allows the lock duration to be decreased.

Proof of Concept

In the setLockDuration function's logic check, there is a verification for the new _duration, requiring uint32(block.timestamp) + uint32(_duration) < lockedTokens[msg.sender][tokenContract].unlockTime. However, the new unlockTime is set to lastLockTime + uint32(_duration). This results in the new unlockTime being less than the old unlockTime.

Example: Bob locks tokens with a duration of 10 days, making the unlockTime the 11th day. On the 4th day, Bob calls the setLockDuration function with _duration set to 7 days. This check passes, and the new unlockTime becomes the 8th day, thus reducing the lock duration.

Tools Used

Manual Audit

    function setLockDuration(uint256 _duration) external notPaused {
        if (_duration > configStorage.getUint(StorageKey.MaxLockDuration))
            revert MaximumLockDurationError();

        playerSettings[msg.sender].lockDuration = uint32(_duration);
        // update any existing lock
        uint256 configuredTokensLength = configuredTokenContracts.length;
        for (uint256 i; i < configuredTokensLength; i++) {
            address tokenContract = configuredTokenContracts[i];
            if (lockedTokens[msg.sender][tokenContract].quantity > 0) {
+                uint32 lastLockTime = lockedTokens[msg.sender][tokenContract]
+                    .lastLockTime;
                // check they are not setting lock time before current unlocktime
                  if (
+                    uint32(lastLockTime) + uint32(_duration) <
+                    lockedTokens[msg.sender][tokenContract].unlockTime
+                ) {
+                    revert LockDurationReducedError();
+                }

-                if (
-                    uint32(block.timestamp) + uint32(_duration) <
-                    lockedTokens[msg.sender][tokenContract].unlockTime
-                ) {
-                    revert LockDurationReducedError();
-                }

-                uint32 lastLockTime = lockedTokens[msg.sender][tokenContract]
-                    .lastLockTime;
                lockedTokens[msg.sender][tokenContract].unlockTime =
                    lastLockTime +
                    uint32(_duration);
            }
        }

        emit LockDuration(msg.sender, _duration);
    }

Assessed type

Other

#0 - c4-judge

2024-06-04T12:40:56Z

alex-ppg marked the issue as duplicate of #89

#1 - c4-judge

2024-06-05T12:53:41Z

alex-ppg marked the issue as satisfactory

#2 - c4-judge

2024-06-05T12:54:34Z

alex-ppg changed the severity to 3 (High Risk)

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter