-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathcryticparser.py
executable file
·449 lines (375 loc) · 13.7 KB
/
cryticparser.py
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
"""
Module handling the cli arguments
Call cryticparser.init(parser: ArgumentParser) to setup all the crytic-compile arguments in the argument parser
"""
from argparse import ArgumentParser
from crytic_compile.crytic_compile import get_platforms
from crytic_compile.cryticparser import DEFAULTS_FLAG_IN_CONFIG
def init(parser: ArgumentParser) -> None:
"""Add crytic-compile arguments to the parser
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_solc = parser.add_argument_group("Compile options")
platforms = get_platforms()
group_solc.add_argument(
"--compile-force-framework",
help="Force the compile to a given framework "
f"({','.join([x.NAME.lower() for x in platforms])})",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["compile_force_framework"],
)
group_solc.add_argument(
"--compile-remove-metadata",
help="Remove the metadata from the bytecodes",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["compile_remove_metadata"],
)
group_solc.add_argument(
"--compile-custom-build",
help="Replace platform specific build command",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["compile_custom_build"],
)
group_solc.add_argument(
"--ignore-compile",
help="Do not run compile of any platform",
action="store_true",
dest="ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["ignore_compile"],
)
_init_solc(parser)
_init_truffle(parser)
_init_embark(parser)
_init_dapp(parser)
_init_etherlime(parser)
_init_etherscan(parser)
_init_waffle(parser)
_init_npx(parser)
_init_buidler(parser)
_init_hardhat(parser)
def _init_solc(parser: ArgumentParser) -> None:
"""Init solc arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_solc = parser.add_argument_group("Solc options")
group_solc.add_argument(
"--solc", help="solc path", action="store", default=DEFAULTS_FLAG_IN_CONFIG["solc"]
)
group_solc.add_argument(
"--solc-remaps",
help="Add remapping",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["solc_remaps"],
)
group_solc.add_argument(
"--solc-args",
help="Add custom solc arguments. Example: --solc-args"
' "--allow-path /tmp --evm-version byzantium".',
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["solc_args"],
)
group_solc.add_argument(
"--solc-disable-warnings",
help="Disable solc warnings",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["solc_disable_warnings"],
)
group_solc.add_argument(
"--solc-working-dir",
help="Change the default working directory",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["solc_working_dir"],
)
group_solc.add_argument(
"--solc-solcs-select",
help="Specify different solc version to try (env config). Depends on solc-select ",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["solc_solcs_select"],
)
group_solc.add_argument(
"--solc-solcs-bin",
help="Specify different solc version to try (path config)."
" Example: --solc-solcs-bin solc-0.4.24,solc-0.5.3",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["solc_solcs_bin"],
)
group_solc.add_argument(
"--solc-standard-json",
help="Compile all specified targets in a single compilation using solc standard json",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["solc_standard_json"],
)
group_solc.add_argument(
"--solc-force-legacy-json",
help="Force the solc compiler to use the legacy json ast format over the compact json ast format",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["solc_force_legacy_json"],
)
def _init_waffle(parser: ArgumentParser) -> None:
"""Init waffle arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_waffle = parser.add_argument_group("Waffle options")
group_waffle.add_argument(
"--waffle-ignore-compile",
help="Do not run waffle compile",
action="store_true",
dest="waffle_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["waffle_ignore_compile"],
)
group_waffle.add_argument(
"--waffle-config-file",
help="Provide a waffle config file",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["waffle_config_file"],
)
def _init_truffle(parser: ArgumentParser) -> None:
"""Init truffle arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_truffle = parser.add_argument_group("Truffle options")
group_truffle.add_argument(
"--truffle-ignore-compile",
help="Do not run truffle compile",
action="store_true",
dest="truffle_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["truffle_ignore_compile"],
)
group_truffle.add_argument(
"--truffle-build-directory",
help="Use an alternative truffle build directory",
action="store",
dest="truffle_build_directory",
default=DEFAULTS_FLAG_IN_CONFIG["truffle_build_directory"],
)
group_truffle.add_argument(
"--truffle-version",
help="Use a local Truffle version (with npx)",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["truffle_version"],
)
group_truffle.add_argument(
"--truffle-overwrite-config",
help="Use a simplified version of truffle-config.js for compilation",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["truffle_overwrite_config"],
)
group_truffle.add_argument(
"--truffle-overwrite-version",
help="Overwrite solc version in truffle-config.js (only if --truffle-overwrite-config)",
action="store",
default=DEFAULTS_FLAG_IN_CONFIG["truffle_overwrite_version"],
)
def _init_embark(parser: ArgumentParser) -> None:
"""Init embark arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_embark = parser.add_argument_group("Embark options")
group_embark.add_argument(
"--embark-ignore-compile",
help="Do not run embark build",
action="store_true",
dest="embark_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["embark_ignore_compile"],
)
group_embark.add_argument(
"--embark-overwrite-config",
help="Install @trailofbits/embark-contract-export and add it to embark.json",
action="store_true",
default=DEFAULTS_FLAG_IN_CONFIG["embark_overwrite_config"],
)
def _init_brownie(parser: ArgumentParser) -> None:
"""Init brownie arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_embark = parser.add_argument_group("Brownie options")
group_embark.add_argument(
"--brownie-ignore-compile",
help="Do not run brownie compile",
action="store_true",
dest="brownie_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["brownie_ignore_compile"],
)
def _init_dapp(parser: ArgumentParser) -> None:
"""Init dapp arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_dapp = parser.add_argument_group("Dapp options")
group_dapp.add_argument(
"--dapp-ignore-compile",
help="Do not run dapp build",
action="store_true",
dest="dapp_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["dapp_ignore_compile"],
)
def _init_etherlime(parser: ArgumentParser) -> None:
"""Init etherlime arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_etherlime = parser.add_argument_group("Etherlime options")
group_etherlime.add_argument(
"--etherlime-ignore-compile",
help="Do not run etherlime compile",
action="store_true",
dest="etherlime_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["etherlime_ignore_compile"],
)
group_etherlime.add_argument(
"--etherlime-compile-arguments",
help="Add arbitrary arguments to etherlime compile "
"(note: [dir] is the the directory provided to crytic-compile)",
action="store_true",
dest="etherlime_compile_arguments",
default=DEFAULTS_FLAG_IN_CONFIG["etherlime_compile_arguments"],
)
def _init_etherscan(parser: ArgumentParser) -> None:
"""Init etherscan arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_etherscan = parser.add_argument_group("Etherscan options")
group_etherscan.add_argument(
"--etherscan-only-source-code",
help="Only compile if the source code is available.",
action="store_true",
dest="etherscan_only_source_code",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_only_source_code"],
)
group_etherscan.add_argument(
"--etherscan-only-bytecode",
help="Only looks for bytecode.",
action="store_true",
dest="etherscan_only_bytecode",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_only_bytecode"],
)
group_etherscan.add_argument(
"--etherscan-target-only",
help="Etherscan only include target contract.",
action="store_true",
dest="etherscan_target_only",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_target_only"],
)
group_etherscan.add_argument(
"--etherscan-apikey",
help="Etherscan API key.",
action="store",
dest="etherscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--arbiscan-apikey",
help="Etherscan API key.",
action="store",
dest="arbiscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--polygonscan-apikey",
help="Etherscan API key.",
action="store",
dest="polygonscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--avax-apikey",
help="Etherscan API key.",
action="store",
dest="avax_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--ftmscan-apikey",
help="Etherscan API key.",
action="store",
dest="ftmscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--bscan-apikey",
help="Etherscan API key.",
action="store",
dest="bscan_api_key",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"],
)
group_etherscan.add_argument(
"--etherscan-export-directory",
help="Directory in which to save the analyzed contracts.",
action="store",
dest="etherscan_export_dir",
default=DEFAULTS_FLAG_IN_CONFIG["etherscan_export_directory"],
)
def _init_npx(parser: ArgumentParser) -> None:
"""Init npx arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_npx = parser.add_argument_group("NPX options")
group_npx.add_argument(
"--npx-disable",
help="Do not use npx",
action="store_true",
dest="npx_disable",
default=DEFAULTS_FLAG_IN_CONFIG["npx_disable"],
)
def _init_buidler(parser: ArgumentParser) -> None:
"""Init buidler arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_buidler = parser.add_argument_group("Buidler options")
group_buidler.add_argument(
"--buidler-ignore-compile",
help="Do not run buidler compile",
action="store_true",
dest="buidler_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["buidler_ignore_compile"],
)
group_buidler.add_argument(
"--buidler-cache-directory",
help="Use an alternative buidler cache directory (default ./cache)",
action="store",
dest="buidler_cache_directory",
default=DEFAULTS_FLAG_IN_CONFIG["buidler_cache_directory"],
)
group_buidler.add_argument(
"--buidler-skip-directory-name-fix",
help="Disable directory name fix (see https://github.com/crytic/crytic-compile/issues/116)",
action="store_true",
dest="buidler_skip_directory_name_fix",
default=DEFAULTS_FLAG_IN_CONFIG["buidler_skip_directory_name_fix"],
)
def _init_hardhat(parser: ArgumentParser) -> None:
"""Init hardhat arguments
Args:
parser (ArgumentParser): argparser where the cli flags are added
"""
group_hardhat = parser.add_argument_group("hardhat options")
group_hardhat.add_argument(
"--hardhat-ignore-compile",
help="Do not run hardhat compile",
action="store_true",
dest="hardhat_ignore_compile",
default=DEFAULTS_FLAG_IN_CONFIG["hardhat_ignore_compile"],
)
group_hardhat.add_argument(
"--hardhat-cache-directory",
help="Use an alternative hardhat cache directory (default ./cache)",
action="store",
dest="hardhat_cache_directory",
default=DEFAULTS_FLAG_IN_CONFIG["hardhat_cache_directory"],
)
group_hardhat.add_argument(
"--hardhat-artifacts-directory",
help="Use an alternative hardhat artifacts directory (default ./artifacts)",
action="store",
dest="hardhat_artifacts_directory",
default=DEFAULTS_FLAG_IN_CONFIG["hardhat_artifacts_directory"],
)