Signers can bypass checks and change threshold within a transaction
The post-execution guard that was meant to stop signers from changing a Safe's signing threshold only compared the threshold against a value recalculated from the current owner list, so a transaction that also removed owners could lower the threshold and still pass. Signers could therefore reduce the threshold and gain more control over future transactions.
cducrest-brainbot Follow with obront
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-hats-judging/issues/52
Found by
cducrest-brainbot, obront
Summary
The checkAfterExecution() function has checks to ensure that the safe's threshold isn't changed by a transaction executed by signers. However, the parameters used by the check can be changed midflight so that this crucial restriction is violated.
Vulnerability Detail
The checkAfterExecution() is intended to uphold important invariants after each signer transaction is completed. This is intended to restrict certain dangerous signer behaviors. From the docs:
/// @notice Post-flight check to prevent
safesigners from removing this contract guard, changing any modules, or changing the threshold
However, the restriction that the signers cannot change the threshold can be violated.
To see how this is possible, let's check how this invariant is upheld. The following check is performed within the function:
if (safe.getThreshold() != _getCorrectThreshold()) {
revert SignersCannotChangeThreshold();
}
If we look up _getCorrectThreshold(), we see the following:
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;
}
As we can see, this means that the safe's threshold after the transaction must equal the valid signers, bounded by the minThreshold and maxThreshold.
However, this check does not ensure that the value returned by _getCorrectThreshold() is the same before and after the transaction. As a result, as long as the number of owners is also changed in the transaction, the condition can be upheld.
To illustrate, let's look at an example:
- Before the transaction, there are 8 owners on the vault, all signers. targetThreshold == 10 and minThreshold == 2, so the safe's threshold is 8 and everything is good.
- The transaction calls
removeOwner(), removing an owner from the safe and adjusting the threshold down to 7. - After the transaction, there will be 7 owners on the vault, all signers, the safe's threshold will be 7, and the check will pass.
This simple example focuses on using removeOwner() once to decrease the threshold. However, it is also possible to use the safe's multicall functionality to call removeOwner() multiple times, changing the threshold more dramatically.
Impact
Signers can change the threshold of the vault, giving themselves increased control over future transactions and breaking an important trust assumption of the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
Save the safe's current threshold in checkTransaction() before the transaction has executed, and compare the value after the transaction to that value from storage.
Discussion
spengrah
In one sense, this is sort of ok since we're still always ensuring that the threshold is "correct" based on the number of valid signers on the safe, and changing the threshold doesn't allow . If a valid signer is removed by a safe tx, they can re-claim and then everything is back to the way it was.
But in another sense, it does make it fairly difficult to conceptualize the system, and it would also be ideal to successfully follow the documentation 😉. In all, I think this is more of a medium severity.
The suggested solution should work, but likely isn't needed if we're also storing/comparing the full owner array in order to address #118 and #70.
cc @zobront
spengrah
Withdrawing the severity dispute since it would be quite painful if the signers continuously replaced existing signers to reach max signers, which could prevent replaced signers from reclaiming.
spengrah
https://github.com/Hats-Protocol/hats-zodiac/pull/5
zobront
@spengrah I believe this is still possible, if the safe is able to tamper with hat status or wearer eligibility and then reduce the threshold.
If this seems ok to you, then make sure to change the wording if your documentation and comments to not imply this isn't possible. If it's not ok with you, then I'd recommend implementing the recommended fix from this issue.
spengrah
@zobront ah ok, I see what you're saying. This is definitely something that should be documented more clearly: an assumption is that the safe itself (controlled by the signers) does not have authority over the signersHat(s), ie is neither an admin, eligibility module, or toggle module. It wouldn't make sense for this to be the case and still expect the signers to not be able to control their own hat(s).
So, this is ok, and I'll push a documentation/comments update.
zobront
Confirmed updated comments. This is still possible but is now clearly warned against.
jacksanford1
Based on the discussion above, the original issue was not fixed by https://github.com/Hats-Protocol/hats-zodiac/pull/5. After further deliberation, the protocol team opted to acknowledge the issue's existence (instead of fixing it) and update their documentation to better educate users about the potential for this issue.
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 guard recalculated the expected threshold from the post-transaction owner list instead of comparing against the threshold recorded before the transaction, so both values moved together.
Impact
Signers could lower the vault's threshold, giving themselves increased control over future transactions and breaking a trust assumption; the team later chose to document the behaviour rather than fix it.
What the attacker needed
Signer rights on the Safe; ability to submit a Safe transaction
The fix
The recommended fix was to store the threshold in checkTransaction before execution and compare it afterwards, but the team ultimately only updated the documentation to warn about the behaviour.
How it was found
- Start with a Safe that has eight owners, all valid signers, and a threshold of eight.
- Submit a transaction that calls removeOwner, which removes an owner and lowers the threshold to seven.
- The post-execution check recalculates the expected threshold as seven and passes, leaving the threshold changed.
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 needs a set number of owners to approve a transaction before it goes through; this number is called the threshold. A guard contract was supposed to stop owners from lowering that number, but it only checked that the number matched the current owner count, so removing an owner and lowering the threshold together slipped past the check.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.