Skip to content
Race condition Audit finding Advanced

Signer can avoid restrictions and change `safe` state variables

The HatsSignerGate contract stores the Safe's owners and threshold before a delegatecall to check afterwards that they haven't changed. A signer can re-enter checkTransaction during the delegatecall, overwriting the stored values with new ones, so the post-check passes and the signer can become the sole owner with threshold 1.

bughuntoor Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-hats-protocol-judging/issues/3

Found by

bughuntoor

Summary

In order to make sure that a delegatecall does not change Safe's state, HSG's checkTransaction stores the current threshold, owners list and fallback handler. Then, after the call is executed, checkAfterExecution is supposed to verify that these variables have not been changed.

Solidity
    if (operation == Enum.Operation.DelegateCall) {
      // case: DELEGATECALL
      // We disallow delegatecalls to unapproved targets
      if (!enabledDelegatecallTargets[to]) revert DelegatecallTargetNotEnabled();

      // Otherwise record the existing owners and threshold for post-flight checks to ensure that Safe state has not
      // been altered
      _existingOwnersHash = keccak256(abi.encode(owners));
      _existingThreshold = threshold;
      _existingFallbackHandler = safe.getSafeFallbackHandler();

However, since the checkTransaction can be re-entered by a new call, these restrictions can easily be bypassed. If the delegatecall changes the owners and the threshold, the executing signer can then just provide a new transaction to be executed with the new owners being just him and threshold set to 1. This will then override the above stored variables. Because of this the checkAfterExecution check will also succeed.

Root Cause

Possible reentrancy within checkTransaction

Attack Path

  1. Signers sign a tx which would alter the owners list and set the threshold to 1.
  2. Within that delegatecall, the only remaining owner signs a new transaction and executes it. It doesn't realistically mater what the tx is.
  3. checkTransaction is entered. _existingOwnersHash and _existingThreshold are overwritten to their new values.
  4. The checkAfterExecution on both the inner and the outer call check against the altered values, hence they both succeed.
  5. In the end, the intended restrictions are bypassed and the ownerlist and threshold are both overwritten.
  6. The user who has remained the only owner has full access over the multi-sig until the other owners re-claim their hats.

Affected Code

https://github.com/sherlock-audit/2024-11-hats-protocol/blob/main/hats-zodiac/src/HatsSignerGate.sol#L471

Impact

Users can bypassed intended restrictions not to be able to overwrite the owner list and threshold variables.

Mitigation

If checkTransaction is entered, and the transient variables have already been assigned values, revert if the values differ from the current ones.

Discussion

spengrah

Fix PR: https://github.com/Hats-Protocol/hats-zodiac/pull/81

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Hats-Protocol/hats-zodiac/pull/81

The original report as published on Sherlock, by bughuntoor. 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 reentrancy in checkTransaction allows the stored owner hash and threshold to be overwritten during a delegatecall, so the post-execution check compares against the new values.

Impact

A signer could bypass the intended restriction and become the sole owner with threshold 1, gaining full control of the multi-sig until other owners re-claim their hats.

What the attacker needed

Signer with a hat; ability to sign and execute a transaction

The fix

The issue was fixed by reverting if checkTransaction is re-entered and the transient variables already have different values.

How it was found

  1. Signers sign a transaction that would alter the owners list and set the threshold to 1.
  2. Within that delegatecall, the only remaining owner signs and executes a new transaction.
  3. checkTransaction is entered again, overwriting the stored owner hash and threshold with the new values.
  4. checkAfterExecution on both the inner and outer calls check against the altered values and both succeed.
  5. The intended restrictions are bypassed and the owner list and threshold are overwritten.

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 multi-signature wallet (Safe) requires several owners to approve transactions. The HatsSignerGate contract tries to prevent a delegatecall (a call that runs another contract's code in the Safe's context) from changing the list of owners or the number of approvals needed. However, the check can be run again while the first call is still in progress, letting an attacker overwrite the saved values and bypass the restriction.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by bughuntoor

View all

16 more disclosed reports, best first.

More from HatsSignerGate v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.