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 #142 from luongnt95/revert_opcode
Browse files Browse the repository at this point in the history
Implement REVERT opcode
  • Loading branch information
luongnt95 authored Jul 14, 2017
2 parents f29ad98 + 8b5449d commit bf59f4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -125,7 +126,7 @@
"Gblockhash": 20
}

Wzero = ("STOP", "RETURN")
Wzero = ("STOP", "RETURN", "REVERT")

Wbase = ("ADDRESS", "ORIGIN", "CALLER", "CALLVALUE", "CALLDATASIZE",
"CODESIZE", "GASPRICE", "COINBASE", "TIMESTAMP", "NUMBER",
Expand Down
9 changes: 5 additions & 4 deletions symExec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf59f4f

Please sign in to comment.