CityOfZion / neo-python

Python Node and SDK for the NEO 2.x blockchain. For NEO 3.x go to our successor project neo-mamba
https://neo-python.readthedocs.io/en/latest/
MIT License
313 stars 189 forks source link

Circular map reference causes Python stack overflow #1000

Closed hal0x2328 closed 5 years ago

hal0x2328 commented 5 years ago

Current behavior

(Using development branch, probably applies to master as well).

A circular map reference in a contract will hang the neo-python process and eventually overflow the Python stack.

Here's the line that will be executed over and over increasing the stack usage each time it encounters the circular reference:

https://github.com/CityOfZion/neo-python/blob/b519f55e8ae352f770cfa3290c7916beacfee562/neo/VM/ExecutionEngine.py#L105

This probably impacts circular array references as well.

Expected behavior

Python should exhibit the same behavior as neo-cli, which is to FAULT as soon as the VM stack size exceeds the maximum allowed.

How to reproduce

Run neo-python on TestNet and wait until you hit transaction e30e96c2203e1e8e604b17718edd37ae812324e91804e4af352908793e4e2911 in block 2946221. You'll know when you hit it because the prompt will become completely unresponsive. (neo-cli returns a FAULT on this transaction after only 1.072 GAS used and then continues on to the next transaction).

or,

try this demo contract:

def Main(operation):
  mymap = {}
  mymap['key1'] = "circular reference demo"
  mymap['key2'] = "or, how to kill neo-python with a single invocation"
  mymap['key3'] = "more keys helps speed up the process"
  mymap['key4'] = "more keys helps speed up the process"
  mymap['key5'] = "more keys helps speed up the process"
  mymap['key6'] = "more keys helps speed up the process"
  mymap['key7'] = "more keys helps speed up the process"
  mymap['key8'] = "more keys helps speed up the process"
  mymap['key9'] = "more keys helps speed up the process"
  mymap['circular'] = mymap

invoke as:

sc build_run poc.py False False False 07 05 test

Your environment

OS: OSX Mojave neo-python v0.8.5-dev Python 3.7.2