Skip to content
Crypto Audit finding Advanced

If a hat is owned by address(0), phony signatures will be accepted by the safe

The signature validation function uses ecrecover, which returns address(0) for malformed signatures. If a hat is owned by address(0), such phony signatures are accepted as valid, allowing transactions without sufficient support to execute.

duc Follow with obront

Originally disclosed on Sherlock

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

Found by

duc, obront

Summary

If a hat is sent to address(0), the multisig will be fooled into accepting phony signatures on its behalf. This will throw off the proper accounting of signatures, allowing non-majority transactions to pass and potentially allowing users to steal funds.

Vulnerability Detail

In order to validate that all signers of a transaction are valid signers, HatsSignerGateBase.sol implements the countValidSignatures() function, which recovers the signer for each signature and checks isValidSigner() on them.

The function uses ecrecover to get the signer. However, ecrecover is well known to return address(0) in the event that a phony signature is passed with a v value other than 27 or 28. See this example for how this can be done.

In the event that this is a base with only a single hat approved for signing, the isValidSigner() function will simply check if the owner is the wearer of a hat:

Solidity
function isValidSigner(address _account) public view override returns (bool valid) {
    valid = HATS.isWearerOfHat(_account, signersHatId);
}

On the Hats.sol contract, this simply checks their balance:

Solidity
function isWearerOfHat(address _user, uint256 _hatId) public view returns (bool isWearer) {
    isWearer = (balanceOf(_user, _hatId) > 0);
}

... which only checks if it is active or eligible...

Solidity
function balanceOf(address _wearer, uint256 _hatId)
    public
    view
    override(ERC1155, IHats)
    returns (uint256 balance)
{
    Hat storage hat = _hats[_hatId];

    balance = 0;

    if (_isActive(hat, _hatId) && _isEligible(_wearer, hat, _hatId)) {
        balance = super.balanceOf(_wearer, _hatId);
    }
}

... which calls out to ERC1155, which just returns the value in storage (without any address(0) check)...

Solidity
function balanceOf(address owner, uint256 id) public view virtual returns (uint256 balance) {
    balance = _balanceOf[owner][id];
}

The result is that, if a hat ends up owned by address(0) for any reason, this will give blanket permission for anyone to create a phony signature that will be accepted by the safe.

You could imagine a variety of situations where this may apply:

  • An admin minting a mutable hat to address(0) to adjust the supply while waiting for a delegatee to send over their address to transfer the hat to
  • An admin sending a hat to address(0) because there is some reason why they need the supply slightly inflated
  • An admin accidentally sending a hat to address(0) to burn it

None of these examples are extremely likely, but there would be no reason for the admin to think they were putting their multisig at risk for doing so. However, the result would be a free signer on the multisig, which would have dramatic consequences.

Impact

If a hat is sent to address(0), any phony signature can be accepted by the safe, leading to transactions without sufficient support being executed.

This is particularly dangerous in a 2/3 situation, where this issue would be sufficient for a single party to perform arbitrary transactions.

Code Snippet

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

Tool used

Manual Review

Recommendation

The easiest option is to add a check in countValidSignatures() that confirms that currentOwner != address(0) after each iteration.

For extra security, you may consider implementing a check in balanceOf() that errors if we use address(0) as the address to check. (This is what OpenZeppelin does in their ERC721 implementation: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/7f028d69593342673492b0a0b1679e2a898cf1cf/contracts/token/ERC721/ERC721.sol#L62-L65)

Discussion

zobront

No fix made for this but it's solved by the fix to #50.

MLON33

No fix made for this but it's solved by the fix to #50.

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

MLON33

zobront added "Fix Approved" label

The original report as published on Sherlock, by duc. 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 signature validation function does not check that the recovered signer is not address(0), and the hat ownership check does not reject address(0), so a malformed signature that recovers to address(0) is considered valid if address(0) owns a hat.

Impact

If a hat is owned by address(0), any phony signature can be accepted, allowing transactions without sufficient support to execute; this is particularly dangerous in a 2/3 multisig where a single party could perform arbitrary transactions.

What the attacker needed

A hat is owned by address(0); attacker can submit a transaction with a phony signature

The fix

The issue was fixed by the fix to issue #50, as noted in the discussion.

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 multisig wallet requires several signatures to approve a transaction. The code that checks signatures can be tricked into accepting a fake signature if a special token (a 'hat') is owned by the zero address, which is like a black hole. This means an attacker could get a fake signature counted as valid and bypass the need for enough real signatures.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by duc

View all

5 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.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.