-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
358 lines (318 loc) · 14.5 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>SolidityCode.Reviews</title>
<link rel="stylesheet" href="./static/style.css">
</head>
<body>
<div style="padding-bottom: 25px;">
<table style="width:75%">
<tr>
<td>
<a href="./index.html">
<img src="./static/eth-logo.png" style="width: 100px;" />
</a>
</td>
<td>
<a href="https://www.trailofbits.com/products" target="_blank">
<img src="./static/slither-logo.png" style="width: 140px;" />
</a>
</td>
<td style="text-align: left;">
<span class="page-heading">
Solidity Analyzer
</span>
<br>
<span class="section-heading2">
with the Slither/Crytic framework
</span>
</td>
<td style="text-align:right">
<span style="font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif; font-size:16pt">
<a href="./categories.html" target="_blank">Solidity Vulnerabilities Covered</a>
<br>
<img src="./static/github-logo.png" width="24px">
<a href="https://github.com/trailofbits/eth-security-toolbox/" target="_blank">
Eth Security Toolbox</a>
<br>
<a href="#divCode"> Analyze Code Directly</a>
<br>
<a href="#divUri"> Analyze With Contract Address</a>
</span>
</td>
</tr>
</table>
</div>
<div id="divBody">
<table style="width: 75%; border:black; border-width:0px; border-style:solid; border-spacing: 0; ">
<tr>
<td style="width: 33%; height: 1000px; border:gray; border-width:1px; border-style:solid; vertical-align:top; ">
<div>
<table>
<tr>
<td>
<span class="section-heading">
Upload Solidity file (.sol) :
</span>
<br><br>
<div style="border-style:solid; border-color:gray; border-width:1px; height:125px; width: 375px; padding: 3px;">
<form id="uploadForm" enctype="multipart/form-data" method="post">
<input type="file" name="selectedFile" id="selectedFile" />
<br><br>
<table style="width:80%">
<tr>
<td style="text-align: center;">
<input type="submit" accept=".sol" value="Upload File" class="form-submit-button" />
</td>
</tr>
</table>
</form>
</div>
<br>
</td>
</tr>
<tr>
<td>
<div>
<div>
<label id="lblCompiler" style="font-size: 16pt; font-weight: bold; "></label>
<!-- <label id="lblFile" style="font-size: 14pt; font-weight: bold; "></label> -->
</div>
<label id="lblMsg"></label>
<span id="referencesHeader" style="font-size: 16pt; font-weight: bold; text-decoration: underline;"></span>
<span id="referenceList" style="font-size: 14pt; font-weight: normal;"></span><br>
</div>
</td>
</tr>
</table>
</form>
</div>
</td>
</tr>
<tr>
<td style="width: 33%; border:gray; border-width:1px; border-style:solid;vertical-align:top">
<div class="disabled-section" id="divCode">
<table>
<tr>
<td>
<span class="section-heading">
Solidity Code Direct :
</span>
<br><br>
<textarea placeholder="Paste solidity code here.. "></textarea>
</td>
</tr>
<tr>
<td style="align-content: center; text-align:center">
<form>
<button class="form-submit-button">Submit Code</button>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td style="width: 33%; border:gray; border-width:1px; border-style:solid; vertical-align:top">
<div class="disabled-section" id="divUri">
<table>
<tr>
<td>
<span class="section-heading">
Ethereum Contract URI :
</span>
<br><br>
<textarea class="uriTextArea" placeholder="Paste link to Address/Txn Hash/Block/Token/Ens"></textarea>
</td>
</tr>
<tr>
<td style="align-content: center; text-align:center">
<form>
<br>
<button class="form-submit-button">Submit URI</button>
</form>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
<script>
const uploadForm = document.getElementById('uploadForm');
const selectedFile = document.getElementById("selectedFile");
const lblCompiler = document.getElementById("lblCompiler");
// const lblFile = document.getElementById("lblFile")
const referencesHeader = document.getElementById("referencesHeader")
const referenceList = document.getElementById("referenceList");
var analysisResultsJson = "";
var jsonAnalysisObj;
const diagnosticsOn = true;
const initialize = async () => {
try {
selectedFile.value = '';
uploadForm.addEventListener('submit', uploadFile);
var httpRequest = new XMLHttpRequest();
function uploadFile(event) {
event.preventDefault();
var data = new FormData(document.getElementById("uploadForm"));
httpRequest.onreadystatechange = checkResponse;
httpRequest.open("POST", "https://web3api.tools/uploadfile");
httpRequest.send(data);
}
function checkResponse() {
if (httpRequest.readyState == 4) {
//clear form
lblCompiler.innerHTML = "";
lblMsg.innerHTML = "";
referenceList.innerHTML ="";
referencesHeader.innerHTML = "";
var rawText = httpRequest.response.toString();
if (diagnosticsOn){
console.log("raw text : /n"+ rawText)
}
var showErrorMsg = ""
if (rawText.toString().includes("USE_VERSION: Invalid version '^0.8.10;")){
showErrorMsg = "Coompilation Error : version 0.8.10 not yet available. Please lower to version 0.7.0 or lower." ;
lblCompiler.innerHTML = showErrorMsg;
return;
//other errors
//No visibility specified. Did you intend to add \"public\"?
}
if (rawText.toString().includes("No visibility specified. Did you intend to add")){
showErrorMsg = "Compilation Error : No visibility specified. Did you intend to add \"public\"" ;
lblCompiler.innerHTML = showErrorMsg;
return;
}
var rootJson = JSON.parse(rawText);
var fullJSONString = JSON.stringify(rawText);
var fullJSONObj =JSON.parse(fullJSONString);
const res = JSON.parse(rawText);
var jsonAnalysisString = res.analysis_results_json.toString();
var jsonAnalysisStartPos = jsonAnalysisString.indexOf('{"');
var jsonAnalysisStringFormatted = jsonAnalysisString.substr(jsonAnalysisStartPos);
const jsonAnalysis = JSON.parse(jsonAnalysisStringFormatted);
const regexp = new RegExp('Reference: ','g');
let match;
var references = "";
while ((match = regexp.exec(rawText)) !== null) {
let textAfterMatch = rawText.substr(regexp.lastIndex);
let linkStart = textAfterMatch.indexOf("http");
let textAfterLinkMatch = textAfterMatch.substr(linkStart);
let linkEnd = textAfterLinkMatch.indexOf("\\u");
let linkText = textAfterLinkMatch.substr(linkStart, linkEnd);
references += "<br><a href='" + linkText + "' target='_blank'>" + linkText + "</a>";
}
var compilerTextStart = rawText.indexOf("Switched global version to ");
var restOfString = rawText.substr(compilerTextStart);
var nextLineBreakAfterCompilerText = restOfString.indexOf("\\n");
var compilerVersionText = restOfString.substr(0, nextLineBreakAfterCompilerText);
var formattedCompilerVersionText = compilerVersionText.replace("Switched global version to ", "Solidity Compiler Used For Analysis : ");
if (formattedCompilerVersionText)
{
var compileTextSplit = formattedCompilerVersionText.split(":");
compileTextSplit[1]
var finalCompilerHTML = compileTextSplit[0] + " : <span style='color:royalblue; font-size:18pt'>" + compileTextSplit[1] + "</span>";
lblCompiler.innerHTML = finalCompilerHTML;
}
//remove output of sol-select - needs updated in sh
fullJSONString = fullJSONString.replace(compilerVersionText, "");
fullJSONObj = JSON.parse(fullJSONString);
const data = jsonAnalysis;
var success = data.success;
var error = data.error;
var results = data.results;
var detectors = results.detectors;
let detectorArray;
if (detectors) {
detectorArray = detectors;
}
var solidityCompiler = "";
var filename = "";
var issueDescriptions = "";
var mainString = "";
var detectorType = "";
var detectorStringId = "";
var criticality = "";
var ctr = 1;
if (detectorArray)
{
for (const detector of detectorArray) {
var detectorElements = detector.elements;
for (const detectorElement of detectorElements) {
detectorStringId = detector.check;
detectorType = detectorElement.type + "/" + detectorElement.name;
criticality = detector.impact;
if (detectorElement.type == "pragma"){
solidityCompiler = detectorElement.name;
filename = detectorElement.source_mapping.filename_short;
}
}
//format code location
var detectorDescriptionTxt = detector.description;
var fileOpenParenIndex = detectorDescriptionTxt.toString().indexOf("(files/");
var fileClosedParenIndex = "";
var fileAndLineNumberText = "";
var detectorDescriptionFormatted = "";
// detector/category type
if (fileOpenParenIndex > 0) {
fileClosedParenIndex = detectorDescriptionTxt.toString().substr(fileOpenParenIndex).indexOf(")");
fileAndLineNumberText = detectorDescriptionTxt.substr(fileOpenParenIndex, fileClosedParenIndex + 1);
detectorDescriptionFormatted = detectorDescriptionTxt.replace(fileAndLineNumberText,"");
fileAndLineNumberText = fileAndLineNumberText.replace("files/","").replace("#"," line:");
fileAndLineNumberText = fileAndLineNumberText.replace("(","").replace(")","");
}
else {
detectorDescriptionFormatted = detectorDescriptionTxt;
}
issueDescriptions += "<div class='monospace'>";
issueDescriptions += "(" + ctr.toString() + ") " + "Description : ";
issueDescriptions += "<span style='font-weight:bold'>" + detectorDescriptionFormatted + "</span>"
issueDescriptions += "<br>";
issueDescriptions += " Type/Category : ";
issueDescriptions += "<span style='font-weight:normal'>" + detectorStringId + " (" + detectorType + ")" + "</span>";
issueDescriptions += "<br>";
issueDescriptions += " Criticality : ";
if (criticality == "High") {
issueDescriptions += "<span style='font-weight:bold; color:red'>" + criticality + "</span>";
} else {
issueDescriptions += "<span style='font-weight:normal'>" + criticality + "</span>";
}
if (fileAndLineNumberText) {
issueDescriptions += "<br>";
issueDescriptions += " File/Line # : ";
issueDescriptions += "<span style='font-size:12pt; color:navy'>" + fileAndLineNumberText + "</span>";
}
issueDescriptions += "</div>";
issueDescriptions += "<br>";
ctr += 1;
}
}
let detectorsArrayLength;
if (detectors) {
detectorsArrayLength = detectors.length;
}
lblMsg.innerHTML += "<br> <span style='text-decoration:underline; font-size:16pt;'>Issues Found</span> : ";
lblMsg.innerHTML += "<span style='font-weight:bold; font-size:18pt; color:red'> " + detectorsArrayLength + "</span>";
lblMsg.innerHTML += "<br>";
lblMsg.innerHTML += "<br>" + issueDescriptions;
if (referenceList) {
referencesHeader.innerText = "References";
referenceList.innerHTML = references;
}
}
}
}
catch(error) {
}
}
window.addEventListener('DOMContentLoaded', initialize);
var lblMsg = document.getElementById("lblMsg");
</script>
</body>
</html>