If signer gate is deployed to safe with more than 5 existing modules, safe will be bricked
When the signer gate is attached to an existing Safe that already has more than five modules, the gate only counts the first five, so its stored module count is wrong. Every later transaction then fails the module-hash check and reverts, leaving the Safe unusable.
cducrest-brainbot Follow with juancito, obront and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-hats-judging/issues/43
Found by
cducrest-brainbot, juancito, obront, roguereddwarf
Summary
HatsSignerGate can be deployed with a fresh safe or connected to an existing safe. In the event that it is connected to an existing safe, it pulls the first 5 modules from that safe to count the number of connected modules. If there are more than 5 modules, it silently only takes the first five. This results in a mismatch between the real number of modules and enabledModuleCount, which causes all future transactions to revert.
Vulnerability Detail
When a HatsSignerGate is deployed to an existing safe, it pulls the existing modules with the following code:
(address[] memory modules,) = GnosisSafe(payable(_safe)).getModulesPaginated(SENTINEL_MODULES, 5);
uint256 existingModuleCount = modules.length;
Because the modules are requested paginated with 5 as the second argument, it will return a maximum of 5 modules. If the safe already has more than 5 modules, only the first 5 will be returned.
The result is that, while the safe has more than 5 modules, the gate will be set up with enabledModuleCount = 5 + 1.
When a transaction is executed, checkTransaction() will get the hash of the first 6 modules:
(address[] memory modules,) = safe.getModulesPaginated(SENTINEL_OWNERS, enabledModuleCount);
_existingModulesHash = keccak256(abi.encode(modules));
After the transaction, the first 7 modules will be checked to compare it:
(address[] memory modules,) = safe.getModulesPaginated(SENTINEL_OWNERS, enabledModuleCount + 1);
if (keccak256(abi.encode(modules)) != _existingModulesHash) {
revert SignersCannotChangeModules();
}
Since it already had more than 5 modules (now 6, with HatsSignerGate added), there will be a 7th module and the two hashes will be different. This will cause a revert.
This would be a high severity issue, except that in the comments for the function it says:
/// @dev Do not attach HatsSignerGate to a Safe with more than 5 existing modules; its signers will not be able to execute any transactions
This is the correct recommendation, but given the substantial consequences of getting it wrong, it should be enforced in code so that a safe with more modules reverts, rather than merely suggested in the comments.
Impact
If a HatsSignerGate is deployed and connected to a safe with more than 5 existing modules, all future transactions sent through that safe will revert.
Code Snippet
Tool used
Manual Review
Recommendation
The deployHatsSignerGate() function should revert if attached to a safe with more than 5 modules:
function deployHatsSignerGate(
uint256 _ownerHatId,
uint256 _signersHatId,
address _safe, // existing Gnosis Safe that the signers will join
uint256 _minThreshold,
uint256 _targetThreshold,
uint256 _maxSigners
) public returns (address hsg) {
// count up the existing modules on the safe
(address[] memory modules,) = GnosisSafe(payable(_safe)).getModulesPaginated(SENTINEL_MODULES, 5);
uint256 existingModuleCount = modules.length;
+ (address[] memory modulesWithSix,) = GnosisSafe(payable(_safe)).getModulesPaginated(SENTINEL_MODULES, 6);
+ if (modules.length != moduleWithSix.length) revert TooManyModules();
return _deployHatsSignerGate(
_ownerHatId, _signersHatId, _safe, _minThreshold, _targetThreshold, _maxSigners, existingModuleCount
);
}
Discussion
spengrah
Based on other findings, considering removing the ability for any other modules to exist alongside HSG. If we go that route, the fix here would likely be to revert if modulesWith1.length > 0.
cc @zobront
zobront
Great, I agree with that.
spengrah
https://github.com/Hats-Protocol/hats-zodiac/pull/10
MLON33
zobront added "Fix Approved" label
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the setup code asks the Safe for its modules in a page limited to five entries and treats that page as the complete list, so the stored module count is too low.
Impact
All future transactions sent through that Safe will revert, effectively bricking it; the text notes the function comments already warn against this setup.
What the attacker needed
An existing Safe with over 5 modules; deployer attaches the gate to that Safe
The fix
The deployment function should revert when the Safe has more modules than the gate can count, and the project later approved a change to reject any pre-existing modules.
How it was found
- Deploy the signer gate and connect it to an existing Safe that already has more than five modules.
- The gate records a module count of five plus itself.
- Send a transaction through the Safe.
- The module-hash comparison fails and the transaction reverts.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A Safe is a shared crypto wallet that can have extra helper programs called modules attached to it. This gate counted only the first five helpers and remembered the wrong total, so its safety check on every later payment failed and the wallet could no longer send anything.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.