You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
sherlock-admin opened this issue
Mar 9, 2023
· 0 comments
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
So it also has the public balanceOfBatch function that is exposed by the ÈRC1155 contract.
This however can return wrong results since it does not check that the wearer is eligible to wear the hat and if the hat is active.
Vulnerability Detail
This is the balanceOfBatch function:
function balanceOfBatch(address[] calldataowners, uint256[] calldataids)
publicviewvirtualreturns (uint256[] memorybalances)
{
require(owners.length== ids.length, "LENGTH_MISMATCH");
balances =newuint256[](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]];
}
}
}
As you can see it directly returns the values from the _balanceOf mapping.
The Hats.balanceOf function however first checks _isActive and _isEligible and only then queries the _balanceOf mapping:
function balanceOf(address_wearer, uint256_hatId)
publicviewoverride(ERC1155, IHats)
returns (uint256balance)
{
Hat storage hat = _hats[_hatId];
balance =0;
if (_isActive(hat, _hatId) &&_isEligible(_wearer, hat, _hatId)) {
balance =super.balanceOf(_wearer, _hatId);
}
}
Impact
Contracts that integrate with Hats and use the balanceOfBatch function get wrong results and misbehave.
The Hats contract should override the balanceOfBatch function and either revert when it is called (effectively disabling the function) or the function should include the _isActive(hat, _hatId) && _isEligible(_wearer, hat, _hatId) check.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
DuplicateA valid issue that is a duplicate of an issue with `Has Duplicates` labelMediumA valid Medium severity issueRewardA payout will be made for this issue
roguereddwarf
medium
Hats.balanceOfBatch returns wrong result
Summary
The
Hats
contract inherits fromERC1155
.So it also has the public
balanceOfBatch
function that is exposed by theÈRC1155
contract.This however can return wrong results since it does not check that the wearer is
eligible
to wear the hat and if the hat isactive
.Vulnerability Detail
This is the
balanceOfBatch
function:As you can see it directly returns the values from the
_balanceOf
mapping.The
Hats.balanceOf
function however first checks_isActive
and_isEligible
and only then queries the_balanceOf
mapping:Impact
Contracts that integrate with
Hats
and use thebalanceOfBatch
function get wrong results and misbehave.Code Snippet
https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/lib/ERC1155/ERC1155.sol#L122-L139
https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/Hats.sol#L1149-L1162
Tool used
Manual Review
Recommendation
The
Hats
contract should override thebalanceOfBatch
function and either revert when it is called (effectively disabling the function) or the function should include the_isActive(hat, _hatId) && _isEligible(_wearer, hat, _hatId)
check.Duplicate of #85
The text was updated successfully, but these errors were encountered: