Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

bin2chen - mintDepositInQueue() queue funds may be locked #167

Closed
sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Closed

bin2chen - mintDepositInQueue() queue funds may be locked #167

sherlock-admin opened this issue Mar 27, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 27, 2023

bin2chen

high

mintDepositInQueue() queue funds may be locked

Summary

if a malicious receiver is a contract and reverts directly onERC1155Received, which causes mintDepositInQueue() revert and the funds of the users in front of this receiver will be locked

Vulnerability Detail

mintDepositInQueue() is used to execute deposit requests that are in the queue.
The code is as follows:

    function mintDepositInQueue(uint256 _epochId, uint256 _operations)
        external
        epochIdExists(_epochId)
        epochHasNotStarted(_epochId)
        nonReentrant
    {
        // make sure there is already a new epoch set
        // epoch has not started
        QueueItem[] memory queue = depositQueue;
        uint256 length = depositQueue.length;

        // dont allow minting if epochId is 0
        if (_epochId == 0) revert InvalidEpochId();

        if (length == 0) revert OverflowQueue();
        // relayers can always input a very big number to mint all deposit queues, without the need to read depostQueue length first
        if (_operations > length) _operations = length;

        // queue is executed from the tail to the head
        // get last index of queue
        uint256 i = length - 1;
        while ((length - _operations) <= i) {

            _mintShares( //<---------------If receiver is a contract, perform a revert at onERC1155Received(),will block queue
                queue[i].receiver,
                _epochId,
                queue[i].assets - relayerFee
            );
            emit Deposit(
                msg.sender,
                queue[i].receiver,
                _epochId,
                queue[i].assets - relayerFee
            );
            depositQueue.pop();
            if (i == 0) break;
            unchecked {
                i--;
            }
        }

        emit RelayerMinted(_epochId, _operations);

        asset.safeTransfer(msg.sender, _operations * relayerFee);
    }

The queue will be executed by FILO
But there is a problem here, _mintShares() may forever revert
if a malicious receiver is a contract and reverts directly onERC1155Received, which causes mintDepositInQueue() revert and the queue to be blocked and the funds of the users in front of this receiver will be locked
Example:
depositQueue[0] = jack , assets=100
depositQueue[1] = bob, assets=100
depositQueue[2] = Alice , assets=1 -----> Alice is a contract and revert in onERC1155Received()
depositQueue[3].....

In this case, jack and bob's funds will be locked

****Note: mintRollovers() also has the same problem

Impact

queue funds may be locked

Code Snippet

https://github.com/sherlock-audit/2023-03-Y2K/blob/main/Earthquake/src/v2/Carousel/Carousel.sol#L334

Tool used

Manual Review

Recommendation

Suggest adding a methods to the factory.sol , it can remove a certain index of depositQueue from Carousel

Duplicate of #468

@github-actions github-actions bot closed this as completed Apr 3, 2023
@github-actions github-actions bot added High A valid High severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Apr 3, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Apr 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant