-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreate-fuzzes.js
155 lines (128 loc) · 5.37 KB
/
create-fuzzes.js
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
const deploy = require('./deploy-contract')
const Web3 = require('web3')
const glob = require("glob")
const fs = require('fs')
const createCsvWriter = require('csv-writer').createObjectCsvWriter;
const get_abi = require('./get-abi');
let web3 = new Web3(Web3.givenProvider || "ws://localhost:33333");
let numberOfTXsForEachContractSet = 200// put 10 here
let safety = null;
let file_name = null;
let source_code = null;
let tx_array = []
let current_generated_txs = 25;
let lock = false;
let fuzzCreationTime = 0;
let files_to_use = [
{
file_name: 'vulnerables.sol',
mode: 'vul',
value_for_sending_to_victim: 100000000000000000000
},
{
file_name: 'safes.sol',
mode: 'safe',
value_for_sending_to_victim: 10000000000000000000
}
]
/*
let files_to_use = [
{
file_name: 'vulnerables.sol',
mode: 'vul',
value_for_sending_to_victim: 100000000000000000000
},
]
*/
vulnerable_set_attacker_abi = get_abi('vulnerables.sol');
safe_set_attacker_abi = get_abi('safes.sol');
let makeCreateTXFuzz = () => {
files_to_use.forEach((file_object, index) => {
safety = file_object['mode'];
file_name = file_object['file_name']
if (safety == "vul") {
deploy('vulnerables.sol', 'Vulnerable', file_object['value_for_sending_to_victim'])
.then(async (victim_addr) => {
return {
victim_addr: victim_addr,
attacker_addr: await deploy('vulnerables.sol', 'GiveMeEverything')
};
})
.then(addr_object => {
let tx_object = {
"files": 'vulnerables.sol',
"attacker": {
"address": addr_object["attacker_addr"],
"abi": vulnerable_set_attacker_abi
},
"victim": {
"contract_name": "Vulnerable",
"address": addr_object["victim_addr"],
},
"label": "vul"
}
let thisInterval = setInterval(() => {
if (lock == false) {
lock = true;
console.log("Locked the critical section.")
clearInterval(thisInterval);
current_generated_txs++;
the_json_txs_object = JSON.parse(fs.readFileSync('params/tx_fuzz.json'))
the_json_txs_object[current_generated_txs.toString()] = tx_object;
fs.writeFileSync('params/tx_fuzz.json', JSON.stringify(the_json_txs_object, null, 4))
console.log("Releasing the lock......")
lock = false;
} else {
console.log("critical section was locked, waiting...")
return;
}
}, 1000)
});
} else if (safety == "safe") {
deploy('safes.sol', 'Safe', file_object['value_for_sending_to_victim'])
.then(async (victim_addr) => {
return {
victim_addr: victim_addr,
attacker_addr: await deploy('safes.sol', 'GiveMeEverything')
};
})
.then(addr_object => {
let tx_object = {
"files": 'safes.sol',
"attacker": {
"address": addr_object["attacker_addr"],
"abi": safe_set_attacker_abi
},
"victim": {
"contract_name": "Safe",
"address": addr_object["victim_addr"],
},
"label": "safe"
}
let thisInterval = setInterval(() => {
if (lock == false) {
lock = true;
console.log("Locked the critical section.")
clearInterval(thisInterval);
current_generated_txs++;
the_json_txs_object = JSON.parse(fs.readFileSync('params/tx_fuzz.json'))
the_json_txs_object[current_generated_txs.toString()] = tx_object;
fs.writeFileSync('params/tx_fuzz.json', JSON.stringify(the_json_txs_object, null, 4))
console.log("Releasing the lock......")
lock = false;
} else {
console.log("critical section was locked, waiting...")
return;
}
}, 1000)
});
}
})
}
for (var i = 1; i <= numberOfTXsForEachContractSet; i++) {
setTimeout(() => {
console.log(`*********** Creating new transaction pair ************`)
makeCreateTXFuzz()
}, fuzzCreationTime)
fuzzCreationTime = fuzzCreationTime + 15000
}