question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JUMPDEST instructions missing in CFG

See original GitHub issue

Description

  1. Not sure if it’s a bug or a feature, but the JUMPDEST at the start of jump targets isn’t shown in the CFG. See e.g. the JUMPI to offset 159, and the target node starts at offset 160.

cfg

  1. Function names used to be shown in the CFG at the start of each function, those are gone as well.

How to Reproduce

Using Mythril 0.18.11 Pypi:

$ myth -g cfg.html -ia 0x35efabf6e2d970a3bc3fa1de991ec63987c127bc

Expected behavior

Include the JUMPDEST instruction at the start of the node or the function name if it’s the start of a function.

Environment

  • Mythril version: 0.18.11 Pypi
  • Python version: 3.6.3
  • OS and Version: Mac OS High Sierra

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JoranHonigcommented, Sep 7, 2018

What about something like the following:

@instruction(auto_increment=False)
def jumpi_(self, global_state):
    ...
    new_state.mstate.pc = index
    ...

I think this will be simpler, and more easy to directly understand the meaning

1reaction
dmuhscommented, Sep 6, 2018

@JoranHonig Thanks for clarifying. After having spent just a couple of hours with the LASER core routines it’s still quite a bit of black magic to me. As for the pc index of the JUMPDEST, instead of manipulating the @instruction decorator and having to deal with all instructions, we could simply decrement the index in the JUMP and JUMPI mutator functions. In these functions there’s already logic handling JUMPDEST instructions, so it wouldn’t add any bloat to the functions and we could simply set the index, e.g. in jumpi_ like such (in instructions.py:842):

        if instr['opcode'] == "JUMPDEST":
            if (type(condi) == bool and condi) or (type(condi) == BoolRef and not is_false(condi)):
                new_state = copy(global_state)
                new_state.mstate.pc = index - 1
                new_state.mstate.depth += 1
                new_state.mstate.constraints.append(condi)

                states.append(new_state)

While that still doesn’t look too clean as the -1 isn’t self-explanatory, I think it’s more elegant than handling the case in the instruction decorator. If we were to do the latter, we’d have to get the jump destination address there again and set the pc accordingly. But then we would’ve repeated the same logic again, which would make it harder to maintain and refactor. A comment at the pc change in the above code sample would of course also help make things clearer. 😄

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why jumping into an instruction even if containing a ...
We define this as any position in the code occupied by a JUMPDEST instruction. All such positions must be on valid instruction boundaries, ......
Read more >
Mythril Documentation - Read the Docs
This module contains a representation class for EVM instructions and transitions between them. class mythril.laser.ethereum.instructions.
Read more >
Understand EVM bytecode – Part 2 - Trustlook blog
This is a special opcode which only marks an address that can be jumped to. It does not seem to play an important...
Read more >
EtherSolve: Computing an Accurate Control-Flow Graph from ...
This paper presents a novel static analysis algorithm based on the symbolic execution of the Ethereum operand stack that allows us to resolve ......
Read more >
Error in compiling/installing RealTime Kernel on Ubuntu 20.04 ...
I followed this guide https://unix.stackexchange.com/a/294116/419660. sudo gedit .config. Add a # in front of the lines ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found