Skip to content

SignatureChecker::isValidSignatureNow is broken for EIP7702 accounts #5707

@devdacian

Description

@devdacian

SignatureChecker::isValidSignatureNow is broken for EIP7702 accounts as:

  • these accounts have code
  • they sign using their private key as normal EOAs, so validation needs to occur via ECDSA.tryRecover

The current code ensures this wont happen, but the verification will be attempted only via isValidERC1271SignatureNow which is not correct for EIP7702 accounts:

    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        // @audit EIP7702 accounts have code, so `if` branch won't be executed
        if (signer.code.length == 0) {
            (address recovered, ECDSA.RecoverError err, ) = ECDSA.tryRecover(hash, signature);
            return err == ECDSA.RecoverError.NoError && recovered == signer;
        } else {
            return isValidERC1271SignatureNow(signer, hash, signature);
        }
    }

A correct implementation would first try ECDSA.tryRecover, then if that didn't work try isValidERC1271SignatureNow ? Something like:

    function isValidSignatureNow(address signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
        // try this first for EOA & EIP7702 accounts
        (address recovered, ECDSA.RecoverError err,) = ECDSA.tryRecover(hash, signature);
        if (err == ECDSA.RecoverError.NoError && recovered == signer) return true;

        // if first method failed, try EIP1271 smart wallet
        else return isValidERC1271SignatureNow(signer, hash, signature);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions