Skip to content
Business logic Audit finding Intermediate

[Medium][Outdated State] `_removeSigner` incorrectly updates `signerCount` and safe `threshold`

The `_removeSigner` function incorrectly updates the `signerCount` and safe `threshold` when a previously inactive signer becomes active again. This can lead to an incorrect number of signatures required for transactions.

Allarious Follow with Bauer and duc

Originally disclosed on Sherlock

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

Found by

Allarious, Bauer, duc

Summary

_removeSigner can be called whenever a signer is no longer valid to remove an invalid signer. However, under certain situations, removeSigner incorrectly reduces the number of signerCount and sets the threshold incorrectly.

Vulnerability Detail

_removeSigner uses the code snippet below to decide if the number of signerCount should be reduced:

Solidity
        if (validSignerCount == currentSignerCount) {
            newSignerCount = currentSignerCount;
        } else {
            newSignerCount = currentSignerCount - 1;
        }

If first clause is supposed to be activated when validSignerCount and currentSignerCount are still in sync, and we want to remove an invalid signer. The second clause is for when we need to identify a previously active signer which is inactive now and want to remove it. However, it does not take into account if a previously in-active signer became active. In the scenario described below, the signerCount would be updated incorrectly:

(1) Lets imagine there are 5 signers where 0, 1 and 2 are active while 3 and 4 are inactive, the current signerCount = 3 (2) In case number 3 regains its hat, it will become active again (3) If we want to delete signer 4 from the owners' list, the _removeSigner function will go through the signers and find 4 valid signers, since there were previously 3 signers, validSignerCount == currentSignerCount would be false. (4) In this case, while the number of validSingerCount increased, the _removeSigner reduces one.

Impact

This can make the signerCount and safe threshold to update incorrectly which can cause further problems, such as incorrect number of signatures needed.

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

Code Snippet

No code snippet provided

Tool used

Manual Review

Recommendation

Check if the number of validSignerCount decreased instead of checking equality:

Solidity
@line 387 HatsSignerGateBase
- if (validSignerCount == currentSignerCount) {
+ if (validSignerCount >= currentSignerCount) {

Discussion

spengrah

This is another issue that can be avoided by using a dynamic getSignerCount instead of relying on the signerCount state variable.

cc @zobront

spengrah

https://github.com/Hats-Protocol/hats-zodiac/pull/6

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

Likely the code assumes that if the number of valid signers equals the stored count, no change is needed, but it fails to account for a previously inactive signer becoming active, leading to an incorrect decrement.

Impact

This can cause the signerCount and safe threshold to update incorrectly, potentially leading to an incorrect number of signatures needed for transactions.

What the attacker needed

A multi-signature wallet using HatsSignerGate; at least one inactive signer who can become active again; ability to call removeSigner

The fix

The fix should change the condition to check if validSignerCount is greater than or equal to currentSignerCount, and the issue was fixed according to the discussion.

How it was found

  1. Start with 5 signers where signers 0, 1, and 2 are active, and 3 and 4 are inactive, so signerCount is 3.
  2. Signer 3 regains their hat and becomes active again.
  3. Attempt to remove signer 4 from the owners' list.
  4. The _removeSigner function counts 4 valid signers, which does not equal the stored signerCount of 3, so it reduces signerCount by one incorrectly.

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.

This is a smart contract bug where removing a signer from a multi-signature wallet can mess up the count of active signers. If a signer who was inactive becomes active again, the code still subtracts one from the total, making the wallet think there are fewer signers than there really are. That can change how many signatures are needed to approve transactions, potentially making it harder or easier to move funds.

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.