FuzzingLabs / octopus

Security Analysis tool for WebAssembly module (wasm) and Blockchain Smart Contracts (BTC/ETH/NEO/EOS)
https://fuzzinglabs.com/
MIT License
479 stars 83 forks source link

UnboundLocalError: local variable 'args' referenced before assignment #24

Open naderfyi opened 1 year ago

naderfyi commented 1 year ago

Bytecode can be found here if you want to test it: Download

For some bytecodes when I try to extract the CFG using: python3 main.py -f bb.bin -g

I get the following error:

Traceback (most recent call last):
  File "/Users/nader/Desktop/octo/octopus/octopus/platforms/ETH/cfg.py", line 9, in __new__
    return EvmCFG(bytecode, analysis=evm_analysis)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/cfg.py", line 160, in __init__
    self.run_dynamic_analysis()
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/cfg.py", line 173, in run_dynamic_analysis
    emul.emulate()
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 400, in ssa_stack_memory_storage_flow_instruction
    self.emulate(new_state, depth=depth + 1)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 148, in emulate_one_instruction
    self.emul_comparaison_logic_instruction(instr, state)
  File "/Users/nader/Desktop/octo/octopus/octopus/arch/evm/emulator.py", line 261, in emul_comparaison_logic_instruction
    instr.name, args=args)
UnboundLocalError: local variable 'args' referenced before assignment

Anyone knows what might be the exact problem here?

I would gladly work on a fix for this if there is any guidance on how the emulator is working.

btogzhan2000 commented 1 year ago

If this helps to anyone, in octopus/arch/evm/emulator.py, function emul_comparaison_logic_instruction(self, instr, state), you can put args=None at the start of the code and it will work. I faced the same issue.

Jswdbx commented 1 year ago

If this helps to anyone, in octopus/arch/evm/emulator.py, function emul_comparaison_logic_instruction(self, instr, state), you can put args=None at the start of the code and it will work. I faced the same issue.

Hello, I also have the same problem, but after you put args=None at the beginning of the function according to your answer, there are other problems. Do you have other problems?

I get the following error:

Traceback (most recent call last):
  File "W:\pycharm\octopus-master\octopus_eth_evm.py", line 187, in <module>
    main()
  File "W:\pycharm\octopus-master\octopus_eth_evm.py", line 164, in main
    octo_cfg = EthereumCFG(octo_bytecode)
  File "W:\pycharm\octopus-master\octopus\platforms\ETH\cfg.py", line 9, in __new__
    return EvmCFG(bytecode, analysis=evm_analysis)
  File "W:\pycharm\octopus-master\octopus\arch\evm\cfg.py", line 160, in __init__
    self.run_dynamic_analysis()
  File "W:\pycharm\octopus-master\octopus\arch\evm\cfg.py", line 173, in run_dynamic_analysis
    emul.emulate()
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 432, in ssa_stack_memory_storage_flow_instruction
    self.emulate(new_state, depth=depth + 1)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 399, in ssa_stack_memory_storage_flow_instruction
    self.emulate(new_state, depth=depth + 1)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 122, in emulate
    halt = self.emulate_one_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 168, in emulate_one_instruction
    halt = self.emulate_one_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 168, in emulate_one_instruction
    halt = self.ssa_stack_memory_storage_flow_instruction(instr, state, depth)
  File "W:\pycharm\octopus-master\octopus\arch\evm\emulator.py", line 352, in ssa_stack_memory_storage_flow_instruction
    target = next(filter(lambda element: element.offset == jump_addr, self.instructions))
StopIteration