-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.py
More file actions
731 lines (621 loc) · 31.3 KB
/
Run.py
File metadata and controls
731 lines (621 loc) · 31.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
# -*- coding: UTF-8 -*-
import subprocess
import argparse
import random
import time
import os,shutil
import ctypes,sys
import heapq
import generate_input
import json
PROJECT_DIR = "/home/fuying/EVMFuzzer" # NEED TO BE MODIFIED
contractPATH = PROJECT_DIR + "/contract/"
testPATH = PROJECT_DIR + "/TestOut/"
curC = 0
totalVarient = 0
X1 = 0 # different output
X2 = 0 # more gasUsed
X3 = 0 # less gasUsed
X4 = 0 # same gasUsed
X5 = 0 # more opSeqLen
X6 = 0 # less opSeqLen
X7 = 0 # same opSeqLen
fmt = '\033[0;3{}m{}\033[0m'.format
class color:
BLACK = 0 #黑
RED = 1 #红
GREEN = 2 #绿
YELLOW = 3 #棕
BLUE = 4 #蓝
PURPLE = 5 #紫
CYAN = 6 #青
GRAY = 7 #灰
def show_help():
"""
Show receving arguments
"""
welcome = "WELCOME TO EVMFUZZER!"
print(fmt(color.YELLOW, welcome.center(os.get_terminal_size().columns))) # width: columns height: lines
print("\nVERSION:")
print(" 2.0.1")
print("\nSTEPS:")
print(" 1 >> Download and setup the environment.")
print(" 2 >> Upload user's EVM and the interface.")
print(" 3 >> Fuzzing.")
print(" 4 >> Sending the report.")
def create_folder(dirPATH):
"""
Create folders needed
"""
binPATH = dirPATH + "bincode/"
seedPATH = dirPATH + "seed/"
outputPATH = dirPATH + "output/"
if os.path.exists(binPATH) == False :
os.makedirs(binPATH)
if os.path.exists(seedPATH) == False :
os.makedirs(seedPATH)
if os.path.exists(outputPATH) == False :
os.makedirs(outputPATH)
return binPATH, seedPATH, outputPATH
def parse_args():
"""
Parse input arguments
"""
parser = argparse.ArgumentParser(description='EVMFuzzer')
parser.add_argument('--file', dest='file', default="myContract.sol", type=str)
parser.add_argument('--func', dest='func', default="multiPath", type=str)
parser.add_argument('--bin', dest='bin', default="MyContract", type=str)
parser.add_argument('--sig', dest='sig',
default="0x87f71cef00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002",
type=str)
args = parser.parse_args()
return args
# delete pragma solidiy xxxx
# in case of compiler version problem
def preProcess(seedPATH, fileName):
"""
Preprocess of smart contracts
"""
f1 = open(contractPATH + fileName, 'r')
f2 = open(seedPATH + "PreProcess_" + fileName, 'w')
for _, line in enumerate(f1):
if line.find("pragma") >= 0:
pass
else:
f2.write(line)
f1.close()
f2.close()
def update_weight(dirPATH, fileName, combination):
"""
Update mutator weights
"""
# need mutator_diff_file.json
diff_file = open(dirPATH + fileName, 'r')
diff_list = diff_file.readlines()
weight = {} # an empty dict
cnt = 0
for i in range(len(diff_list)):
cnt += int(diff_list[i])
for i in range(len(diff_list)):
weight[i+1] = float(int(diff_list[i]) / cnt)
# print("Weight : {}".format(weight))
# ret = list(map(weight.index, heapq.nlargest(len(weight), weight)))
ret = sorted(weight.items(), key=lambda x: x[1], reverse=True)
m_queue = []
for i in range(len(ret)) :
m_queue.append(ret[i][0])
# print("Mutator_queue : {}".format(m_queue))
choice = []
if combination == 1 :
# choice.append(m_queue[0])
for i in range(len(m_queue)) :
if i % 2 == 0 :
choice.append(m_queue[i])
elif combination == 2 :
for i in range(len(m_queue)) :
if i % 2 != 0 :
choice.append(m_queue[i])
elif combination == 3 :
choice.append(m_queue[0])
choice.append(m_queue[len(m_queue)-1])
elif combination == 4 :
choice.append(m_queue[random.randint(0, len(m_queue)-1)])
return weight, choice
def editLine(dirPATH, filename, lineno, diff):
fro = open(dirPATH+filename, "r")
current_line = 0
while current_line < lineno:
fro.readline()
current_line += 1
seekpoint = fro.tell()
frw = open(dirPATH+filename, "r+")
frw.seek(seekpoint, 0)
# read the line we want to discard
test = fro.readline() # 读入一行进内存 同时! 文件指针下移实现删除
test = diff
frw.writelines(test)
# now move the rest of the lines in the file
# one line back
chars = fro.readline()
while chars:
frw.writelines(chars)
chars = fro.readline()
fro.close()
frw.truncate()
frw.close()
def del_folder(path) :
"""
Empty the folder
"""
for i in os.listdir(path) :
path_file = os.path.join(path, i)
if os.path.isfile(path_file) :
os.remove(path_file)
else :
del_folder(path_file)
def scheduling(contractList, diff_pri, time_pri):
"""
Dynamic Priority Scheduling Algorithm
"""
# print(contractList, diff_pri, time_pri)
sortList = []
priority = {}
for i in range(len(contractList)):
priority[i] = 0.7 * diff_pri[contractList[i]] + 0.3 * time_pri[contractList[i]]
# sorted by priority
data = [(pri, name) for pri, name in zip(priority, contractList)]
data.sort(reverse=True)
sortList = [name for pri, name in data]
# update time priority
for i in range(1, len(contractList)):
time_pri[contractList[i]] += 1
return sortList
def main():
# args = parse_args()
if os.path.exists(testPATH) :
shutil.rmtree(testPATH)
os.makedirs(testPATH)
global curC
global totalVarient
global X1
global X2
global X3
global X4
global X5
global X6
global X7
# upload user's interface
print(fmt(color.RED, "\nPlease put your source code under **myEVM folder** and provide the trasaction interface."))
print(fmt(color.RED, "The interface form should like: xxxxxx --code A --input B"))
print(fmt(color.RED, "where A is the runtime code of contract, and B is the input data for transaction."))
print(fmt(color.RED, "\n"))
### default API
ori = "python3 " + PROJECT_DIR + "/myEVM/runTx.py --code A --data B"
print(fmt(color.YELLOW, "E.g. python3 /home/usr/project/myEVM/runTx.py --code A --data B (The default value is set.)"))
userAPI = input()
if userAPI != "":
ori=userAPI
need_prefix = True
print(fmt(color.RED, "\n"))
print(fmt(color.RED, "Does the input data need '0x' prefix? The default setting is Yes. (Y/N)"))
flag = input().upper()
if flag.find("N") >= 0 :
need_prefix = False
maxIter = 100
print(fmt(color.RED, "\n"))
print(fmt(color.RED, "Please set fuzz times: (The default setting is 100)"))
times = input()
if times != "":
maxIter = int(times)
for _, _, filenames in os.walk(contractPATH, followlinks=True):
# Step 1.遍历合约
for fileName in filenames:
curC += 1
dirPATH = testPATH + "contract" + str(curC) + "/"
binPATH, seedPATH, outputPATH = create_folder(dirPATH)
contractList = []
diff_pri = {} # an empty dict
time_pri = {}
# 清空 diffHis文件 bincode/ seed/
# if os.path.exists(dirPATH + "diffHis") :
# diffhistory = open(dirPATH + "diffHis", 'w')
# diffhistory.seek(0)
# diffhistory.truncate()
# diffhistory.close()
# del_folder(binPATH)
# del_folder(seedPATH)
preProcess(seedPATH, fileName)
fileName = "PreProcess_" + fileName
# 生成函数签名
# p = subprocess.Popen("solc " + seedPATH + fileName + " --hashes -o " + dirPATH, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
retcode = subprocess.call("solc " + seedPATH + fileName + " --hashes -o " + dirPATH, shell=True)
if(retcode == 1):
os.remove(seedPATH + fileName)
continue
print(fmt(color.YELLOW, "Generate function signature, Done!"))
# print("Done!")
# p1 = input()
# 初始种子
contractList.append(fileName)
for f in os.listdir(dirPATH):
if os.path.splitext(f)[1] == '.signatures':
sigfile = open(dirPATH + f, "r")
line = sigfile.read().splitlines()
# Step 2.遍历函数
for signature in line:
pos1 = signature.find('(')
pos2 = signature.find(')')
funcName = signature[10:pos1]
sig = "0x" + signature[:8]
dataList = signature[pos1+1:pos2].split(',')
# check parameter type
canDeal = True
for i, val in enumerate(dataList) :
if (val.find('bool') == -1) and (val.find('uint') == -1) and (val.find('int') == -1) and (val.find('address') == -1):
canDeal = False
break
if (val.find('[') != -1) and (val.find(']') != -1) : # 数组
canDeal = False
break
if canDeal == False :
continue
inputData = generate_input.make(dataList)
sigName = sig + inputData
print(fmt(color.RED, "Select contract: "),fileName)
print(fmt(color.RED, "Select function: "), funcName)
# print(fmt(color.YELLOW, "Select contract: {}, function: {}".format(fileName, funcName))
print(fmt(color.RED, "Input data: "),sigName)
# print("Select contract: {}, function: {}".format(fileName, funcName))
# print("Input data: {}".format(sigName))
#p2 = input()
choice = []
weight = {}
index = 0
# 循环
while index < maxIter:
# a = index % (len(contractList))
# fileName = contractList[a]
print(fmt(color.YELLOW, "Start iteration {}: ".format(index)))
if index == 0:
pass
else:
contractList = scheduling(contractList, diff_pri, time_pri)
fileName = contractList[0]
if index == 0:
contract = fileName
else:
select = random.randint(1, 4)
select_name = ['EvenComb', 'OddComb', 'ExtremeComb', 'RandomComb']
print(fmt(color.RED, "Selected combined strategy in #iter {}: ".format(index)),select_name[select-1])
# print("Selected combined strategy in #iter{}: {}".format(index, select_name[select-1]))
weight, choice = update_weight(dirPATH, "mutator_diff", select) # combined strategy
shutil.copyfile(seedPATH + fileName, seedPATH + fileName.split(".sol")[0] + "_" + str(index) + ".sol" )
print(fmt(color.RED, "Combined mutators: "),choice)
# print("Combined mutators: {}".format(choice))
# p3 = input()
for i in range(len(choice)) :
retcode = subprocess.call(
"python3 " + PROJECT_DIR + "/mutators_weight.py --file " + fileName.split(".sol")[0] + "_" + str(index) + ".sol"
+ " --dir " + seedPATH + " --func " + funcName + " --select " + str(choice[i]),
shell=True)
if retcode == 1 :
continue
contract = fileName.split(".sol")[0] + "_" + str(index) + ".sol"
# 删除bin文件夹 solc编译
# subprocess.call("rm -rf " + dirPATH + "bincode", shell=True)
# print("Generating bytecode.")
retcode = subprocess.call("solc --bin-runtime " + seedPATH + contract + " -o " + binPATH + "bincode_" + funcName + "_" + str(index), shell=True)
# p = subprocess.Popen("solc --bin-runtime " + seedPATH + contract + " -o " + binPATH + "bincode_" + funcName + "_" + str(index), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# sout = p.stderr.readlines()
# if "Error" in sout:
# print(contract)
# os._exit(0)
# os.remove(seedPATH + contract)
# if contract in contractList :
# contractList.remove(contract)
# continue
if(retcode == 1):
print(retcode, contract)
# os._exit(0)
os.remove(seedPATH + contract)
if contract in contractList :
contractList.remove(contract)
continue
# print("Done!")
print(fmt(color.YELLOW, "Generating bytecode Done!"))
print("\n")
# 读取bincode
path_list = binPATH + "bincode_" + funcName + "_" + str(index) + "/"
for f in os.listdir(path_list):
if os.path.splitext(f)[1] == '.bin-runtime': # 判断文件后缀
codefile = open(path_list + f, "r")
bincode = codefile.read()
codefile.close()
shutil.copyfile(seedPATH + contract, path_list + contract)
# 4个平台运行
retcode = subprocess.call(
"/usr/local/bin/node " + PROJECT_DIR + "/benchmarkEVMs/jsEVM/js_runcode.js --code " + bincode + "--sig " + sigName + " > " + outputPATH + "jsout.json",
shell=True)
if retcode == 0 :
# print("jsevm Success!")
print(fmt(color.YELLOW, "jsevm Success!"))
else :
# print("jsevm Fail!")
print(fmt(color.RED, "jsevm Fail!"))
retcode = subprocess.call(
"python3 " + PROJECT_DIR + "/benchmarkEVMs/py-evm/test_tx.py --data " + bincode + " --sig " + sigName + " > " + outputPATH + "pyout.json",
shell=True)
if retcode == 0 :
print(fmt(color.YELLOW, "pyevm Success!"))
# print("pyevm Success!")
else :
print(fmt(color.RED, "pyevm Fail!"))
# print("pyevm Fail!")
retcode = subprocess.call(
"./benchmarkEVMs/evm --debug --json --code " + bincode + " --input " + sigName[2:] + " run > " + outputPATH + "gethout.json",
shell=True)
if retcode == 0 :
# print("geth Success!")
print(fmt(color.YELLOW, "geth Success!"))
else :
# print("geth Fail!")
print(fmt(color.RED, "geth Fail!"))
# aleth trace
retcode = subprocess.call(
"./benchmarkEVMs/aleth-vm trace --code " + bincode + " --mnemonics --input " + sigName + " > " + outputPATH + "aletraceout",
shell=True)
retcode = subprocess.call(
"python3 " + PROJECT_DIR + "/utils/cpp_convert_json_1.py " + outputPATH + "aletraceout " + " > " + outputPATH + "alethout.json",
shell=True)
# aleth output
retcode = subprocess.call(
"./benchmarkEVMs/aleth-vm stats --code " + bincode + " --mnemonics --input " + sigName + " > " + outputPATH + "aleresultout",
shell=True)
retcode = subprocess.call(
"python3 " + PROJECT_DIR + "/utils/cpp_convert_json_2.py " + outputPATH + "aleresultout " + " >> " + outputPATH + "alethout.json",
shell=True)
if retcode == 0 :
# print("aleth Success!")
print(fmt(color.YELLOW, "aleth Success!"))
else :
# print("aleth Fail!")
print(fmt(color.RED, "aleth Fail!"))
# test EVM
tmp = ori.replace("A", bincode)
if need_prefix:
cmd = tmp.replace("B", sigName)
else :
cmd = tmp.replace("B", sigName[2:])
# print(cmd)
retcode = subprocess.call(cmd + " > " + outputPATH + "myout.json",
shell=True)
if retcode == 0 :
print(fmt(color.YELLOW, "TestEVM Success!"))
else :
# print("TestEVM Fail!")
print(fmt(color.RED, "TestEVM Fail!"))
time.sleep(5)
# 比较结果 diff
retcode = subprocess.call(
"/usr/local/bin/node " + PROJECT_DIR + "/utils/cmp.js --js_file "
+ outputPATH + "jsout.json" + " --py_file "
+ outputPATH + "pyout.json" + " --cpp_file "
+ outputPATH + "gethout.json" + " --geth_file "
+ outputPATH + "alethout.json" + " --ret_dir "
+ dirPATH + "newdiff" + " --txdata " + sigName + " --resfile " + dirPATH + "result.json" ,
shell=True)
# print("Compare diff.")
time.sleep(5)
try :
open(dirPATH + "newdiff", "r")
except :
os.mknod(dirPATH + "newdiff")
newdiffFile = open(dirPATH + "newdiff", "r")
if os.path.getsize(dirPATH + "newdiff") == 0:
newdiff = 0
else :
newdiff = int(newdiffFile.read().strip())
newdiffFile.close()
try :
open(dirPATH + "diff", "r")
except :
os.mknod(dirPATH + "diff")
diffFile = open(dirPATH + "diff", "r")
if os.path.getsize(dirPATH + "diff") == 0:
olddiff = 0
else :
olddiff = int(diffFile.read().strip())
diffFile.close()
if newdiff > olddiff:
# 更新diff文件
diffFile = open(dirPATH + "diff", "w")
diffFile.write(str(newdiff))
diffFile.close()
contractList.append(contract)
# record priority
diff_pri[contract] = newdiff
time_pri[contract] = 0
if index == 0 :
diff_pri[contract] = newdiff
time_pri[contract] = 0
# 写 diff history 文件
if index == 0:
diffhistory = open(dirPATH + "diffHis", "a")
diffhistory.write(contract + "_" + "first" + "_" + str(newdiff).strip() + '\n')
# write mutator weight
diffhistory.write(str(weight) + '\n')
diffhistory.close()
else:
diffhistory = open(dirPATH + "diffHis", "a")
diffhistory.write(contract + "_" + str(choice) + "_" + str(newdiff).strip() + '\n')
# write mutator weight
diffhistory.write(str(weight) + '\n')
diffhistory.close()
# print("Update contract diff.")
# 写 mutator_diff 文件
if index == 0:
mutatordiffFile = open(dirPATH + "mutator_diff", "w")
for i in range(1, 9):
mutatordiffFile.write(str(newdiff).strip()+'\n')
mutatordiffFile.close()
else:
for i in range(len(choice)):
editLine(dirPATH, "mutator_diff", choice[i]-1, str(newdiff).strip()+'\n')
# mutatordiffFile = open(dirPATH + "mutator_diff", "w")
# for i in range(1, 6):
# if choice==i:
# mutatordiffFile.write(str(newdiff).strip() + '\n')
# mutatordiffFile.close()
# print("Update mutator diff.")
# record Testing result
# print(fmt(color.YELLOW, "Collecting information."))
# print("Collecting information.")
jsFile = open(outputPATH + "jsout.json", 'r', encoding='utf-8')
pyFile = open(outputPATH + "pyout.json", 'r', encoding='utf-8')
gethFile = open(outputPATH + "gethout.json", 'r', encoding='utf-8')
alethFile = open(outputPATH + "alethout.json", 'r', encoding='utf-8')
myFile = open(outputPATH + "myout.json", 'r', encoding='utf-8')
js_output, py_output, geth_output, aleth_output, my_output = "", "", "", "", ""
js_gas, py_gas, geth_gas, aleth_gas, my_gas = 0, 0, 0, 0, 0
js_op, py_op, geth_op, aleth_op, my_op = 0, 0, 0, 0, 0
for line in jsFile.readlines():
if line.find("output") >= 0 :
dic = json.loads(line)
js_output = dic['output']
js_gas = int(dic['gasUsed'], 16)
else:
js_op += 1
jsFile.close()
for line in pyFile.readlines():
if line.find("output") >= 0 :
dic = json.loads(line)
py_output = dic['output']
py_gas = int(dic['gasUsed'], 16)
else:
py_op += 1
pyFile.close()
for line in gethFile.readlines():
if line.find("output") >= 0 :
dic = json.loads(line)
geth_output = dic['output']
geth_gas = int(dic['gasUsed'], 16)
else:
geth_op += 1
gethFile.close()
for line in alethFile.readlines():
if line.find("output") >= 0 :
dic = json.loads(line)
aleth_output = dic['output']
aleth_gas = int(dic['gasUsed'], 16)
else:
aleth_op += 1
alethFile.close()
for line in myFile.readlines():
if line.find("output") >= 0 :
dic = json.loads(line)
my_output = dic['output']
my_gas = int(dic['gasUsed'], 16)
else:
my_op += 1
myFile.close()
# compare and count
avg_gas = int((js_gas + py_gas + geth_gas + aleth_gas) / 4)
avg_op = int((js_op + py_op + geth_op + aleth_op) / 4)
# output
if (my_output != js_output) and (my_output != py_output) and (my_output != geth_output) and (my_output != aleth_output):
X1 += 1
# gasUsed
if my_gas > int(1.3 * avg_gas) :
X2 += 1
elif my_gas < int(0.8 * avg_gas) :
X3 += 1
else :
X4 += 1
# opcode sequence
if my_op > int(1.55 * avg_op) :
X5 += 1
elif my_op < int(1.35 * avg_op) :
X6 += 1
else :
X7 += 1
print("\n")
print(fmt(color.YELLOW, "Collecting information Done!"))
# print("Done!")
#p4 = input()
index += 1
totalVarient += 1
def send_report(time1, time2):
"""
Show final report
"""
# print(totalVarient, X1, X2, X3, X4, X5, X6, X7)
title = "Detection Report"
print(fmt(color.YELLOW, title.center(os.get_terminal_size().columns)))
if totalVarient == 0:
print("ERROR! Exception occurs and no work done.")
return 0
per1 = round((100.0 * X1 / totalVarient), 2)
per2 = round((100.0 * X2 / totalVarient), 2)
per3 = round((100.0 * X3 / totalVarient), 2)
per4 = round((100.0 * X4 / totalVarient), 2)
per5 = round((100.0 * X5 / totalVarient), 2)
per6 = round((100.0 * X6 / totalVarient), 2)
per7 = round((100.0 * X7 / totalVarient), 2)
print("\nAfter {:.2f}s running, EVMFuzzer successfully generated {} seeds.".format((time2-time1), totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per1)+'%'), end='')
print(" ({}/{}) of the tests, the output results are different from the standard execution.".format(X1, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per2)+'%'), end='')
print(" ({}/{}) of the tests, the gas consuming are more than the average value.".format(X2, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per3)+'%'), end='')
print(" ({}/{}) of the tests, the gas consuming are less than the average value.".format(X3, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per4)+'%'), end='')
print(" ({}/{}) of the tests, the gas consuming are equal to the average value.".format(X4, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per5)+'%'), end='')
print(" ({}/{}) of the tests, the execution sequence are more than the average value.".format(X5, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per6)+'%'), end='')
print(" ({}/{}) of the tests, the execution sequence are less than the average value.".format(X6, totalVarient))
print(" > In ", end='')
print(fmt(color.RED, str(per7)+'%'), end='')
print(" ({}/{}) of the tests, the execution sequence are equal to the average value.".format(X7, totalVarient))
# make conclusion
print("\nFinal Conslusion:")
if per1 < 1.0 :
print(fmt(color.YELLOW, "1. The code implementation of test EVM is relatively complete, can be used for Ethereum."))
else :
print(fmt(color.YELLOW, "1. The code implementation of test EVM is incomplete, cannot be used for Ethereum."))
if per3 <= 50.0 and per2 <= 50:
print(fmt(color.YELLOW, "2. The calculation of gas is accurate, "), end='')
else :
print(fmt(color.YELLOW, "2. The deviation of gas calculation is large, "), end='')
if per3 > 0.0 :
print(fmt(color.YELLOW, "there exists dynamic optimization during the calculation process, "), end='')
else :
print(fmt(color.YELLOW, "there is no dynamic optimization during the calculation process, "), end='')
if per3 > per2 :
print(fmt(color.YELLOW, "and the optimization effect is good."))
else :
print(fmt(color.YELLOW, "which need further improvement."))
if per6 <= 50.0 and per5 <= 50:
print(fmt(color.YELLOW, "3. The execution path planning is correct, "), end='')
else :
print(fmt(color.YELLOW, "3. The deviation of executing sequence is large, "), end='')
if per6 > 0.0 :
print(fmt(color.YELLOW, "there exists dynamic optimization during the executing procedure, "), end='')
else :
print(fmt(color.YELLOW, "there is no dynamic optimization during the executing procedure, "), end='')
if per6 > per5 :
print(fmt(color.YELLOW, "and the optimization effect is good."))
else :
print(fmt(color.YELLOW, "which need further improvement."))
if __name__ == '__main__':
show_help()
start_time = time.time()
main()
end_time = time.time()
send_report(start_time, end_time)