Пример #1
0
 def test1(self):
     a = pedersen.Pedersen(64)
     b = a.commit(1)
     c = bitproof(0, b, a.state)
     d = bitproof(1, b, a.state)
     self.assertTrue(verify(b.c, a.state, d))
     self.assertFalse(verify(b.c, a.state, c))
Пример #2
0
 def __init__(self):
     """Initializes three boards and commitment generator
     The first board is the normal board
     The second board is the commitment board for one's own use
     The third board is the public commitment board for opponent use
     """
     super().__init__()
     self.commitment_generator = pedersen.Pedersen(64)
     self.commitment_board = [None for _ in range(64)]
     self.public_commitments = [0 for _ in range(64)]
Пример #3
0
def t():
    x = 6400
    t = [[], [], [], [], []]
    c = []
    gen = pedersen.Pedersen(256)
    for j in range(x):
        if j % 64 == 0 and j != 0:
            start = time.time()
            l = pedersen.Pedersen.add_commitments(gen.state, *c)
            end = time.time()
            t[4].append(end-start)
            start = time.time()
            gen = pedersen.Pedersen(256)
            end = time.time()
            t[1].append(end - start)
        start = time.time()
        ab = gen.commit(j % 2)
        end = time.time()
        c.append(ab)
        t[0].append(end-start)
        start = time.time()
        v = pedersen.Pedersen.verify(j % 2, ab, gen.state)
        end = time.time()
        t[2].append(end-start)
        start = time.time()
        b = bitproof.bitproof(j % 2, ab, gen.state)
        end = time.time()
        t[3].append(end-start)
        print(j)
        
    print(t)  
    tt = []
    for a in t:
        tt.append(statistics.fmean(a))
    plt.xscale("log")
    plt.xlabel("Average Time (s)")
    plt.title("Action Speed")
    plt.barh(["Commit Value", "Create Pedersen Generator", "Verify Commitment", "Create Bit Proof", "Add 64 Commitments"], tt)
    plt.show()
Пример #4
0
def pedersen_distribution():
    """Returns tests for the distribution of public values
    for Pedersen commitments when the message is zero or one
    """ 
    x= 1000000
    gen = pedersen.Pedersen(256)
    c0 = []
    c1 = []
    for i in range(x):
        c0.append(gen.commit(0).c / 1.0)
        c1.append(gen.commit(1).c / 1.0)
        if (i % (x / 100) == 0):
            print(100 * i / x)
    print(stats.ks_2samp(c0, c1))
    print("ks 0:", stats.kstest(c0, "uniform"))
    print("ks 1:", stats.kstest(c1, "uniform"))
    print("0", stats.describe(c0))
    print("1", stats.describe(c1))
    print("0 repeats:", stats.find_repeats(c0))
    print("1 repeats:", stats.find_repeats(c1))
    print("0 entropy:", stats.entropy(c0))
    print("1 entropy:", stats.entropy(c1))
    input()
Пример #5
0
def bitproof_test(z, title, same_graph = True, x = 100000):
    """Print's histogram for selected value of bitproof commitment
    along with statistical tests on the values
    z takes the form of lambda x: x.(variable here)
    same_graph is whether the histograms are on the same page
    x is the number of trials
    """
    gen = pedersen.Pedersen(64)
    c0 = gen.commit(0)
    c1 = gen.commit(1)
    b0 = []
    b1 = []
    for i in range(x):
        b0.append(z(bitproof.bitproof(0, c0, gen.state)) / 1.0)
        b1.append(z(bitproof.bitproof(1, c1, gen.state)) / 1.0)
        if (i % (x/100) == 0):
            print(100 * i / x)
    print(title)
    print(stats.ks_2samp(b0, b1))
    print("ks 0:", stats.kstest(b0, "uniform"))
    print("ks 1:", stats.kstest(b1, "uniform"))
    print("0", stats.describe(b0))
    print("1", stats.describe(b1))
    print("0 repeats:", stats.find_repeats(b0))
    print("1 repeats:", stats.find_repeats(b1))
    print("0 entropy:", stats.entropy(b0))
    print("1 entropy:", stats.entropy(b1))
    plt.title(f"Histogram of {title} Values")
    plt.hist(b0, bins = "auto", range = (0, gen.state.p / 1.0)) 
    if not same_graph:
        plt.ylabel("Occurences")
        plt.xlabel("Variable value")
        plt.show()
    plt.hist(b1, bins = "auto", range = (0, gen.state.p / 1.0))
    plt.ylabel("Occurences")
    plt.xlabel("Variable value")
    plt.show()
Пример #6
0
def pedersen_histogram():
    """Plots histograms of public values of Pedersen commitments
    when message is zero or one
    """
    x= 1000000
    gen = pedersen.Pedersen(256)
    c0 = []
    c1 = []
    for i in range(x):
        c0.append(gen.commit(0).c / 1.0)
        c1.append(gen.commit(1).c / 1.0)
        if (i % 10000 == 0):
            print(i // 10000)

    plt.title("Histogram of Commitments when Message Equals Zero")
    plt.hist(c0, bins = "auto", range = (0, gen.state.p / 1.0))  
    plt.ylabel("Occurences")
    plt.xlabel("Commitment value")
    plt.show()
    plt.title("Histogram of Commitments when Message Equals One")
    plt.hist(c1, bins = "auto", range = (0, gen.state.p / 1.0))  
    plt.ylabel("Occurences")
    plt.xlabel("Commitment value")
    plt.show()
Пример #7
0
def time_generate():
    """Returns the time to generate a Pedersen commitment of selected sizes"""
    c = []
    x = 1000
    a = ("16", "32", "64", "128", "256")
    times = [[],[],[],[],[]]
    t = []
    e = []
    for i in range(len(a)):
        for j in range(x):
            start = time.time()
            gen = pedersen.Pedersen(2 ** (4 + i))
            end = time.time()
            times[i].append(end - start)
            if (j % 25 == 0):
                print(j)
        print(i)
        t.append(statistics.fmean(times[i]))
        e.append(statistics.stdev(times[i]))
    plt.ylabel("Bits")
    plt.xlabel("Time (avg over 1000 trials) (s)")
    plt.title("Commitment Bit Length vs Time of Generation")
    plt.barh(a, t, xerr = e)
    plt.show()