targetThreshold can be set below minThreshold, violating important invariant
The contract checked that minThreshold was not above targetThreshold when setting the minimum, but did not perform the equivalent check when setting the target. An attacker or careless admin could set targetThreshold below minThreshold, causing the safe's threshold to drop below the required minimum and making all transactions fail.
Bauer Follow with carrot, cducrest-brainbot and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-hats-judging/issues/36
Found by
Bauer, carrot, cducrest-brainbot, obront, rvierdiiev
Summary
There are protections in place to ensure that minThreshold is not set above targetThreshold, because the result is that the max threshold on the safe would be less than the minimum required. However, this check is not performed when targetThreshold is set, which results in the same situation.
Vulnerability Detail
When the minThreshold is set on HatsSignerGateBase.sol, it performs an important check that minThreshold <= targetThreshold:
function _setMinThreshold(uint256 _minThreshold) internal {
if (_minThreshold > maxSigners || _minThreshold > targetThreshold) {
revert InvalidMinThreshold();
}
minThreshold = _minThreshold;
}
However, when targetThreshold is set, there is no equivalent check that it remains above minThreshold:
function _setTargetThreshold(uint256 _targetThreshold) internal {
if (_targetThreshold > maxSigners) {
revert InvalidTargetThreshold();
}
targetThreshold = _targetThreshold;
}
This is a major problem, because if it is set lower than minThreshold, reconcileSignerCount() will set the safe's threshold to be this value, which is lower than the minimum, and will cause all tranasctions to fail.
Impact
Settings that are intended to be guarded are not, which can lead to parameters being set in such a way that all transactions fail.
Code Snippet
Tool used
Manual Review
Recommendation
Perform a check in _setTargetThreshold() that it is greater than or equal to minThreshold:
function _setTargetThreshold(uint256 _targetThreshold) internal {
+ if (_targetThreshold < minThreshold) {
+ revert InvalidTargetThreshold();
+ }
if (_targetThreshold > maxSigners) {
revert InvalidTargetThreshold();
}
targetThreshold = _targetThreshold;
}
Discussion
spengrah
https://github.com/Hats-Protocol/hats-zodiac/pull/8
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
The setter for targetThreshold lacked the invariant check that targetThreshold must be greater than or equal to minThreshold, which the minThreshold setter enforced in the opposite direction.
Impact
Parameters intended to be guarded could be set so that the safe's threshold falls below the minimum, causing all transactions to fail.
What the attacker needed
Ability to set targetThreshold
The fix
A check should be added in _setTargetThreshold that reverts when the new target is below minThreshold; the linked pull request and 'Fix Approved' label indicate it was fixed.
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 smart contract here acts like a shared wallet that needs a certain number of signatures before money moves. It has a minimum number of signers required and a target number it aims for. The code only checked one direction of the relationship between these two numbers, so the target could be set below the minimum, which broke the wallet so nothing could be approved.
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.