Verifies a zero-knowledge proof.
    @errorOnFail: Raise an exception if the proof does not hold.

def verify(x, t, y, pi, errorOnFail=True):
    """
    Verifies a zero-knowledge proof.
    @errorOnFail: Raise an exception if the proof does not hold.
    """
    # Unpack the proof
    p,_,_ = pi

    # Verify types
    assertType(x, str)
    assertType(t, str)
    assertType(y, G1Element)
    assertType(p, G2Element)

    # TODO: beta can be pre-computed while waiting for a server response.
    beta = hashG1(t, x)

    # Compute q = e( H(t,m), P)**kw two ways
    q1 = pair(beta, p)
    q2 = pair(y, generatorG2())

    # The BLS signature is valid when q1 == q2
    if q1 == q2:
        return True

    if errorOnFail:
        raise Exception("BLS signature failed verification")
    else:
        return False