import ipaddress


def serialize_ip(ip):
    """
    Serializes an IP(v4/v6) address into the format required by DNSCrypt:
     - IPv6: the 16 bytes of the IPv6 address
     - IPv4: 10 zero bytes + 2 0xff bytes + the IPv4 address bytes
    """
    packed = ipaddress.ip_address(ip).packed
    if len(packed) == 16:
        return packed
    if len(packed) == 4:
        return b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff' + packed
    raise ValueError('Invalid IP')