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.

UnboundLocalError when using dynamic analysis

See original GitHub issue

Some EVM bytecode inputs result in an UnboundLocalError exception. For example:

$ python octopus_eth_evm.py -g -r "6080604052348015600f57600080fd5b506004361060465760003560e01c80632f576f2014604b57806381b36467146067578063a0ef91df14606f578063bcb4ab0e146077575b600080fd5b6051607f565b6040518082815260200191505060405180910390f35b606d6088565b005b60756094565b005b607d60f3565b005b60008054905090565b6001600014609257fe5b565b3373ffffffffffffffffffffffffffffffffffffffff166108fc3073ffffffffffffffffffffffffffffffffffffffff16319081150290604051600060405180830381858888f1935050505015801560f0573d6000803e3d6000fd5b50565b600160008190555056fea165627a7a7230582097b073d8789a43fedeb6be6929b92747b0ddbcfd568d5c737d90ea40ce8efe9f0029"
Traceback (most recent call last):
  File "octopus_eth_evm.py", line 186, in <module>
    main()
  File "octopus_eth_evm.py", line 164, in main
    octo_cfg = EthereumCFG(octo_bytecode)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/cfg.py", line 9, in __new__
    return EvmCFG(bytecode, analysis=evm_analysis)
  File "/Users/bernhardmueller/Projects/octopus/octopus/arch/evm/cfg.py", line 160, in __init__
    self.run_dynamic_analysis()
  File "/Users/bernhardmueller/Projects/octopus/octopus/arch/evm/cfg.py", line 173, in run_dynamic_analysis
    emul.emulate()
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 433, in ssa_stack_memory_storage_flow_instruction
    self.emulate(new_state, depth=depth + 1)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 400, in ssa_stack_memory_storage_flow_instruction
    self.emulate(new_state, depth=depth + 1)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 148, in emulate_one_instruction
    self.emul_comparaison_logic_instruction(instr, state)
  File "/Users/bernhardmueller/Projects/octopus/octopus/platforms/ETH/emulator.py", line 261, in emul_comparaison_logic_instruction
    instr.name, args=args)
UnboundLocalError: local variable 'args' referenced before assignment

The bytecode was generated with solc 0.5.7 from the following source:

pragma solidity ^0.5.0;

contract Test {

	uint256 myinteger;

    function doNothing() public view returns (uint256) {
    	return myinteger;
    }

    function write() public {
    	myinteger = 1;
    }

    function alwaysfail() public {
    	assert(0 == 1);
    }

    function withdrawEth() public {
    	msg.sender.transfer(address(this).balance);
    }
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pventuzelocommented, May 7, 2019

Thanks Bernhard 😉 i will try to take a look asap

0reactions
pventuzelocommented, Sep 15, 2022

Sorry, I’m not planning to fix this at the moment. You might be interested in using https://github.com/crytic/evm_cfg_builder

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnboundLocalError when using dynamic analysis · Issue #10 ...
Some EVM bytecode inputs result in an UnboundLocalError exception. For example: $ python octopus_eth_evm.py -g -r ...
Read more >
Python – UnboundLocalError: local variable 'p' referenced ...
You are getting this error for invalid inputs because it prints out the first time for invalid inputs but then the code continues...
Read more >
How To Resolve UnboundLocalError On Local Variable When ...
Summary: To resolve an UnboundLocalError when the local variable is reassigned after the first use, you can either use the global keyword or...
Read more >
Eigenvalus analysis in PSSE - Python for PSSE help forum
Hello! I am trying to perform a small signal stability analysis on PSS E, but when I run the dynamic simulation "Launch eigenvalue...
Read more >
Programming FAQ — Python 3.11.1 documentation
Why am I getting an UnboundLocalError when the variable has a value? What are the rules for local and global variables in Python?...
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