Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
Last active September 25, 2019 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqueswww/a0f36ec0b10757198afa1e6154891a94 to your computer and use it in GitHub Desktop.
Save jacqueswww/a0f36ec0b10757198afa1e6154891a94 to your computer and use it in GitHub Desktop.
Pretty Damn awful, PyEVM Virtual Machine debugger. Using a custom opdcode set in Vyper ;)
def debug_opcode(computation):
print('YOUR ARE HERE!')
import ipdb; ipdb.set_trace()
import evm
from evm.vm.opcode import as_opcode
from vyper.opcodes import opcodes as vyper_opcodes
from evm.vm.forks.byzantium.computation import ByzantiumComputation
opcodes = ByzantiumComputation.opcodes.copy()
opcodes[vyper_opcodes['DEBUG'][0]] = as_opcode(
logic_fn=debug_opcode,
mnemonic="DEBUG",
gas_cost=0
)
setattr(evm.vm.forks.byzantium.computation.ByzantiumComputation, 'opcodes', opcodes)
@uhbif19
Copy link

uhbif19 commented Sep 24, 2019

How to use it in contracts?

@jacqueswww
Copy link
Author

Checkout https://github.com/status-im/vyper-debug, has a vyper-run command wich one can use to run a contract.
One just places vdb in the contract to create a breakpoint.

@uhbif19
Copy link

uhbif19 commented Sep 25, 2019

This works only with Vyper? I use PyEVM to test Solidity contracts. Looks like your snipped is related only to PyEVM, and not Vyper. Maybe combination of your snippet with inline assembler with this instruction could work?

@jacqueswww
Copy link
Author

Yes this is for vyper, for solidity checkout https://github.com/iamdefinitelyahuman/brownie - has pretty good debugger that uses PyEVM underlying.
The above snippet uses a custom opcode that the vyper compiler injects into the bytecode - which was a quick hack, in favour of using the program counter.

@uhbif19
Copy link

uhbif19 commented Sep 25, 2019

Thanks for replies. I will check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment