Skip to content
Business logic Audit finding Intermediate

Safe threshold can be set above target threshold, causing transactions to revert

The contract's threshold reconciliation logic fails to lower the safe's threshold when the target threshold is set below the current safe threshold and the valid signer count exceeds the target. This leaves the safe threshold above the target, causing all subsequent transactions to revert due to a threshold validity check.

Allarious Follow with cccz, cducrest-brainbot and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-hats-judging/issues/44

Found by

Allarious, cccz, cducrest-brainbot, duc, obront, unforgiven

Summary

If a targetThreshold is set below the safe's threshold, the reconcileSignerCount() function will fail to adjust the safe's threshold as it should, leading to a mismatch that causes all transactions to revert.

Vulnerability Detail

It is possible and expected that the targetThreshold can be lowered, sometimes even lower than the current safe threshold.

In the setTargetThreshold() function, there is an automatic update to lower the safe threshold accordingly. However, in the event that the signerCount < 2, it will not occur. This could easily happen if, for example, the hat is temporarily toggled off.

But this should be fine! In this instance, when a new transaction is processed, checkTransaction() will be called, which calls reconcileSignerCount(). This should fix the problem by resetting the safe's threshold to be within the range of minThreshold to targetThreshold.

However, the logic to perform this update is faulty.

Solidity
uint256 currentThreshold = safe.getThreshold();
uint256 newThreshold;
uint256 target = targetThreshold; // save SLOADs

if (validSignerCount <= target && validSignerCount != currentThreshold) {
    newThreshold = validSignerCount;
} else if (validSignerCount > target && currentThreshold < target) {
    newThreshold = target;
}
if (newThreshold > 0) { ... update safe threshold ... }

As you can see, in the event that the validSignerCount is lower than the target threshold, we update the safe's threshold to validSignerCount. That is great.

In the event that validSignerCount is greater than threshold, we should be setting the safe's threshold to targetThreshold. However, this only happens in the else if clause, when currentThreshold < target.

As a result, in the situation where target < current <= validSignerCount, we will leave the current safe threshold as it is and not lower it. This results in a safe threshold that is greater than targetThreshold.

Here is a simple example:

  • valid signers, target threshold, and safe's threshold are all 10
  • the hat is toggled off
  • we lower target threshold to 9
  • the hat is toggled back on
  • if block above (validSignerCount <= target && validSignerCount != currentThreshold) fails because validSignerCount > target
  • else if block above (validSignerCount > target && currentThreshold < target) fails because currentThreshold > target
  • as a result, newThreshold == 0 and the safe isn't updated
  • the safe's threshold remains at 10, which is greater than target threshold

In the checkAfterExecution() function that is run after each transaction, there is a check that the threshold is valid:

Solidity
if (safe.getThreshold() != _getCorrectThreshold()) {
    revert SignersCannotChangeThreshold();
}

The _getCorrectThreshold() function checks if the threshold is equal to the valid signer count, bounded by the minThreshold on the lower end, and the targetThreshold on the upper end:

Solidity
function _getCorrectThreshold() internal view returns (uint256 _threshold) {
    uint256 count = _countValidSigners(safe.getOwners());
    uint256 min = minThreshold;
    uint256 max = targetThreshold;
    if (count < min) _threshold = min;
    else if (count > max) _threshold = max;
    else _threshold = count;
}

Since our threshold is greater than targetThreshold this check will fail and all transactions will revert.

Impact

A simple change to the targetThreshold fails to propagate through to the safe's threshold, which causes all transactions to revert.

Code Snippet

https://github.com/Hats-Protocol/hats-zodiac/blob/9455cc0957762f5dbbd8e62063d970199109b977/src/HatsSignerGateBase.sol#L95-L114

https://github.com/Hats-Protocol/hats-zodiac/blob/9455cc0957762f5dbbd8e62063d970199109b977/src/HatsSignerGateBase.sol#L183-L217

Tool used

Manual Review

Recommendation

Edit the if statement in reconcileSignerCount() to always lower to the targetThreshold if it exceeds it:

Diff
-if (validSignerCount <= target && validSignerCount != currentThreshold) {
+if (validSignerCount <= target) {
    newThreshold = validSignerCount;
-} else if (validSignerCount > target && currentThreshold < target) {
+} else {
    newThreshold = target;
}
-if (newThreshold > 0) { ... update safe threshold ... }
+if (newThreshold != currentThreshold) { ... update safe threshold ... }

Discussion

spengrah

This issue is also resolved by using a dynamic signerCount() function instead of relying on the signerCount state var. This is implemented in https://github.com/Hats-Protocol/hats-zodiac/pull/6, with an additional test to demonstrate added in https://github.com/Hats-Protocol/hats-zodiac/pull/7

MLON33

zobront added "Fix Approved" label

The original report as published on Sherlock, by Allarious. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 condition in `reconcileSignerCount()` only updates the safe's threshold to the target when the current threshold is below the target, missing the case where the current threshold is above the target but the valid signer count is also above the target.

Impact

All transactions revert because the safe's threshold remains above the target threshold, blocking normal operation.

What the attacker needed

TargetThreshold set below safe threshold; signerCount < 2 at time of setting; hat toggled off then on

The fix

The if statement in `reconcileSignerCount()` should be modified to always lower the threshold to the target if it exceeds it, and the update condition should check if the new threshold differs from the current one.

How it was found

  1. Set valid signers, target threshold, and safe's threshold all to 10.
  2. Toggle the hat off.
  3. Lower the target threshold to 9.
  4. Toggle the hat back on.
  5. Process a new transaction, which calls `checkTransaction()` and then `reconcileSignerCount()`.
  6. Observe that the safe's threshold remains at 10, causing `checkAfterExecution()` to revert.

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 manages a multi-signature wallet (a safe) where a certain number of signers must approve transactions. The contract has a target number of required approvals, but a bug prevents it from updating the safe's required approvals when the target is lowered, so the safe keeps requiring too many approvals and every transaction fails.

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.

More by Allarious

View all

8 more disclosed reports, best first.

More from Hats

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.