From 125336ca11545426ec4633573cbfeab1f6ac3f00 Mon Sep 17 00:00:00 2001 From: Bernhard Mueller Date: Sat, 10 Mar 2018 21:54:11 +0700 Subject: [PATCH] Update invalid opcode module --- mythril/analysis/modules/assert.py | 10 ++++++---- solidity_examples/invalid_opcodes.sol | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 solidity_examples/invalid_opcodes.sol diff --git a/mythril/analysis/modules/assert.py b/mythril/analysis/modules/assert.py index cd8265e0..18d00117 100644 --- a/mythril/analysis/modules/assert.py +++ b/mythril/analysis/modules/assert.py @@ -25,7 +25,9 @@ def execute(statespace): instruction = state.get_current_instruction() - if(instruction['opcode'] == "ASSERT_VIOLATION"): + if(instruction['opcode'] == "ASSERT_FAIL"): + + logging.debug("Opcode 0xfe detected.") try: model = solver.get_model(node.constraints) @@ -33,9 +35,9 @@ def execute(statespace): address = state.get_current_instruction()['address'] - description = "Invalid opcode reached (0xfe). can be caused by a possible type error, out-of-bounds array access, or assert violation.\n\n" + description = "Invalid opcode reached (0xfe). This can be caused by a type error, out-of-bounds array access, or assert violation.\n\n" - description = "Variable values:\n\n" + description += "The following input and state variables trigger the invalid instruction:\n\n" for d in model.decls(): @@ -46,7 +48,7 @@ def execute(statespace): description += ("%s: %s\n" % (d.name(), condition)) - description += "\n\nNote that assert() should only be used to check invariants. Use require() for regular input checking." + description += "\nNote that assert() should only be used to check invariants. Use require() for regular input checking.\n" issues.append(Issue(node.contract_name, node.function_name, address, "Assertion violation", description)) diff --git a/solidity_examples/invalid_opcodes.sol b/solidity_examples/invalid_opcodes.sol new file mode 100644 index 00000000..97867524 --- /dev/null +++ b/solidity_examples/invalid_opcodes.sol @@ -0,0 +1,16 @@ +contract InvalidOpcodes { + + function assert1() { + uint256 i = 1; + assert(i == 0); + } + + function assert2() { + uint256 i = 1; + assert(i > 0); + } + + function assert3(uint input) { + assert(input != 23); + } +}