Nested linked trees could cause recursion stack overflow
Summary
There is no limit on the depth of nested linked trees. Hats protocol could suffer from recursion stack overflow because of the Solidity stack slots limit.
Vulnerability Detail
There are many recursive functions in the Hats.sol and HatsIdUtilities.sol. And they would traverse the linked trees. If the depth of the linked trees are too large, those functions could suffer from recursion stack overflow because of the Solidity stack slots limit.
Impact
Those recursive functions suffer from recursion stack overflow.
GimelSec
medium
Nested linked trees could cause recursion stack overflow
Summary
There is no limit on the depth of nested linked trees. Hats protocol could suffer from recursion stack overflow because of the Solidity stack slots limit.
Vulnerability Detail
There are many recursive functions in the
Hats.sol
andHatsIdUtilities.sol
. And they would traverse the linked trees. If the depth of the linked trees are too large, those functions could suffer from recursion stack overflow because of the Solidity stack slots limit.Impact
Those recursive functions suffer from recursion stack overflow.
Code Snippet
https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/HatsIdUtilities.sol#L96 https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/HatsIdUtilities.sol#L184 https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/HatsIdUtilities.sol#L151 https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/HatsIdUtilities.sol#L194 https://github.com/Hats-Protocol/hats-protocol/blob/fafcfdf046c0369c1f9e077eacd94a328f9d7af0/src/Hats.sol#L831
Tool used
Manual Review
Recommendation
Don’t use recursive functions, use loops instead. Or add a limit on the depth of linked trees.
Duplicate of #96