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

GimelSec - An inconsistency in the behaviour of balanceOf() and balanceOfBatch(). #108

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

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Mar 9, 2023

GimelSec

medium

An inconsistency in the behaviour of balanceOf() and balanceOfBatch().

Summary

balanceOf() checks _isActive() and _isEligible(), but balanceOfBatch() returns static _balanceOf directly.

Vulnerability Detail

The hats protocol overrides balanceOf() to checks _isActive() and _isEligible(), but it doesn't override balanceOfBatch(). The balanceOfBatch() returns static _balanceOf directly:

    function balanceOfBatch(address[] calldata owners, uint256[] calldata ids)
        public
        view
        virtual
        returns (uint256[] memory balances)
    {
        require(owners.length == ids.length, "LENGTH_MISMATCH");

        balances = new uint256[](owners.length);

        // Unchecked because the only math done is incrementing
        // the array index counter which cannot possibly overflow.
        unchecked {
            for (uint256 i = 0; i < owners.length; ++i) {
                balances[i] = _balanceOf[owners[i]][ids[i]];
            }
        }
    }

Impact

It's inconsistency in the behaviour of balanceOf() and balanceOfBatch().
It would fail if someone creates a new version of singer gates and misuses balanceOfBatch(). Also, some protocols will be broken if a third party protocol integrates the Hats protocol with balanceOfBatch().

Code Snippet

https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/lib/ERC1155/ERC1155.sol#L122-L139

Tool used

Manual Review

Recommendation

Override balanceOfBatch() and check _isActive() and _isEligible().

Duplicate of #85

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Mar 12, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Mar 29, 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 Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant