def test_pc_log_batch(t): pc = PolyCommitLog() phi = polynomials_over(ZR).random(t) r = ZR.random() c = pc.commit(phi, r) witnesses = pc.batch_create_witness(phi, r) assert pc.verify_eval(c, 4, phi(4), witnesses[3])
def test_hbacss2_size_benchmark_batch_creation(benchmark, t): pc = PolyCommitLog(degree_max=t) pc.preprocess_prover(16) r = ZR.random() phis = [] for _ in range(t): phi_curr = polynomials_over(ZR).random(t) phis.append(phi_curr) benchmark(pc.double_batch_create_witness, phis, r)
def test_pc_log(t): pc = PolyCommitLog() phi = polynomials_over(ZR).random(t) # ToDo: see if other polycommits return the commit randomness # rather than expecting it as arg r = ZR.random() c = pc.commit(phi, r) witness = pc.create_witness(phi, r, 3) assert pc.verify_eval(c, 3, phi(3), witness) assert not pc.verify_eval(c, 4, phi(3), witness) assert not pc.verify_eval(G1.rand(), 3, phi(3), witness)
def test_double_batch_pc_log_batch_differing_degrees(t): pc = PolyCommitLog() n = 2*t+1 phi1 = polynomials_over(ZR).random(t) phi2 = polynomials_over(ZR).random(t) r = ZR.random() c1 = pc.commit(phi1, r) c2 = pc.commit(phi2, r) witnesses = pc.double_batch_create_witness([phi1, phi2], r, n=n) assert pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[3]) assert pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[3], degree=t) assert not pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[3], degree=t+1) assert not pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[3], degree=t-1)
def test_double_batch_pc_log_batch_prove_and_verify(t): pc = PolyCommitLog() phi1 = polynomials_over(ZR).random(t) phi2 = polynomials_over(ZR).random(t) phi3 = polynomials_over(ZR).random(t) r = ZR.random() c1 = pc.commit(phi1, r) c2 = pc.commit(phi2, r) witnesses = pc.double_batch_create_witness([phi1, phi2], r) assert pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[3]) assert not pc.batch_verify_eval([c1,c2], 3, [phi1(4), phi2(4)], witnesses[3]) assert not pc.batch_verify_eval([c1,c2], 4, [phi1(4), phi2(4)], witnesses[2]) assert not pc.batch_verify_eval([c1,c1], 4, [phi1(4), phi2(4)], witnesses[3])
def test_hbacss2_size_benchmark_batch_verify(benchmark, t): pc = PolyCommitLog(degree_max=t) pc.preprocess_verifier(16) phis = [] r = ZR.random() cs = [] for _ in range(t): phi_curr = polynomials_over(ZR).random(t) phis.append(phi_curr) c_curr = pc.commit(phi_curr, r) cs.append(c_curr) witnesses = pc.double_batch_create_witness(phis, r) i = 4 phis_at_4 = [] for j in range(len(phis)): phis_at_4.append(phis[j](i)) benchmark(pc.batch_verify_eval, cs, i, phis_at_4, witnesses[i - 1])
def test_hbacss2_actual_pcl_all_correct(benchmark_router, benchmark, batch_multiple, t): from pypairing import G1, ZR loop = asyncio.get_event_loop() n = 3 * t + 1 g, h, pks, sks = get_avss_params_pyp(n, t) values = [ZR.random()] * batch_multiple * (t + 1) * (t + 1) crs = [g] params = (t, n, g, h, pks, sks, crs, values) pcl = PolyCommitLog(degree_max=t) pcl.preprocess_verifier(16) pcl.preprocess_prover(16) def _prog(): loop.run_until_complete( hbacss2_actual_pcl_all_correct(benchmark_router, params, pcl)) benchmark(_prog)
from pytest import mark from honeybadgermpc.betterpairing import ZR from honeybadgermpc.polynomial import polynomials_over from honeybadgermpc.poly_commit_log import PolyCommitLog import pickle import cProfile t = 21 pc = PolyCommitLog(degree_max=t) r = ZR.random() phis = [] r = ZR.random() cs = [] for _ in range(3 * t + 1): phi_curr = polynomials_over(ZR).random(t) phis.append(phi_curr) c_curr = pc.commit(phi_curr, r) cs.append(c_curr) cProfile.run("pc.double_batch_create_witness(phis, r)")
# t = 20 # pc = PolyCommitLog(degree_max=t) # pc.preprocess_prover() # r = ZR.random() # phis = [] # cs = [] # for _ in range(polycount): # phi_curr = polynomials_over(ZR).random(t) # phis.append(phi_curr) # benchmark(pc.double_batch_create_witness, phis, r) if __name__ == "__main__": t = 20 # t = 2 pc = PolyCommitLog(degree_max=t) pc.preprocess_prover() phis = [] r = ZR.random() cs = [] for _ in range(6 * (t + 1)): phi_curr = polynomials_over(ZR).random(t) phis.append(phi_curr) c_curr = pc.commit(phi_curr, r) cs.append(c_curr) # cProfile.run("pc.double_batch_create_witness(phis, r)") witnesses = pc.double_batch_create_witness(phis, r) i = 4 phis_at_4 = [] for j in range(len(phis)): phis_at_4.append(phis[j](i))