<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ecdsa_verify_compact(msg32, sig, pub):
 """ Takes a message of length 32 and a signed message and a pubkey Returns True if the signature is valid """

    assert isinstance(msg32, bytes)
    assert len(msg32) == 32
    # Check if pubkey has been bin_electrum encoded.
    # If so, append \04 to the front of the key, to make sure the length is 65
    if len(pub) == 64:
        pub = b'\04'+pub
    assert len(pub) == 65
    _check_signature(sig)

    # Setting the pubkey array
    c_sig = ffi.new("secp256k1_ecdsa_signature *")

    # converts the recoverable signature to a signature
    lib.secp256k1_ecdsa_recoverable_signature_convert(
        ctx,
        c_sig,
        _parse_to_recoverable_signature(sig)
    )

    is_valid = lib.secp256k1_ecdsa_verify(
        ctx,
        c_sig,  # const secp256k1_ecdsa_signature
        msg32,  # const unsigned char
        _deserialize_pubkey(pub)  # const secp256k1_pubkey
    )
    return is_valid == 1