diff --git a/oyente/analysis.py b/oyente/analysis.py index 64fe634c..b4b731da 100644 --- a/oyente/analysis.py +++ b/oyente/analysis.py @@ -63,7 +63,10 @@ def check_reentrancy_bug(path_conditions_and_vars, stack, global_state): new_path_condition.append(var == global_state["Ia"][storage_key]) transfer_amount = stack[2] if isSymbolic(transfer_amount) and str(transfer_amount).startswith("Ia_store"): - storage_key = str(transfer_amount).split("-")[1] + try: + storage_key = str(transfer_amount).split("-")[1] + except: + storage_key = str(transfer_amount).split("Ia_store_")[1] try: if int(storage_key) in global_state["Ia"]: new_path_condition.append(global_state["Ia"][int(storage_key)] != 0) diff --git a/oyente/symExec.py b/oyente/symExec.py index 445011f5..059748bc 100755 --- a/oyente/symExec.py +++ b/oyente/symExec.py @@ -755,7 +755,7 @@ def sym_exec_ins(params): elif instr_parts[0] == "ASSERTFAIL": if source_map: source_code = source_map.find_source_code(global_state["pc"]) - if func_call == -1 and "assert" in source_code: + if "assert" in source_code: global_problematic_pcs["assertion_failure"].append(Assertion(global_state["pc"], models[-1])) elif func_call != -1: global_problematic_pcs["assertion_failure"].append(Assertion(func_call, models[-1])) @@ -2051,16 +2051,16 @@ def detect_money_concurrency(): for idx, pcs in enumerate(flows): pcs = validator.remove_false_positives(pcs) if global_params.WEB: - s += "flow " + str(idx + 1) + ":
" + s += "Flow " + str(idx + 1) + ":
" else: - s += "\nflow " + str(idx + 1) + ":" + s += "\nFlow " + str(idx + 1) + ":" for pc in pcs: source_code = source_map.find_source_code(pc).split("\n", 1)[0] if not source_code: continue location = source_map.get_location(pc) if global_params.WEB: - s += "%s:%s:%s: Money concurrency bug:
" % (source_map.cname.split(":", 1)[1], location['begin']['line'] + 1, location['begin']['column'] + 1) + s += "%s:%s:%s:
" % (source_map.cname.split(":", 1)[1], location['begin']['line'] + 1, location['begin']['column'] + 1) s += "%s
" % source_code s += "^
" else: @@ -2069,6 +2069,7 @@ def detect_money_concurrency(): s += "^" if s: any_bug = True + s = "Money concurrency bug:
" + "
" + s + "
" results["money_concurrency"] = s s = "\t Money concurrency bug: True" + s if s else "\t Money concurrency bug: False" log.info(s) diff --git a/web/app/assets/javascripts/src/app/oyente-analyzer.js b/web/app/assets/javascripts/src/app/oyente-analyzer.js index 3b159b28..64f57386 100644 --- a/web/app/assets/javascripts/src/app/oyente-analyzer.js +++ b/web/app/assets/javascripts/src/app/oyente-analyzer.js @@ -73,7 +73,7 @@ function Analyzer () { var results = yo`
${Object.keys(contracts).map(function(filename) { return yo`
-
${filename}
+
${filename}

${contracts[filename].map(function (contract) { if (contract.evm_code_coverage === "0/0") { diff --git a/web/app/controllers/home_controller.rb b/web/app/controllers/home_controller.rb index 9528a330..041caea5 100644 --- a/web/app/controllers/home_controller.rb +++ b/web/app/controllers/home_controller.rb @@ -4,7 +4,7 @@ def index def analyze @results = {} - @results[:filename] = oyente_params[:current_file] + @results[:current_file] = oyente_params[:current_file] unless check_params @results[:error] = "Invalid input" else @@ -36,10 +36,11 @@ def analyze end end end - UserMailer.analyzer_result_notification(file.path, @results, oyente_params[:email]).deliver_later + UserMailer.analyzer_result_notification(dir_path, @results, oyente_params[:email]).deliver_later unless oyente_params[:email].nil? rescue - file.close @results[:error] = "Error" + ensure + file.close end end end diff --git a/web/app/helpers/application_helper.rb b/web/app/helpers/application_helper.rb index 85e5282a..a15c42ab 100644 --- a/web/app/helpers/application_helper.rb +++ b/web/app/helpers/application_helper.rb @@ -1,9 +1,9 @@ module ApplicationHelper def bug_exists? msg - if msg.empty? - return "False".html_safe - else + if msg return "True".html_safe + else + return "False".html_safe end end end diff --git a/web/app/mailers/user_mailer.rb b/web/app/mailers/user_mailer.rb index b44736bb..b2241d40 100644 --- a/web/app/mailers/user_mailer.rb +++ b/web/app/mailers/user_mailer.rb @@ -1,10 +1,13 @@ class UserMailer < ApplicationMailer helper ApplicationHelper - def analyzer_result_notification filepath, results, email + def analyzer_result_notification dir_path, results, email @results = results - attachments[@results[:filename]] = File.read(filepath) + @results[:contracts].each do |filename, result| + filepath = "#{dir_path}/#{filename}" + attachments[filename] = File.read(filepath) + end mail to: email, subject: "Analysis results by Oyente" end diff --git a/web/app/views/user_mailer/analyzer_result_notification.html.erb b/web/app/views/user_mailer/analyzer_result_notification.html.erb index 591297ff..32c3d6e5 100644 --- a/web/app/views/user_mailer/analyzer_result_notification.html.erb +++ b/web/app/views/user_mailer/analyzer_result_notification.html.erb @@ -1,35 +1,37 @@

Oyente analysis result

-
<%= @results[:filename] %>
-
- <% if @results.key?(:error) %> -
<%= @results[:error] %>
- <% else %> - <% @results[:contracts].each do |contract| %> -
-
======= contract <%= contract[:cname] %> =======
- <% if contract[:evm_code_coverage] == "0/0" %> -
EVM code coverage: <%= contract[:evm_code_coverage] %>
- <% else %> -
EVM code coverage: <%= contract[:evm_code_coverage] %>%
- <% end %> -
Callstack bug: <%= bug_exists?(contract[:callstack]) %>
-
Money concurrency bug: <%= bug_exists?(contract[:concurrency]) %>
-
Time dependency bug: <%= bug_exists?(contract[:time_dependency]) %>
-
Reentrancy bug: <%= bug_exists?(contract[:reentrancy]) %>
-
Assertion failure: <%= bug_exists?(contract[:assertion_failure]) %>
- <% if contract[:callstack].present? || contract[:concurrency].present? \ - || contract[:time_dependency].present? || contract[:reentrancy].present? || contract[:assertion_failure].present? %> + <% @results[:contracts].each do |filename, results| %> +
<%= filename %>
+
+ <% results.each do |contract| %> + <% if contract.key?(:error) %> +
<%= contract[:error] %>
+ <% else %> +
+
======= contract <%= contract[:cname] %> =======
+ <% if contract[:evm_code_coverage] == "0/0" %> +
EVM code coverage: <%= contract[:evm_code_coverage] %>
+ <% else %> +
EVM code coverage: <%= contract[:evm_code_coverage] %>%
+ <% end %> +
Callstack bug: <%= bug_exists?(contract[:callstack]) %>
+
Money concurrency bug: <%= bug_exists?(contract[:money_concurrency]) %>
+
Time dependency bug: <%= bug_exists?(contract[:time_dependency]) %>
+
Reentrancy bug: <%= bug_exists?(contract[:reentrancy]) %>
+
Assertion failure: <%= bug_exists?(contract[:assertion_failure]) %>
+ <% if contract[:callstack].present? || contract[:money_concurrency].present? \ + || contract[:time_dependency].present? || contract[:reentrancy].present? || contract[:assertion_failure].present? %> +
+ <% end %> +
<%= contract[:callstack].html_safe if contract[:callstack] %>
+
<%= contract[:money_concurrency].html_safe if contract[:money_concurrency] %>
+
<%= contract[:time_dependency].html_safe if contract[:time_dependency] %>
+
<%= contract[:reentrancy].html_safe if contract[:reentrancy] %>
+
<%= contract[:assertion_failure].html_safe if contract[:assertion_failure] %>
+
======= Analysis Completed =======

- <% end %> -
<%= contract[:callstack].html_safe %>
-
<%= contract[:concurrency].html_safe %>
-
<%= contract[:time_dependency].html_safe %>
-
<%= contract[:reentrancy].html_safe %>
-
<%= contract[:assertion_failure].html_safe %>
-
======= Analysis Completed =======
-
-
+
+ <% end %> <% end %> <% end %>