From 8b5449d4e886cc1bca82442b24703b01e2a237e5 Mon Sep 17 00:00:00 2001 From: luongnt95 Date: Fri, 14 Jul 2017 10:14:21 +0700 Subject: [PATCH] Implement REVERT opcode --- opcodes.py | 3 ++- symExec.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/opcodes.py b/opcodes.py index 9f7240bb..f0342a35 100644 --- a/opcodes.py +++ b/opcodes.py @@ -70,6 +70,7 @@ "CALL": [0xf1, 7, 1], "CALLCODE": [0xf2, 7, 1], "RETURN": [0xf3, 2, 0], + "REVERT": [0xfd, 2, 0], "DELEGATECALL": [0xf4, 6, 1], "BREAKPOINT": [0xf5, 0, 0], "RNGSEED": [0xf6, 1, 1], @@ -125,7 +126,7 @@ "Gblockhash": 20 } -Wzero = ("STOP", "RETURN") +Wzero = ("STOP", "RETURN", "REVERT") Wbase = ("ADDRESS", "ORIGIN", "CALLER", "CALLVALUE", "CALLDATASIZE", "CODESIZE", "GASPRICE", "COINBASE", "TIMESTAMP", "NUMBER", diff --git a/symExec.py b/symExec.py index 08b75299..b738a5bf 100755 --- a/symExec.py +++ b/symExec.py @@ -230,6 +230,7 @@ def change_format(): firstLine = file_contents[0].strip('\n') for line in file_contents: line = line.replace('SELFDESTRUCT', 'SUICIDE') + line = line.replace('Missing opcode 0xfd', 'REVERT') line = line.replace('Missing opcode', 'INVALID') line = line.replace(':', '') lineParts = line.split(' ') @@ -450,7 +451,7 @@ def collect_vertices(tokens): end_ins_dict[current_block] = last_ins_address current_block = current_ins_address is_new_block = False - elif tok_string == "STOP" or tok_string == "RETURN" or tok_string == "SUICIDE": + elif tok_string == "STOP" or tok_string == "RETURN" or tok_string == "SUICIDE" or tok_string == "REVERT": jump_type[current_block] = "terminal" end_ins_dict[current_block] = current_ins_address elif tok_string == "JUMP": @@ -1415,7 +1416,7 @@ def sym_exec_ins(start, instr, stack, mem, global_state, path_conditions_and_var with open(evm_file_name, 'r') as evm_file: evm = evm_file.read()[:-1] start = code_from * 2 - end = start + no_bytes * 2 + end = start + no_bytes * 2 code = evm[start: end] mem[mem_location] = code else: @@ -1469,7 +1470,7 @@ def sym_exec_ins(start, instr, stack, mem, global_state, path_conditions_and_var evm = data_source.getCode(address) start = code_from * 2 - end = start + no_bytes * 2 + end = start + no_bytes * 2 code = evm[start: end] mem[mem_location] = code else: @@ -1870,7 +1871,7 @@ def sym_exec_ins(start, instr, stack, mem, global_state, path_conditions_and_var path_conditions_and_vars["path_condition"].append(is_enough_fund) else: raise ValueError('STACK underflow') - elif instr_parts[0] == "RETURN": + elif instr_parts[0] == "RETURN" or instr_parts[0] == "REVERT": # TODO: Need to handle miu_i if len(stack) > 1: global_state["pc"] = global_state["pc"] + 1