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
Incompatibility between balanceOf and balanceOfBatch.
Summary
ERC1155 has a function balanceOfBatch not overridden by contract Hats. This function is public and does not account for the active/inactive status of a hat or whether the user is eligible; it instead returns the static balance of inputed users.
If a users use this balanceOfBatch function for checking the status of hats wearers, they will receive wrong result and make wrong decisions based on that.
Vulnerability Detail
Here is a POC:
contractIncompatibilityBetweenBalanceOfAndBatchBalanceOfisTestSetup {
function testIncompatibility() public {
(uint256[] memoryids, address[] memorywearers) =createHatsBranch(3, topHatId, topHatWearer, false);
// make hat number 2 inactive
vm.prank(_toggle);
hats.setHatStatus(ids[2], false);
uint256 balanceOfResult;
uint256[] memory balanceOfBatchResult;
balanceOfResult = hats.balanceOf(wearers[2], ids[2]);
balanceOfBatchResult = hats.balanceOfBatch(wearers, ids);
// balance of wearers[2] for ids[2] is returned differently from 2 functionsassertEq(balanceOfResult, 0);
assertEq(balanceOfBatchResult[2], 1);
}
}
command to test forge test --match-path test/Hats.t.sol -vvvv --match-contract IncompatibilityBetweenBalanceOfAndBatchBalanceOf
Impact
Incompatibility between balanceOf and balanceOfBatch
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
ktg
medium
Incompatibility between balanceOf and balanceOfBatch.
Summary
ERC1155 has a function
balanceOfBatch
not overridden by contractHats
. This function is public and does not account for the active/inactive status of a hat or whether the user is eligible; it instead returns thestatic balance
of inputed users.If a users use this
balanceOfBatch
function for checking the status of hats wearers, they will receive wrong result and make wrong decisions based on that.Vulnerability Detail
Here is a POC:
command to test
forge test --match-path test/Hats.t.sol -vvvv --match-contract IncompatibilityBetweenBalanceOfAndBatchBalanceOf
Impact
balanceOf
andbalanceOfBatch
Code Snippet
https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/Hats.sol#L1149-#L1162
Tool used
Manual Review
Recommendation
I recommend overriding function
balanceOfBatch
and return the same result withbalanceOf
Duplicate of #85
The text was updated successfully, but these errors were encountered: