def remove_swarm_metadata(code: bytes) -> bytes:
    """
    Remove swarm metadata from Solidity bytecode
    :param code:
    :return: Code without metadata
    """
    swarm = b'\xa1\x65bzzr0'
    position = code.find(swarm)
    if position == -1:
        raise ValueError('Swarm metadata not found in code %s' % code.hex())
    return code[:position]