Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #257 from luongnt95/develop
Browse files Browse the repository at this point in the history
Add support for standard json output
  • Loading branch information
luongnt95 authored Jan 5, 2018
2 parents 6a74ab8 + d3383a8 commit 920fe9d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
22 changes: 19 additions & 3 deletions oyente/input_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class InputHelper:
BYTECODE = 0
SOLIDITY = 1
STANDARD_JSON = 2
STANDARD_JSON_OUTPUT = 3

def __init__(self, input_type, **kwargs):
self.input_type = input_type
Expand All @@ -37,6 +38,13 @@ def __init__(self, input_type, **kwargs):
'allow_paths': None,
'compiled_contracts': []
}
elif input_type == InputHelper.STANDARD_JSON_OUTPUT:
attr_defaults = {
'source': None,
'evm': False,
'root_path': "",
'compiled_contracts': [],
}

for (attr, default) in six.iteritems(attr_defaults):
val = kwargs.get(attr, default)
Expand Down Expand Up @@ -85,8 +93,11 @@ def _get_compiled_contracts(self):
if not self.compiled_contracts:
if self.input_type == InputHelper.SOLIDITY:
self.compiled_contracts = self._compile_solidity()
else:
elif self.input_type == InputHelper.STANDARD_JSON:
self.compiled_contracts = self._compile_standard_json()
elif self.input_type == InputHelper.STANDARD_JSON_OUTPUT:
self.compiled_contracts = self._compile_standard_json_output(self.source)

return self.compiled_contracts

def _compile_solidity(self):
Expand All @@ -110,7 +121,12 @@ def _compile_standard_json(self):
out = p2.communicate()[0]
with open('standard_json_output', 'w') as of:
of.write(out)
# should handle the case without allow-paths option

return self._compile_standard_json_output('standard_json_output')

def _compile_standard_json_output(self, json_output_file):
with open(json_output_file, 'r') as f:
out = f.read()
j = json.loads(out)
contracts = []
for source in j['sources']:
Expand Down Expand Up @@ -186,7 +202,7 @@ def _write_disasm_file(self, target):
of.write(disasm_out)

def _rm_tmp_files_of_multiple_contracts(self, contracts):
if self.input_type == InputHelper.STANDARD_JSON:
if self.input_type in ['standard_json', 'standard_json_output']:
self._rm_file('standard_json_output')
for contract, _ in contracts:
self._rm_tmp_files(contract)
Expand Down
35 changes: 20 additions & 15 deletions oyente/oyente.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def analyze_solidity(input_type='solidity'):
helper = InputHelper(InputHelper.SOLIDITY, source=args.source)
elif input_type == 'standard_json':
helper = InputHelper(InputHelper.STANDARD_JSON, source=args.source, allow_paths=args.allow_paths)
elif input_type == 'standard_json_output':
helper = InputHelper(InputHelper.STANDARD_JSON_OUTPUT, source=args.source)
inputs = helper.get_inputs()
results, exit_code = run_solidity_analysis(inputs)
helper.rm_tmp_files()
Expand All @@ -126,26 +128,27 @@ def main():

parser.add_argument("-t", "--timeout", help="Timeout for Z3 in ms.", action="store", type=int)
parser.add_argument("-gl", "--gaslimit", help="Limit Gas", action="store", dest="gas_limit", type=int)
parser.add_argument("-rp", "--root-path", help="Root directory path used for the online version", action="store", dest="root_path", type=str)
parser.add_argument("-rp", "--root-path", help="Root directory path used for the online version", action="store", dest="root_path", type=str)
parser.add_argument("-ll", "--looplimit", help="Limit number of loops", action="store", dest="loop_limit", type=int)
parser.add_argument("-dl", "--depthlimit", help="Limit DFS depth", action="store", dest="depth_limit", type=int)
parser.add_argument("-ap", "--allow-paths", help="Allow a given path for imports", action="store", dest="allow_paths", type=str)
parser.add_argument("-glt", "--global-timeout", help="Timeout for symbolic execution", action="store", dest="global_timeout", type=int)

parser.add_argument( "-e", "--evm", help="Do not remove the .evm file.", action="store_true")
parser.add_argument( "-w", "--web", help="Run Oyente for web service", action="store_true")
parser.add_argument( "-j", "--json", help="Redirect results to a json file.", action="store_true")
parser.add_argument( "-p", "--paths", help="Print path condition information.", action="store_true")
parser.add_argument( "-db", "--debug", help="Display debug information", action="store_true")
parser.add_argument( "-st", "--state", help="Get input state from state.json", action="store_true")
parser.add_argument( "-r", "--report", help="Create .report file.", action="store_true")
parser.add_argument( "-v", "--verbose", help="Verbose output, print everything.", action="store_true")
parser.add_argument( "-pl", "--parallel", help="Run Oyente in parallel. Note: The performance may depend on the contract", action="store_true")
parser.add_argument( "-b", "--bytecode", help="read bytecode in source instead of solidity file.", action="store_true")
parser.add_argument( "-a", "--assertion", help="Check assertion failures.", action="store_true")
parser.add_argument( "-sj", "--standard-json", help="Support Standard JSON input", action="store_true")
parser.add_argument( "-gb", "--globalblockchain", help="Integrate with the global ethereum blockchain", action="store_true")
parser.add_argument( "-gtc", "--generate-test-cases", help="Generate test cases each branch of symbolic execution tree", action="store_true")
parser.add_argument( "-e", "--evm", help="Do not remove the .evm file.", action="store_true")
parser.add_argument( "-w", "--web", help="Run Oyente for web service", action="store_true")
parser.add_argument( "-j", "--json", help="Redirect results to a json file.", action="store_true")
parser.add_argument( "-p", "--paths", help="Print path condition information.", action="store_true")
parser.add_argument( "-db", "--debug", help="Display debug information", action="store_true")
parser.add_argument( "-st", "--state", help="Get input state from state.json", action="store_true")
parser.add_argument( "-r", "--report", help="Create .report file.", action="store_true")
parser.add_argument( "-v", "--verbose", help="Verbose output, print everything.", action="store_true")
parser.add_argument( "-pl", "--parallel", help="Run Oyente in parallel. Note: The performance may depend on the contract", action="store_true")
parser.add_argument( "-b", "--bytecode", help="read bytecode in source instead of solidity file.", action="store_true")
parser.add_argument( "-a", "--assertion", help="Check assertion failures.", action="store_true")
parser.add_argument( "-sj", "--standard-json", help="Support Standard JSON input", action="store_true")
parser.add_argument( "-gb", "--globalblockchain", help="Integrate with the global ethereum blockchain", action="store_true")
parser.add_argument( "-gtc", "--generate-test-cases", help="Generate test cases each branch of symbolic execution tree", action="store_true")
parser.add_argument( "-sjo", "--standard-json-output", help="Support Standard JSON output", action="store_true")

args = parser.parse_args()

Expand Down Expand Up @@ -202,6 +205,8 @@ def main():
exit_code = analyze_bytecode()
elif args.standard_json:
exit_code = analyze_solidity(input_type='standard_json')
elif args.standard_json_output:
exit_code = analyze_solidity(input_type='standard_json_output')
else:
exit_code = analyze_solidity()

Expand Down

0 comments on commit 920fe9d

Please sign in to comment.