Skip to content

Commit

Permalink
Add AST and source of solc dependencies to submission request
Browse files Browse the repository at this point in the history
  • Loading branch information
dmuhs committed Mar 18, 2020
1 parent 12f4336 commit 93b54f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
10 changes: 5 additions & 5 deletions mythx_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from glob import glob
from os.path import abspath, commonpath
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union, Any

import click
import htmlmin
Expand Down Expand Up @@ -332,7 +332,7 @@ def walk_solidity_files(
sys.exit(0)
LOGGER.debug("Found Solidity files to submit:\n{}".format("\n".join(files)))
for file in files:
jobs.extend(generate_solidity_payload(file, solc_version, remappings))
jobs.append(generate_solidity_payload(file, solc_version, remappings))
return jobs


Expand Down Expand Up @@ -452,7 +452,7 @@ def analyze(
group_mw = GroupDataMiddleware(group_id=group_id, group_name=group_name)
ctx["client"].handler.middlewares.append(group_mw)

jobs = []
jobs: List[Dict[str, Any]] = []
include = list(include)

if not target:
Expand Down Expand Up @@ -487,7 +487,7 @@ def analyze(
jobs.append(generate_bytecode_payload(element))
elif Path(element).is_file() and Path(element).suffix == ".sol":
LOGGER.debug(f"Trying to interpret {element} as a solidity file")
jobs.extend(
jobs.append(
generate_solidity_payload(file=element, version=solc_version, contracts=suffix, remappings=remap_import)
)
elif Path(element).is_dir():
Expand All @@ -498,7 +498,7 @@ def analyze(
else:
# recursively enumerate sol files if not a truffle project
jobs.extend(
walk_solidity_files(ctx, solc_version, base_path=element)
walk_solidity_files(ctx, solc_version, base_path=element, remappings=remap_import)
)
else:
raise click.exceptions.UsageError(
Expand Down
23 changes: 15 additions & 8 deletions mythx_cli/payload/solidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,34 @@ def generate_solidity_payload(
new_result[new_key] = value
result = new_result

payload = {
"sources": {},
"solc_version": solc_version,
}
for contract_name, contract_data in result.items():
if contracts and contract_name not in contracts:
continue

ast = contract_data["ast"]
source_path = str(Path(ast.get("attributes", {}).get("absolutePath")))
creation_bytecode = contract_data["bin"]
deployed_bytecode = contract_data["bin-runtime"]
source_map = contract_data["srcmap"]
deployed_source_map = contract_data["srcmap-runtime"]
ast = contract_data["ast"]
source_path = str(Path(ast.get("attributes", {}).get("absolutePath")))
with open(source_path) as source_f:
source = source_f.read()

yield {
# always add source and AST, even if dependency
payload["sources"][source_path] = {"source": source, "ast": ast}
if contracts and contract_name not in contracts:
continue

payload.update({
"contract_name": contract_name,
"main_source": source_path,
"source_list": [source_path],
"sources": {source_path: {"source": source, "ast": ast}},
"bytecode": patch_solc_bytecode(creation_bytecode),
"source_map": zero_srcmap_indices(source_map),
"deployed_source_map": zero_srcmap_indices(deployed_source_map),
"deployed_bytecode": patch_solc_bytecode(deployed_bytecode),
"solc_version": solc_version,
}
})

return payload

0 comments on commit 93b54f6

Please sign in to comment.