In [1]:
    
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from statistics import mean, stdev, variance, median
import csv
mpl.rcParams['figure.dpi'] = 300
mpl.rcParams['savefig.dpi'] = 300
mpl.rcParams['axes.titlesize'] = "small"
mpl.rcParams['axes.labelsize'] = "large"
    
In [2]:
    
# 30 percent cheaters
w, h = 1000, 6
time30 = [[0 for x in range(100)] for y in range(h)]
status30 = [[0 for x in range(w)] for y in range(h)]
solver30 = [[0 for x in range(w)] for y in range(h)]
gasUsed30 = [[0 for x in range(w)] for y in range(h)]
with open('../data/30_percent_cheaters_1000.csv', 'rb') as csvfile:
    experiment30 = csv.DictReader(csvfile)
    for row in experiment30:
        status30[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Status'])
        solver30[int(row['Verifiers'])-1][int(row['Run'])] = (row['Solver'])
        gasUsed30[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Gas'])
with open('../data/30_percent_cheaters.csv', 'rb') as csvfile:
    experiment30 = csv.DictReader(csvfile)
    for row in experiment30:
        time30[int(row['Verifiers'])-1][int(row['Run'])] = float(row['Time'])
        
# 50 percent cheaters
time50 = [[0 for x in range(100)] for y in range(h)]
status50 = [[0 for x in range(w)] for y in range(h)]
solver50 = [[0 for x in range(w)] for y in range(h)]
gasUsed50 = [[0 for x in range(w)] for y in range(h)]
with open('../data/50_percent_cheaters_1000.csv', 'rb') as csvfile:
    experiment50 = csv.DictReader(csvfile)
    for row in experiment50:
        status50[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Status'])
        solver50[int(row['Verifiers'])-1][int(row['Run'])] = (row['Solver'])
        gasUsed50[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Gas'])
with open('../data/50_percent_cheaters.csv', 'rb') as csvfile:
    experiment50 = csv.DictReader(csvfile)
    for row in experiment50:
        time50[int(row['Verifiers'])-1][int(row['Run'])] = float(row['Time'])
        
# 70 percent cheaters
time70 = [[0 for x in range(100)] for y in range(h)]
status70 = [[0 for x in range(w)] for y in range(h)]
solver70 = [[0 for x in range(w)] for y in range(h)]
gasUsed70 = [[0 for x in range(w)] for y in range(h)]
with open('../data/70_percent_cheaters_1000.csv', 'rb') as csvfile:
    experiment70 = csv.DictReader(csvfile)
    for row in experiment70:
        status70[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Status'])
        solver70[int(row['Verifiers'])-1][int(row['Run'])] = (row['Solver'])
        gasUsed70[int(row['Verifiers'])-1][int(row['Run'])] = int(row['Gas'])
        
with open('../data/70_percent_cheaters.csv', 'rb') as csvfile:
    experiment70 = csv.DictReader(csvfile)
    for row in experiment70:
        time70[int(row['Verifiers'])-1][int(row['Run'])] = float(row['Time'])
    
In [3]:
    
# 30 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(time30)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(time30))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Time to complete computation in ms')
plt.setp(axes, xticks=[y+1 for y in range(len(time30))],
         xticklabels=xlabels)
plt.xticks()
# plt.ylim(0, 5000)
plt.show()
# 50 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(time50)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(time50))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Time to complete computation in ms')
plt.setp(axes, xticks=[y+1 for y in range(len(time50))],
         xticklabels=xlabels)
plt.xticks()
# plt.ylim(0, 5000)
plt.show()
# 70 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(time70)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(time70))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Time to complete computation in ms')
plt.setp(axes, xticks=[y+1 for y in range(len(time70))],
         xticklabels=xlabels)
plt.xticks()
# plt.ylim(0, 5000)
plt.show()
    
    
    
    
In [4]:
    
# 30 percent cheaters
i = 0
for item in time30:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
# 50 percent cheaters
i = 0
for item in time50:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
# 70 percent cheaters
i = 0
for item in time70:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
    
In [5]:
    
# 30 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(gasUsed30)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(gasUsed30))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Total gas consumed')
plt.setp(axes, xticks=[y+1 for y in range(len(gasUsed30))],
         xticklabels=xlabels)
plt.xticks()
plt.ylim(0, 1600000)
plt.show()
# 50 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(gasUsed50)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(gasUsed50))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Total gas consumed')
plt.setp(axes, xticks=[y+1 for y in range(len(gasUsed50))],
         xticklabels=xlabels)
plt.xticks()
plt.ylim(0, 1600000)
plt.show()
# 70 percent cheaters
fig, axes = plt.subplots()
axes.boxplot(gasUsed70)
xlabels = ['1', '2', '3', '4', '5', '6']
axes.yaxis.grid(True)
axes.set_xticks([y for y in range(len(gasUsed70))])
axes.set_xlabel('Number of verifiers')
axes.set_ylabel('Total gas consumed')
plt.setp(axes, xticks=[y+1 for y in range(len(gasUsed70))],
         xticklabels=xlabels)
plt.xticks()
plt.ylim(0, 1600000)
plt.show()
    
    
    
    
In [6]:
    
# 30 percent cheaters
i = 0
for item in gasUsed30:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
# 50 percent cheaters
i = 0
for item in gasUsed50:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
# 70 percent cheaters
i = 0
for item in gasUsed70:
    print xlabels[i]
    print "Mean: {}".format(mean(item))
    print "Median: {}".format(median(item))
    print "Min: {}".format(min(item))
    print "Max: {}".format(max(item))
    print "Standard deviation: {}".format(stdev(item))
    print "Variance: {}".format(variance(item))
    print "Outer 90 percentile: {}".format(np.percentile(item,90))
    print "Outer 95 percentile: {}".format(np.percentile(item,95))
    print "Outer 99 percentile: {}".format(np.percentile(item,99))
    print "-------------"
    i += 1
    
    
In [7]:
    
# 30 percent cheaters
failedJudgeSolutionAccepted30 = [0 for y in range(6)]
failedJudgeSolutionDeclined30 = [0 for y in range(6)]
noSolution30 = [0 for y in range(6)]
wrongAnswerAccepted30 = [0 for y in range(6)]
correct30 = [0 for y in range(6)]
for x in range(h):
    for y in range(w):
        if (status30[x][y] == 901) and (solver30[x][y] == "false"):
            failedJudgeSolutionAccepted30[x] += 1
        elif (status30[x][y] == 902) and (solver30[x][y] == "true"):
            failedJudgeSolutionDeclined30[x] += 1
        elif (status30[x][y] == 902) and (solver30[x][y] == "false"):
            noSolution30[x] += 1
        elif (status30[x][y] == 500) and (solver30[x][y] == "false"):
            wrongAnswerAccepted30[x] += 1
        else:
            correct30[x] += 1
# 50 percent cheaters
failedJudgeSolutionAccepted50 = [0 for y in range(6)]
failedJudgeSolutionDeclined50 = [0 for y in range(6)]
noSolution50 = [0 for y in range(6)]
wrongAnswerAccepted50 = [0 for y in range(6)]
correct50 = [0 for y in range(6)]
for x in range(h):
    for y in range(w):
        if (status50[x][y] == 901) and (solver50[x][y] == "false"):
            failedJudgeSolutionAccepted50[x] += 1
        elif (status50[x][y] == 902) and (solver50[x][y] == "true"):
            failedJudgeSolutionDeclined50[x] += 1
        elif (status50[x][y] == 902) and (solver50[x][y] == "false"):
            noSolution50[x] += 1
        elif (status50[x][y] == 500) and (solver50[x][y] == "false"):
            wrongAnswerAccepted50[x] += 1
        else:
            correct50[x] += 1
            
# 70 percent cheaters
failedJudgeSolutionAccepted70 = [0 for y in range(6)]
failedJudgeSolutionDeclined70 = [0 for y in range(6)]
noSolution70 = [0 for y in range(6)]
wrongAnswerAccepted70 = [0 for y in range(6)]
correct70 = [0 for y in range(6)]
for x in range(h):
    for y in range(w):
        if (status70[x][y] == 901) and (solver70[x][y] == "false"):
            failedJudgeSolutionAccepted70[x] += 1
        elif (status70[x][y] == 902) and (solver70[x][y] == "true"):
            failedJudgeSolutionDeclined70[x] += 1
        elif (status70[x][y] == 902) and (solver70[x][y] == "false"):
            noSolution70[x] += 1
        elif (status70[x][y] == 500) and (solver70[x][y] == "false"):
            wrongAnswerAccepted70[x] += 1
        else:
            correct70[x] += 1
    
In [23]:
    
xlabels = ['1', '2', '3', '4', '5', '6']
indexes = np.arange(len(xlabels))
width = 0.8
# 30 percent cheaters
bottom1, bottom2, bottom3 = [], [], []
for i in range(6):
    bottom1.append(correct30[i] + wrongAnswerAccepted30[i])
for i in range(6):
    bottom2.append(bottom1[i] + noSolution30[i])
for i in range(6):
    bottom3.append(bottom2[i] +failedJudgeSolutionAccepted30[i])  
# the barchart of the data
# plt.figure(figsize=(10,7))
plt.bar(indexes, correct30, width, color='#81c784', label='Accepted correct solution')
plt.bar(indexes, wrongAnswerAccepted30, width, color='#c62828', bottom=correct30, label='Resolve dispute not triggered and accepted wrong solution')
plt.bar(indexes, noSolution30, width, color='#bdbdbd', bottom=bottom1, label='Resolve dispute triggered and denied wrong solution')
plt.bar(indexes, failedJudgeSolutionAccepted30, width, color='#7e57c2', bottom=bottom2, label='Resolve dispute triggered, but accepted wrong solution')
plt.bar(indexes, failedJudgeSolutionDeclined30, width, color='#42a5f5', bottom=bottom3, label='Resolve dispute triggered, but denied correct solution')
plt.xlabel('Number of verifiers')
plt.ylabel('Number of computations')
plt.xticks(indexes, xlabels)
# plt.legend(loc='upper center', bbox_to_anchor=(0.7, 0.2), fancybox=True, shadow=True)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.83), fancybox=True, shadow=False)
plt.show()
# 50 percent cheaters
bottom1, bottom2, bottom3 = [], [], []
for i in range(6):
    bottom1.append(correct50[i] + wrongAnswerAccepted50[i])
for i in range(6):
    bottom2.append(bottom1[i] + noSolution50[i])
for i in range(6):
    bottom3.append(bottom2[i] +failedJudgeSolutionAccepted50[i])  
# the barchart of the data
# plt.figure(figsize=(10,7))
plt.bar(indexes, correct50, width, color='#81c784', label='Accepted correct solution')    
plt.bar(indexes, wrongAnswerAccepted50, width, color='#c62828', bottom=correct50, label='Resolve dispute not triggered and accepted wrong solution')
plt.bar(indexes, noSolution50, width, color='#bdbdbd', bottom=bottom1, label='Resolve dispute triggered and denied wrong solution')
plt.bar(indexes, failedJudgeSolutionAccepted50, width, color='#7e57c2', bottom=bottom2,label='Resolve dispute triggered, but accepted wrong solution')
plt.bar(indexes, failedJudgeSolutionDeclined50, width, color='#42a5f5', bottom=bottom3, label='Resolve dispute triggered, but denied correct solution')
plt.xlabel('Number of verifiers')
plt.ylabel('Number of computations')
plt.xticks(indexes, xlabels)
# plt.legend(loc='upper center', bbox_to_anchor=(0.7, 0.2), fancybox=True, shadow=True)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.83), fancybox=True, shadow=False)
plt.show()
# 70 percent cheaters
bottom1, bottom2, bottom3 = [], [], []
for i in range(6):
    bottom1.append(correct70[i] + wrongAnswerAccepted70[i])
for i in range(6):
    bottom2.append(bottom1[i] + noSolution70[i])
for i in range(6):
    bottom3.append(bottom2[i] +failedJudgeSolutionAccepted70[i])  
# the barchart of the data
# plt.figure(figsize=(10,7))
plt.bar(indexes, correct70, width, color='#81c784', label='Accepted correct solution')
plt.bar(indexes, wrongAnswerAccepted70, width, color='#c62828', bottom=correct70, label='Resolve dispute not triggered and accepted wrong solution')
plt.bar(indexes, noSolution70, width, color='#bdbdbd', bottom=bottom1, label='Resolve dispute triggered and denied wrong solution')
plt.bar(indexes, failedJudgeSolutionAccepted70, width, color='#7e57c2', bottom=bottom2,label='Resolve dispute triggered, but accepted wrong solution')
plt.bar(indexes, failedJudgeSolutionDeclined70, width, color='#42a5f5', bottom=bottom3, label='Resolve dispute triggered, but denied correct solution')
plt.xlabel('Number of verifiers')
plt.ylabel('Number of computations')
plt.xticks(indexes, xlabels)
# plt.legend(loc='upper center', bbox_to_anchor=(0.7, 0.2), fancybox=True, shadow=True)
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.83), fancybox=True, shadow=False)
plt.show()
    
    
    
    
In [ ]:
    
print "30%------------------------------"
print "Correct mean: {}".format(mean(correct30))
print "Correct standard deviation: {}".format(stdev(correct30))
print "Wrong mean: {}".format(mean(wrongAnswerAccepted30))
print "wrong standard deviation: {}".format(stdev(wrongAnswerAccepted30))
print "No solution mean: {}".format(mean(noSolution30))
print "No solution standard deviation: {}".format(stdev(noSolution30))
print "50%------------------------------"
print "Correct mean: {}".format(mean(correct50))
print "Correct standard deviation: {}".format(stdev(correct50))
print "Wrong mean: {}".format(mean(wrongAnswerAccepted50))
print "wrong standard deviation: {}".format(stdev(wrongAnswerAccepted50))
print "No solution mean: {}".format(mean(noSolution50))
print "No solution standard deviation: {}".format(stdev(noSolution50))
print "70%------------------------------"
print "Correct mean: {}".format(mean(correct70))
print "Correct standard deviation: {}".format(stdev(correct70))
print "Wrong mean: {}".format(mean(wrongAnswerAccepted70))
print "wrong standard deviation: {}".format(stdev(wrongAnswerAccepted70))
print "No solution mean: {}".format(mean(noSolution70))
print "No solution standard deviation: {}".format(stdev(noSolution70))
    
In [19]:
    
v1, v2, v3, v4, v5, v6 = time30[0], time30[1], time30[2], time30[3], time30[4], time30[5]
    
In [21]:
    
x = [(i + 1) for i in range(1000)]
plt.plot(x, v1, color='#000000')
plt.plot(x, v2, color='#78909c')
plt.plot(x, v3, color='#0d47a1')
plt.plot(x, v4, color='#311b92')
plt.plot(x, v5, color='#ce93d8')
plt.plot(x, v6, color='#e57373')
plt.legend(['{} verifier'.format(i + 1) for i in range(6)], loc='upper right')
plt.xlabel('Number of computation round')
plt.ylabel('Execution time in ms')
plt.grid(True)
plt.show()
    
    
In [27]:
    
for i in range(6):
    print "Verifier: {}".format(i + 1)
    print float(wrongAnswerAccepted30[i]/float(10))
    print float(wrongAnswerAccepted50[i]/float(10))
    print float(wrongAnswerAccepted70[i]/float(10))
    
    
In [ ]: