|
|
@ -6,6 +6,7 @@ from mythril.ether import util |
|
|
|
from mythril.ether.ethcontract import ETHContract |
|
|
|
from mythril.ether.ethcontract import ETHContract |
|
|
|
from mythril.analysis.security import fire_lasers |
|
|
|
from mythril.analysis.security import fire_lasers |
|
|
|
from mythril.analysis.symbolic import StateSpace |
|
|
|
from mythril.analysis.symbolic import StateSpace |
|
|
|
|
|
|
|
from mythril.analysis.report import Report |
|
|
|
from laser.ethereum import helper |
|
|
|
from laser.ethereum import helper |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,51 +38,51 @@ def analyze_truffle_project(): |
|
|
|
|
|
|
|
|
|
|
|
ethcontract= ETHContract(bytecode, name=name, address = util.get_indexed_address(0)) |
|
|
|
ethcontract= ETHContract(bytecode, name=name, address = util.get_indexed_address(0)) |
|
|
|
|
|
|
|
|
|
|
|
contracts = [ethcontract] |
|
|
|
states = StateSpace([ethcontract], max_depth = 10) |
|
|
|
|
|
|
|
issues = fire_lasers(states) |
|
|
|
|
|
|
|
|
|
|
|
states = StateSpace(contracts, max_depth = 10) |
|
|
|
if not len(issues): |
|
|
|
report = fire_lasers(states) |
|
|
|
print("Analysis result for " + name + ": No issues found.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
|
|
|
|
# augment with source code |
|
|
|
report = Report() |
|
|
|
|
|
|
|
# augment with source code |
|
|
|
|
|
|
|
|
|
|
|
disassembly = ethcontract.get_disassembly() |
|
|
|
disassembly = ethcontract.get_disassembly() |
|
|
|
source = contractdata['source'] |
|
|
|
source = contractdata['source'] |
|
|
|
|
|
|
|
|
|
|
|
deployedSourceMap = contractdata['deployedSourceMap'].split(";") |
|
|
|
deployedSourceMap = contractdata['deployedSourceMap'].split(";") |
|
|
|
|
|
|
|
|
|
|
|
mappings = [] |
|
|
|
mappings = [] |
|
|
|
i = 0 |
|
|
|
i = 0 |
|
|
|
|
|
|
|
|
|
|
|
while(i < len(deployedSourceMap)): |
|
|
|
while(i < len(deployedSourceMap)): |
|
|
|
|
|
|
|
|
|
|
|
m = re.search(r"^(\d+):*(\d+)", deployedSourceMap[i]) |
|
|
|
m = re.search(r"^(\d+):*(\d+)", deployedSourceMap[i]) |
|
|
|
|
|
|
|
|
|
|
|
if (m): |
|
|
|
if (m): |
|
|
|
offset = m.group(1) |
|
|
|
offset = m.group(1) |
|
|
|
length = m.group(2) |
|
|
|
length = m.group(2) |
|
|
|
else: |
|
|
|
else: |
|
|
|
m = re.search(r"^:(\d+)", deployedSourceMap[i]) |
|
|
|
m = re.search(r"^:(\d+)", deployedSourceMap[i]) |
|
|
|
|
|
|
|
|
|
|
|
if m: |
|
|
|
if m: |
|
|
|
length = m.group(1) |
|
|
|
length = m.group(1) |
|
|
|
|
|
|
|
|
|
|
|
mappings.append((int(offset), int(length))) |
|
|
|
mappings.append((int(offset), int(length))) |
|
|
|
|
|
|
|
|
|
|
|
i += 1 |
|
|
|
i += 1 |
|
|
|
|
|
|
|
|
|
|
|
for key, issue in report.issues.items(): |
|
|
|
for issue in issues: |
|
|
|
|
|
|
|
|
|
|
|
index = helper.get_instruction_index(disassembly.instruction_list, issue.pc) |
|
|
|
index = helper.get_instruction_index(disassembly.instruction_list, issue.pc) |
|
|
|
|
|
|
|
|
|
|
|
if index: |
|
|
|
if index: |
|
|
|
issue.code_start = mappings[index][0] |
|
|
|
issue.code_start = mappings[index][0] |
|
|
|
issue.code_length = mappings[index][1] |
|
|
|
issue.code_length = mappings[index][1] |
|
|
|
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]] |
|
|
|
issue.code = source[mappings[index][0]: mappings[index][0] + mappings[index][1]] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
report.append_issue(issue) |
|
|
|
|
|
|
|
|
|
|
|
if len(report.issues): |
|
|
|
|
|
|
|
print("Analysis result for " + name + ":\n" + report.as_text()) |
|
|
|
print("Analysis result for " + name + ":\n" + report.as_text()) |
|
|
|
else: |
|
|
|
|
|
|
|
print("Analysis result for " + name + ": No issues found.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|