def test_or_and_dlrne(): secrets, secret_values, secret_dict = get_secrets(4) generators = make_generators(4) lhs_values = [x * g for x, g in zip(secret_values, generators)] y3 = secret_values[2] * generators[3] p1 = DLNotEqual( [lhs_values[0], generators[0]], [lhs_values[1], generators[1]], secrets[0], bind=True, ) p2 = DLNotEqual([lhs_values[1], generators[1]], [y3, generators[3]], secrets[1], bind=True) andp_nested = AndProofStmt(p1, p2) orp = OrProofStmt(andp_nested, p1, p2) prov = orp.get_prover(secret_dict) ver = orp.get_verifier() precom = prov.precommit() ver.process_precommitment(precom) com = prov.commit() chal = ver.send_challenge(com) resp = prov.compute_response(chal) assert ver.verify(resp)
def test_or_proof_manual(params): """ TODO: Clarify what is being tested here. """ p1, p2, secrets = params orproof = OrProofStmt(p1, p2, p1, p2, p1, p2) subproofs = orproof.subproofs rep = 0 chosen = [] sims = [True] while rep < 10: sims = [] # Make random subproofs simulated. for proof in subproofs: is_simulated = random.choice([True, False]) sims.append(is_simulated) proof.set_simulated(is_simulated) if all(sims): continue for i in range(30): # Choose a subproof, look if it was a valid choice, store the result prov = orproof.get_prover(secrets) chosen.append(sims[orproof.chosen_idx] == False) rep += 1 assert all(chosen)
def test_or_proof(params): p1, p2, secrets = params orproof = OrProofStmt(p1, p2, p1, p2, p1, p2) prov = orproof.get_prover(secrets) verif = orproof.get_verifier() com = prov.commit() chal = verif.send_challenge(com) resp = prov.compute_response(chal) # Here we see that some responses have an identical first element. # The only one with a different first element is the non-simulated one. assert verif.verify(resp)
def test_or_and_proof_composition(params): p1, p2, secrets = params andp = AndProofStmt(p1, p2) g1 = 7 * p1.bases[0] g2 = 8 * p1.bases[0] xb = Secret(name="xb") xa = Secret(name="xa") p0 = DLRep(7 * g1 + 18 * g2, xb * g1 + xa * g2) secrets[xa] = 7 secrets[Secret(name="xc")] = 18 orproof = OrProofStmt(p0, andp) prover = orproof.get_prover(secrets) verifier = orproof.get_verifier() assert verify(verifier, prover)