# Signer can avoid restrictions and change `safe` state variables

Reentrancy in HatsSignerGate.checkTransaction lets a signer overwrite stored Safe owners/threshold during a delegatecall, bypassing post-execution state checks.

- Payout: Audit contest
- Severity: medium
- Program: Hats Protocol
- Found by: bughuntoor
- Disclosed: 2024-11-15
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-11-hats-protocol-judging/issues/3
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-hats-protocol%3AM-1
- Tags: area:web3 domain:web3 impact:privesc kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained technique:source-review vuln:access-control vuln:business-logic vuln:reentrancy

**Target:** HatsSignerGate Zodiac module (Safe guard) checkTransaction/checkAfterExecution
**Root cause:** checkTransaction stores _existingOwnersHash/_existingThreshold/_existingFallbackHandler in storage but can be re-entered by a nested transaction, overwriting the saved baseline before checkAfterExecution runs.
**Steps:**
1. Signers sign a tx that delegatecalls an enabled target which alters Safe owners to just the attacker and threshold to 1.
2. Inside that delegatecall, the remaining owner submits and executes a second (arbitrary) transaction.
3. The nested call re-enters checkTransaction, overwriting _existingOwnersHash and _existingThreshold with the new (attacker-controlled) values.
4. Both inner and outer checkAfterExecution compare against the overwritten baseline and pass.
5. Owner list and threshold remain altered; attacker retains sole control of the multisig.
**How found:** Code reading of the guard: noticed checkTransaction writes baseline state to storage (not transient/local) and is re-entrant, so a nested call can overwrite the baseline before checkAfterExecution.
**Exploitation:** Attacker needs a signed delegatecall to an enabled target that mutates Safe owners/threshold; during execution they re-enter checkTransaction via a nested Safe transaction so the guard's saved baseline matches the mutated state, defeating the post-flight check.
**Escalation:** Sole remaining owner gains full control of the multisig until other owners re-claim their hats.
**Insight:** Guard-style pre/post checks that stash baseline state in storage are bypassable if the pre-check is re-entrant; look for guards storing expected state in contract storage rather than transient/immutable per-call context.

