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
linking of hat trees can freeze hat operations because of gas limit
Summary
hats._checkAdmin function has numerous external function calls. When making this call, the gas consumption may exceed the transaction and block gas limit of 30m, resulting in failure. This is particularly true when the tree has a large number of levels (linked) and external contract call (eligibility) consumes a significant amount of gas.
Vulnerability Detail
Most of hats functions (like mint, transfer, change details, approve link) check if the msg.sender is admin by calling _checkAdmin
_checkAdmin calls isWearerOfHat for each level of the tree: // search up _hatId's local address space for an admin hat that the _user wears while (adminLocalHatLevel > 0) { if (isWearerOfHat(_user, getAdminAtLocalLevel(_hatId, adminLocalHatLevel))) { return isAdmin = true; }
isWearerOfHat is calling an eligibility contract that can consume a considerable amount of gas.
So the _checkAdmin is calling a gas-intensive function multiple times and when the hat tree has lots of levels, it can fail because of the gas limit of a block.
Impact
top-level admins can't do any operation on lower-level hats when the tree grows too big.
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
Ace-30
high
linking of hat trees can freeze hat operations because of gas limit
Summary
hats._checkAdmin
function has numerous external function calls. When making this call, the gas consumption may exceed the transaction and block gas limit of 30m, resulting in failure. This is particularly true when the tree has a large number of levels (linked) and external contract call (eligibility) consumes a significant amount of gas.Vulnerability Detail
Most of hats functions (like mint, transfer, change details, approve link) check if the msg.sender is admin by calling
_checkAdmin
_checkAdmin
callsisWearerOfHat
for each level of the tree:// search up _hatId's local address space for an admin hat that the _user wears while (adminLocalHatLevel > 0) { if (isWearerOfHat(_user, getAdminAtLocalLevel(_hatId, adminLocalHatLevel))) { return isAdmin = true; }
isWearerOfHat
is calling an eligibility contract that can consume a considerable amount of gas._checkAdmin
is calling a gas-intensive function multiple times and when the hat tree has lots of levels, it can fail because of the gas limit of a block.Impact
top-level admins can't do any operation on lower-level hats when the tree grows too big.
Code Snippet
https://github.com/more-reese/hats-protocol/blob/2e22c755512eaacb619e38b9e57668529cbb9c34/src/Hats.sol#L779-L797
Tool used
Manual Review
Recommendation
Optimize gas consumption of _checkAdmin
Duplicate of #96
The text was updated successfully, but these errors were encountered: