GithubHelp home page GithubHelp logo

cityofzion / neo-boa Goto Github PK

View Code? Open in Web Editor NEW
68.0 68.0 55.0 1.27 MB

Python compiler for the Neo2 Virtual Machine, see neo3-boa for NEO3

License: MIT License

Python 99.76% Makefile 0.18% Dockerfile 0.06%

neo-boa's People

Contributors

alexhulbert avatar belane avatar conscott avatar edgedlt avatar fabwa avatar hal0x2328 avatar iddoberger avatar ixje avatar jhepkema avatar jhwinter avatar jordanfung avatar jorritvandenberg avatar lllwvlvwlll avatar localhuman avatar lock9 avatar meevee98 avatar melanke avatar metachris avatar relfos avatar rockacola avatar shargon avatar slipo avatar stefandasbach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neo-boa's Issues

Invalid bytecode generated by neo-boa

We are using neo-boa 0.2.1 in order to work around compiler issues in neo-boa 0.2.2 (see #35).

This issue might have the same root cause as #29, but I'm creating anew since it seems like this issue is manifesting itself in a much worse way, with no identified workaround as of yet.

When issuing a testinvoke, we are getting this kind of response, even though the function only ever returns either True or False:

[I 180202 15:36:54 EventHub:71] [test_mode][SmartContract.Execution.Success] [521ce5bdb87b53f7163217fba66663e605f08fce] [b'kyc_ok', b'pre_end', b'r1', b'\x00\xb8d\xd9E', b'\x00\x90/P\t', b'\x00 _\xa0\x12', b'\x00@\xf0\x9b\xbc\xe1\x08', b'\xad\x0e', b'pub_start', b'r2', b'\x00\xac#\xfc\x06', b'\x00\xad\xd5\xc0\x07', b'r3', b'\x00\xe8vH\x17', b'\x00\xdb\x8bU\x07', b'\x00\xac#\xfc\x06', b'\x10\xe1\xb3Z', b'\xf0\x1e\x02', b'\x00\x00\x8dI\xfd\x1a\x07', b'team_tokens', b'\x80\xad*\\', b'\x00\x80S\xee{\xa8\n', b'company_tokens', b'\x00`\x8f\xc6\x92\xa3"', b'rewards_fund', b'\x00']
Used 1.365 Gas 

-------------------------------------------------------------------------------------------------------------------------------------
Test invoke successful
Total operations: 1365
Results ['Struct: [<neo.VM.InteropService.ByteArray object at 0x109c306d8>, <neo.VM.InteropService.ByteArray object at 0x109c30048>, <neo.VM.InteropService.ByteArray object at 0x109c30940>, <neo.VM.InteropService.ByteArray object at 0x109c30588>, <neo.VM.InteropService.ByteArray object at 0x109c30b70>, <neo.VM.InteropService.ByteArray object at 0x109c30160>, <neo.VM.InteropService.ByteArray object at 0x109c30be0>, <neo.VM.InteropService.ByteArray object at 0x109c30a90>, <neo.VM.InteropService.ByteArray object at 0x109c307b8>, <neo.VM.InteropService.ByteArray object at 0x109c30198>, <neo.VM.InteropService.ByteArray object at 0x109c30c18>, <neo.VM.InteropService.ByteArray object at 0x109c30f28>, <neo.VM.InteropService.ByteArray object at 0x109c30b00>, <neo.VM.InteropService.ByteArray object at 0x109c30cc0>, <neo.VM.InteropService.ByteArray object at 0x109c30dd8>, <neo.VM.InteropService.ByteArray object at 0x109c30ef0>, <neo.VM.InteropService.ByteArray object at 0x109c307f0>, <neo.VM.InteropService.ByteArray object at 0x109c30f98>, <neo.VM.InteropService.ByteArray object at 0x109c30400>, <neo.VM.InteropService.ByteArray object at 0x109c30748>, <neo.VM.InteropService.ByteArray object at 0x109c30ba8>, <neo.VM.InteropService.ByteArray object at 0x10a589390>, <neo.VM.InteropService.ByteArray object at 0x10a5896d8>, <neo.VM.InteropService.ByteArray object at 0x10a589438>, <neo.VM.InteropService.ByteArray object at 0x10a5895f8>] ', "ByteArray: bytearray(b'\\x00')"]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.001
-------------------------------------------------------------------------------------------------------------------------------------

It seems like the actual value being returned is some kind of full representation of the stack?

If we actually try to invoke it, there are a bunch of different tracebacks as a result:

[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'z' ROLL
[E 180202 15:28:11 ExecutionEngine:853] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 299, in ExecuteOp
        estack.PushT(estack.Remove(n))
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[I 180202 15:28:11 InteropService:96] Trying to get big integer Array: ['Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'] 
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Not Supported b'\xc4' SETITEM
[E 180202 15:28:11 ExecutionEngine:853] Not Supported
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 724, in ExecuteOp
        index = estack.Pop().GetBigInteger()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/InteropService.py", line 97, in GetBigInteger
        raise Exception("Not Supported")
    Exception: Not Supported
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'z' ROLL
[E 180202 15:28:11 ExecutionEngine:853] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 299, in ExecuteOp
        estack.PushT(estack.Remove(n))
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[I 180202 15:28:11 InteropService:96] Trying to get big integer Array: ['Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'] 
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Not Supported b'\xc4' SETITEM
[E 180202 15:28:11 ExecutionEngine:853] Not Supported
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 724, in ExecuteOp
        index = estack.Pop().GetBigInteger()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/InteropService.py", line 97, in GetBigInteger
        raise Exception("Not Supported")
    Exception: Not Supported
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'z' ROLL
[E 180202 15:28:11 ExecutionEngine:853] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 299, in ExecuteOp
        estack.PushT(estack.Remove(n))
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[I 180202 15:28:11 InteropService:96] Trying to get big integer Array: ['Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'] 
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Not Supported b'\xc4' SETITEM
[E 180202 15:28:11 ExecutionEngine:853] Not Supported
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 724, in ExecuteOp
        index = estack.Pop().GetBigInteger()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/InteropService.py", line 97, in GetBigInteger
        raise Exception("Not Supported")
    Exception: Not Supported
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'z' ROLL
[E 180202 15:28:11 ExecutionEngine:853] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 299, in ExecuteOp
        estack.PushT(estack.Remove(n))
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[I 180202 15:28:11 InteropService:96] Trying to get big integer Array: ['Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'Struct: [<neo.VM.InteropService.ByteArray object at 0x131da17b8>, <neo.VM.InteropService.ByteArray object at 0x131da15f8>, <neo.VM.InteropService.ByteArray object at 0x131da1438>, <neo.VM.InteropService.ByteArray object at 0x131da14e0>, <neo.VM.InteropService.ByteArray object at 0x131da14a8>, <neo.VM.InteropService.ByteArray object at 0x131da1390>, <neo.VM.InteropService.ByteArray object at 0x131da11d0>, <neo.VM.InteropService.ByteArray object at 0x131da1198>, <neo.VM.InteropService.ByteArray object at 0x131da16a0>, <neo.VM.InteropService.ByteArray object at 0x131da10b8>, <neo.VM.InteropService.ByteArray object at 0x131da1f28>, <neo.VM.InteropService.ByteArray object at 0x131da1748>, <neo.VM.InteropService.ByteArray object at 0x131da1160>, <neo.VM.InteropService.ByteArray object at 0x131da1ac8>, <neo.VM.InteropService.ByteArray object at 0x131da1cc0>, <neo.VM.InteropService.ByteArray object at 0x131da1cf8>, <neo.VM.InteropService.ByteArray object at 0x131da1d30>, <neo.VM.InteropService.ByteArray object at 0x131da1d68>, <neo.VM.InteropService.ByteArray object at 0x131da1a90>, <neo.VM.InteropService.ByteArray object at 0x131da1b00>, <neo.VM.InteropService.ByteArray object at 0x131da1b38>, <neo.VM.InteropService.ByteArray object at 0x133116630>, <neo.VM.InteropService.ByteArray object at 0x131da1c18>, <neo.VM.InteropService.ByteArray object at 0x131da1c50>, <neo.VM.InteropService.ByteArray object at 0x131da1da0>] ', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'None'] 
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Not Supported b'\xc4' SETITEM
[E 180202 15:28:11 ExecutionEngine:853] Not Supported
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 724, in ExecuteOp
        index = estack.Pop().GetBigInteger()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/InteropService.py", line 97, in GetBigInteger
        raise Exception("Not Supported")
    Exception: Not Supported
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: 'NoneType' object has no attribute 'IsArray' b'\xc3' PICKITEM
[E 180202 15:28:11 ExecutionEngine:853] 'NoneType' object has no attribute 'IsArray'
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 705, in ExecuteOp
        if not item.IsArray:
    AttributeError: 'NoneType' object has no attribute 'IsArray'
[E 180202 15:28:11 ExecutionEngine:852] COULD NOT EXECUTE OP: Invalid list operation b'|' SWAP
[E 180202 15:28:11 ExecutionEngine:853] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 850, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 313, in ExecuteOp
        x1 = estack.Pop()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 45, in Pop
        return self.Remove(0)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[E 180202 15:28:11 StateMachine:453] could not get storage context Invalid list operation 
[I 180202 15:28:11 EventHub:71] [test_mode][SmartContract.Storage.Get] [6e945ca41064e1c451d11a7a4eaa84d119c7cfbc] ["b'owner' -> bytearray(b'\\xde\\xf3Z-\\x0ci\\xfe\\xb9\\xc4\\xcc\\x96p\\x1f\\xd4\\xdb\\x8fZ\\x044\\x00')"]
[I 180202 15:28:11 EventHub:71] [test_mode][SmartContract.Storage.Get] [6e945ca41064e1c451d11a7a4eaa84d119c7cfbc] ["b'team_tokens' -> bytearray(b'')"]
[I 180202 15:28:11 EventHub:71] [test_mode][SmartContract.Storage.Put] [6e945ca41064e1c451d11a7a4eaa84d119c7cfbc] ["b'team_tokens' -> bytearray(b'\\x00\\x80\\xc6\\xa4~\\x8d\\x03')"]
[I 180202 15:28:11 EventHub:71] [test_mode][SmartContract.Execution.Fail] [6e945ca41064e1c451d11a7a4eaa84d119c7cfbc] [None, 6]
Error testing contract invoke

"Invalid list operation" error with if conditions

As discussed with @localhuman in #python Discord.

The following snippet of code (taken from our modified version of the nex-ico-template project) is failing on the if condition:

is_kyc_approved = self.get_kyc_status(attachments.sender_addr, storage)
print(is_key_approved)
if not is_kyc_approved:
    print("not KYC approved")
    return 0

Here is the output:

[I 180116 18:34:22 EventHub:102] [test_mode][SmartContract.Runtime.Log] [465172675f3249377aff2dde78093cf75b8429ac] b'\x01'
[E 180116 18:34:22 ExecutionEngine:831] COULD NOT EXECUTE OP: Invalid list operation b'c' JMPIF
[E 180116 18:34:22 ExecutionEngine:832] Invalid list operation
    Traceback (most recent call last):
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 829, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/ExecutionEngine.py", line 172, in ExecuteOp
        fValue = estack.Pop().GetBoolean()
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 45, in Pop
        return self.Remove(0)
      File "/Users/brian/Projects/Narrative/neo-python/neo/VM/RandomAccessStack.py", line 57, in Remove
        raise Exception("Invalid list operation")
    Exception: Invalid list operation
[I 180116 18:34:22 EventHub:102] [test_mode][SmartContract.Runtime.Log] [465172675f3249377aff2dde78093cf75b8429ac] b'not KYC approved'

is_kyc_approved is true, but the if condition fails due to the "Invalid list operation" error.

I've tested on the latest neo-boa development branch, and it has the same issue.

We can work around the issue by putting a print statement right after the if or by adding an else condition.

_check_load_attr is not checking for duplicate full_name

I got an error message like below,
Could not execute command: Could not determine attribute to load. Options: ['boa.interop.Neo.Transaction.GetReferences', 'boa.interop.Neo.Transaction.GetReferences', 'boa.interop.Neo.Transaction.GetReferences', 'boa.interop.Neo.Transaction.GetReferences']

I dug deeper into it and found out that it could not determine attribute to load when I called tx.References where tx was GetScriptContainer.

I made a check for duplicate full_name in the _check_load_attr in expression.py which resolved the problem.

Tests fail when run multiple times

If you run make test multiple consecutive times for neo-python, the neo_boa tests will fail for test_ico_template.py with 5 different errors:

======================================================================
FAIL: test_ICOTemplate_1 (boa_test.tests.test_ico_template.TestContract)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/brian/Projects/Narrative/neo-python/venv/lib/python3.6/site-packages/boa_test/tests/test_ico_template.py", line 70, in test_ICOTemplate_1
    self.assertEqual(results[0].GetBigInteger(), 0)
AssertionError: 250040000000000 != 0

======================================================================
FAIL: test_ICOTemplate_2 (boa_test.tests.test_ico_template.TestContract)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/brian/Projects/Narrative/neo-python/venv/lib/python3.6/site-packages/boa_test/tests/test_ico_template.py", line 124, in test_ICOTemplate_2
    self.assertEqual(results[0].GetBigInteger(), test_transfer_amount)
AssertionError: 7200010003 != 2400000001

======================================================================
FAIL: test_ICOTemplate_3_KYC (boa_test.tests.test_ico_template.TestContract)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/brian/Projects/Narrative/neo-python/venv/lib/python3.6/site-packages/boa_test/tests/test_ico_template.py", line 178, in test_ICOTemplate_3_KYC
    self.assertEqual(results[0].GetBoolean(), False)
AssertionError: True != False

======================================================================
FAIL: test_ICOTemplate_5_mint (boa_test.tests.test_ico_template.TestContract)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/brian/Projects/Narrative/neo-python/venv/lib/python3.6/site-packages/boa_test/tests/test_ico_template.py", line 252, in test_ICOTemplate_5_mint
    self.assertEqual(results[0].GetBoolean(), True)
AssertionError: False != True

======================================================================
FAIL: test_ICOTemplate_6_approval (boa_test.tests.test_ico_template.TestContract)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/brian/Projects/Narrative/neo-python/venv/lib/python3.6/site-packages/boa_test/tests/test_ico_template.py", line 284, in test_ICOTemplate_6_approval
    self.assertEqual(results[0].GetBigInteger(), 0)
AssertionError: 123234 != 0

----------------------------------------------------------------------
Ran 73 tests in 36.524s

FAILED (failures=5)
make: *** [test] Error 1

The issue is that the fixtures/debugstorage dir isn't being removed properly. I've confirmed this is the case by checking the fixtures dir after running make test and the debugstorage dir is always left behind. If I delete it and then run make test, it will succeed.

There is code that attempts to do it:

https://github.com/CityOfZion/neo-boa/blob/master/boa_test/tests/test_ico_template.py#L30

But it's not working for some reason. The same code (and issue?) exists in test_storage.py and test_contract.py, as well. Do these tests need to be updated to override leveldb_testpath()?

I'm not 100% sure on the solution, so I've not submitted a PR.

One related aside: it looks like the btest.tar.gz file is left around after running the tests, too. This doesn't seem to be causing any issues, but perhaps we should delete it for completeness, as well?

@localhuman, any thoughts?

CheckWitness does not pass using RegisterAppCall

Current behavior

  • What is the problem?

Contract A does not pass CheckWitness in Contract B using RegisterAppCall.

Contract A calling Contract B

Contract = RegisterAppCall('14b768f3303fb642dfebe7dee4f45550226a47c2', 'operation', 'args')

def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Application():

        if operation == "test_script_hash":
            address_to = args[0]
            contract_hash = GetExecutingScriptHash()

            params = [contract_hash, address_to, 10000]

            Contract('transfer', params)

Contract B method being called

def do_transfer(ctx, t_from, t_to, amount):

if amount <= 0:
    return False

if len(t_to) != 20:
    return False

if CheckWitness(t_from):

    if t_from == t_to:
        print("transfer to self!")
        return True

    from_val = Get(ctx, t_from)

    if from_val < amount:
        print("insufficient funds")
        return False

    if from_val == amount:
        Delete(ctx, t_from)

    else:
        difference = from_val - amount
        Put(ctx, t_from, difference)

    to_value = Get(ctx, t_to)

    to_total = to_value + amount

    Put(ctx, t_to, to_total)

    OnTransfer(t_from, t_to, amount)

    return True
else:
    print("from address is not the tx sender")

return False

Result - Printed to the console
"from address is not the tx sender"

What should be happening

  • I believe CheckWitness should be passing in contract B.

Your environment

  • OS: (Windows version/Linux distro/OSX version)
    Ubuntu 16.04
  • neo-python version: (hint: use np-prompt --version)
    neo-python v0.7.1
  • Python version: (hint: python -V)
    Python 3.6.5

Generate ABI together with AVM

Hi! I strongly appreciate neo-boa project, and I just wonder if you plan to generate an Application Binary Interface (ABI) json description of the compiled functions (parameters/return types) together with the .avm. This is an interesting feature from NEO C# compiler.
Best regards!

Blockchain Module imports not working?

We've found our smart contract stopped compiling on the latest neo-boa (both master and development branches). It looks like this commit is the culprit:

2c6e01a

The compile works fine on the prior commit:

aad18d8

(venv) neo-boa $ git checkout 2c6e01ad89b398092610cff89a23f11484b3bfb1
Previous HEAD position was aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
HEAD is now at 2c6e01a... Blockchain no longer imports other modules
(venv) neo-boa $ python compile.py 
Traceback (most recent call last):
  File "compile.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/ico_template.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetTimestamp not found
(venv) neo-boa $ git checkout aad18d8c47a9b3f99ec15bfdb7653c673f4691c3
Previous HEAD position was 2c6e01a... Blockchain no longer imports other modules
HEAD is now at aad18d8... Merge branch 'development' of github.com:CityOfZion/neo-boa into development
(venv) neo-boa $ python compile.py 
(venv) neo-boa $

Note that "GetTimestamp" compile error is the same on the latest master, as well.

Our project is https://github.com/NarrativeNetwork/tokensale-neo-smartcontract if you want to test against the same source.

If we remove the Header.Timestamp property reference, the GetTimestamp error goes away and turns into:

(venv) neo-boa brian$ python compile.py 
Traceback (most recent call last):
  File "compile.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/ico_template.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetUnspentCoins not found
(venv) neo-boa brian$ 

I tried to isolate a more limited use case, but it seems to be challenging, as there appear to be non-deterministic properties of this issue. Here's one example, but this doesn't seem to be affected by the specific changeset I mentioned above:

from boa.blockchain.vm.Neo.Transaction import Transaction

class Test():
    def Main(self):
        return 0

That results in what appears to be the same GetUnspentCoins error as above:

(venv) neo-boa brian$ python compile.test.py 
Traceback (most recent call last):
  File "compile.test.py", line 3, in <module>
    Compiler.load_and_save('../tokensale-neo-smartcontract/test.py')
  File ".../neo-boa/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File ".../neo-boa/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File ".../neo-boa/boa/code/module.py", line 403, in write
    self.link_methods()
  File ".../neo-boa/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method GetUnspentCoins not found
(venv) neo-boa brian$ 

For now, to work around the issue, we are using neo-boa 0.2.1, as the issue is present in 0.2.2.

[Feature] Linter

Check for the following things which often cause errors:

  • calling a method but not assigning its return value as something
  • calling a method with the wrong number of arguments
  • unsupported python builtin methods

Add Tests

3 layers of tests would be nice

  • First set of tests would simply load and compile all example files to see if any of them have compile errors

  • Unit tests would test individual methods in the code base to make sure they do what they should be doing.

  • Final set of tests would involve including neo-python and running compiled tests through the VM to see if their output is as expected.

[Feature] Use Python assert in smart contract

It would be neat if we could replace something like:

if not CheckWitness(Owner):
    print("Unauthorized user")
    return False

with:

assert CheckWitness(Owner), "Unauthorized user"

I'm moving to just implement this in the following way in my smart contracts:

OnError = RegisterAction('error', 'message')
...
sc_assert(CheckWitness(Owner), "Unauthorized user")

def sc_assert(condition, msg):
    if not condition:
        print(msg) # for neo-python console
        OnError(msg) # for neo-cli ApplicationLog
        throw_if_null(0)

but it would be cool if it were just natively supported with the existing assert keyword in Python.

(I noticed that the neo-cli implementation ofgetapplicationlog returns the notification events that triggered before the contract faulted, so the sc_assert function I wrote takes advantage of that - I see this as being a huge help for people trying to debug contract failures after-the-fact. So if this suggestion were to be implemented as a built-in it would be nice to replicate that feature too.)

Smart Contract Migration results in different return value

I'm currently trying to implement smart contract migration into my token, but it fails. Have now created a sample repo to investigate a bit more.

To make it less error prone on my side, I've copied the values from the tests in this repo and used the simple examples from the neo-python docs, slightly modified.
I store simply a number and then get that again.

When I normally deploy the contract all looks good, like the one I use in the beginning.

 > sc invoke 0x0546b7c512bd2fc13d5579b35e5ed84602e576ac balance ['BBB']
 ---------------------------
Test invoke successful
Total operations: 61
Results [{'type': 'ByteArray', 'value': '01'}]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.0001
----------------------------

neo> [I 190412 11:45:08 EventHub:62] [SmartContract.Execution.Success][7492] [060b418755cdd2bb594a8a58d6c4947e960a1cdb] [tx 52c53d0ad1c2054164a8e0ac85ac8c136bb16dc5d44d72dd104c872c94372001] {'type': 'Array', 'value': [{'type': 'Array', 'value': [{'type': 'ByteArray', 'value': b'2y\x06'}]}, {'type': 'ByteArray', 'value': b'balance'}]}

However when I invoke the migrated contract it the result is an Array

# The migrated coontract however returns

> sc invoke 0x060b418755cdd2bb594a8a58d6c4947e960a1cdb balance ['BBB']

--------------------------
Test invoke successful
Total operations: 7
Results [{'type': 'Array', 'value': [{'type': 'ByteArray', 'value': '327906'}]}, {'type': 'ByteArray', 'value': '62616c616e6365'}]
Invoke TX GAS cost: 0.0
Invoke TX fee: 0.0001
--------------------------

The migration looks like this

    elif operation == 'migrate':    
        print("Migrate operation") 
        
        # taken out of neo boa test example
        param_list = bytearray(b'\x07\x10')
        return_type = bytearray(b'\x05')
        properties = 1
        name = 'migrated contract 3'
        version = '0.3'
        author = 'localhuman3'
        email = '[email protected]'
        description = 'test migrate3'

        new_contract = Migrate(args[0], param_list, return_type, properties, name, version, author, email, description)
        print("contract migrated")

        return new_contract

which I invoke like this

sc invoke 0xe1d955a7a6c2c2af58eb2ea0abf28f3a2a9ee568 migrate [0x011fc56b6a00527ac46a51527ac468164e656f2e53746f726167652e476574436f6e74657874616a52527ac46a00c30361646487646e0006616464696e67680f4e656f2e52756e74696d652e4c6f676a52c36a51c300c37c680f4e656f2e53746f726167652e476574616a53527ac46a53c36a51c351c3936a54527ac46a52c36a51c300c36a54c35272680f4e656f2e53746f726167652e507574616a54c36c7566616a00c30672656d6f7665876454006a52c36a51c300c37c680f4e656f2e53746f726167652e476574616a53527ac46a52c36a51c300c36a53c36a51c351c3945272680f4e656f2e53746f726167652e507574616a53c36a51c351c3946c7566616a00c30762616c616e6365876421006a52c36a51c300c37c680f4e656f2e53746f726167652e476574616c7566616a00c3076d69677261746587642401174d696772617465206f7065726174696f6e207374617274680f4e656f2e52756e74696d652e4c6f670207106a55527ac401056a56527ac4516a57527ac4136d6967726174656420636f6e747261637420336a58527ac403302e336a59527ac40b6c6f63616c68756d616e336a5a527ac40d6e657840656d61696c2e636f6d6a5b527ac40d74657374206d696772617465336a5c527ac46a51c300c36a55c36a56c36a57c36a58c36a59c36a5ac36a5bc36a5cc3587951795a727551727557795279597275527275567953795872755372755579547957727554727568144e656f2e436f6e74726163742e4d696772617465616a5d527ac411636f6e7472616374206d69677261746564680f4e656f2e52756e74696d652e4c6f676a5dc36c756661006c7566] 

I'm using the neo-python version 0.8.4 from current neo-local repo.

I've created a repository with instructions in the README to follow along my steps and to be able to replicate.

Documentation

Finish documentation efforts.

Also, documentation should be converted to use Google Python style, rather than the current RST style.

either blockchain or header API issue

One of my smart contract has this code

currentHeight = GetHeight()
currentHeader = GetHeader(currentHeight)
data = currentHeader.GetConsensusData(currentHeader)

Its giving me this error Exception: Could not load attribute GetConsensusData

I'm must admit that I'm using older version of private net while I'm using the latest version of neo python to build and deploy contract. Not sure how to get around this, my requirement right now is to stick to setup but if it helps can I upgrade all consesus nodes on my private net

Compiler Exception: Target method 2 not found

my code looks like this:

def func(a, b):
    return a + b

def Main():
    return func(func(1, 2), 3)

and the compiler said:

Traceback (most recent call last):
  File "./neopy", line 6, in <module>
    Compiler.load_and_save(i)
  File "/Users/foo/.pyenv/versions/3.5.4/lib/python3.5/site-packages/neo_boa-0.2.1-py3.5.egg/boa/compiler.py", line 105, in load_and_save
    data = compiler.write()
  File "/Users/foo/.pyenv/versions/3.5.4/lib/python3.5/site-packages/neo_boa-0.2.1-py3.5.egg/boa/compiler.py", line 81, in write
    out_bytes = bytes(module.write())
  File "/Users/foo/.pyenv/versions/3.5.4/lib/python3.5/site-packages/neo_boa-0.2.1-py3.5.egg/boa/code/module.py", line 403, in write
    self.link_methods()
  File "/Users/foo/.pyenv/versions/3.5.4/lib/python3.5/site-packages/neo_boa-0.2.1-py3.5.egg/boa/code/module.py", line 462, in link_methods
    raise Exception("Target method %s not found" % vmtoken.target_method)
Exception: Target method 2 not found

Bug with returning True from while

reported by @hal0x2328

The following code is wonky when compiled

from boa.blockchain.vm.Neo.Runtime import GetTrigger
from boa.blockchain.vm.Neo.TriggerType import Application,Verification

def Main(bytes):

    trigger = GetTrigger()

    if trigger == Verification():
        print("Verification!")
        return False

    elif trigger == Application():
        print("Application!")
        i = 0
        l = len(bytes)
        while i < l:
            c = substr(bytes,i,1)
            i = i + 1 
            if c == 0:
                print("Null")
            else:
                print("Not null")
                return True

[DynamicAppCall] stack frame misalignment

When using DynamicAppCall's sometimes the altstack frame is misaligned when returning from the call. To elaborate, after a call like e.g. this

allowance = DynamicAppCall(token_contract, 'allowance', params)

It can happen that the last frame before returning from the call is not dropped from the altstack.

This seems to be a compiler byte code generation issue and does not always happen. I've discussed this with @localhuman and we're not sure yet where the root cause is.

A solution I used for myself is to patch VMToken.py to look like this:

        if pytoken.is_dynamic_appcall:
            # push the contract hash
            vmtoken = self.convert1(
                VMOp.APPCALL, py_token=pytoken, data=bytearray(20))

            self.insert1(VMOp.NOP)
            self.insert1(VMOp.NOP)
            self.insert1(VMOp.NOP)
            self.insert1(VMOp.FROMALTSTACK)
            self.insert1(VMOp.DROP)
            self.insert1(VMOp.NOP)
            return vmtoken

Note this was needed for MY specific smart contract as I needed to patch all calls except one. The 3 NOPs make it easy to find in a hexeditor and thus manually patch where needed. The FROMALTSTACK DROP is used for removing the extraneous stackframe. This serves as a possible solution for those encountering the same issue.

Finally: here is a zip with files + a readme to reproduce the issue. Hopefully we can test this with the new compiler :)

Compiler add BigInteger support

When importing the BigInteger, the compiler report 'not sure what to do with line <boa.code.line.Line object at 0x104861400> '.

The method to_s(), which generates the output of the executable in readable format, is outdated

Current behavior

The method to_s in the module.py seems to be outdated. Indeed the docstring example, LambdaTest.py, is not available anymore. If we also try to run the following python snippet code we get the following result:

from boa.compiler import Compiler
from boa_test.tests.boa_test import BoaTest

c = Compiler.load('./neo-boa/boa_test/example/AddTest.py')
module = c.default 
module.write()
print(module.to_s())

result:

image

Expected behavior

I would have expected see more rows. Something similar to the original python bytecode:

from dis import dis 
path='/home/dau/workspace/python/github.com/neo/neo-boa/boa_test/example/AddTest.py'
source = open(path, 'rb')
compiled_source = compile(source.read(), path, 'exec')
print(dis(compiled_source.co_code))

image

How to reproduce

see above

Your environment

  • OS: Ubuntu 18.X
  • neo-boa version: 0.5.4
  • Python version: 3.6

Issue with performing relative imports

Some users report issues with compiling files that import other modules.
For example:

>>> from boa.compiler import Compiler
>>> Compiler.load_and_save('../neo-ico-template/ico_template.py')
LOADING AND SAVING! ../neo-ico-template/ico_template.py 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/compiler.py", line 106, in load_and_save
    compiler = Compiler.load(path)
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/compiler.py", line 139, in load
    module = Module(path)
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/code/module.py", line 237, in __init__
    self.build()
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/code/module.py", line 261, in build
    imp = Import(lineset.items, self.path)
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/code/items.py", line 228, in __init__
    self.build()
  File "/Users/whale/blockchain/neo-python/neo-python/venv/lib/python3.5/site-packages/boa/code/items.py", line 237, in build
    module = importlib.import_module(self.module_path, self.module_path)
  File "/Users/whale/.pyenv/versions/3.5.1/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 981, in _gcd_import
  File "<frozen importlib._bootstrap>", line 931, in _sanity_check
SystemError: Parent module 'boa.blockchain.vm.Neo.Runtime' not loaded, cannot perform relative import

The compiler should do the best it can do determine relevant paths and add them to sys.path when necessary.

testInvoke error debugging

Hello

I'd enabled config sc-debug-notify on, but the only error I can see is Error testing contract invoke no other info

I'm sure the contact exist on private net, as this command

contract 0x16f59140b09a3ef087c01386cfb5ce27af45edfb

returns all its info

more detail in the snap, I'm running private net on the centos droplet inside docker image

image

Unexpected trailing 0x00 added to Log/Notify

    Notify(0xf9)
    Log(0xf9)

produces:

[SmartContract.Runtime.Notify] [109f289cf6ebeea930c0079b816e7f975094f0c6] [b'\xf9\x00']
[SmartContract.Runtime.Log] [109f289cf6ebeea930c0079b816e7f975094f0c6] [b'\xf9\x00']

failed to compile python file with smart contract to avm file

Following guide, I installed python 3.5.2 and boa. I got below error when trying to compile to avm file.
AttributeError: module 'sys' has no attribute 'file'

Detial error message as below:
(venv) ubuntu@ubuntu-VirtualBox:~/Downloads/neo-python-master/venv$ python boafile.py
Traceback (most recent call last):
File "boafile.py", line 3, in
Compiler.load_and_save('/home/ubuntu/Downloads/neo-python-master/venv/test.py')
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/compiler.py", line 104, in load_and_save
compiler = Compiler.load(path)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/compiler.py", line 137, in load
module = Module(path)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 235, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 259, in build
imp = Import(lineset.items, self.path)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 220, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 239, in build
items_to_import=self.module_items_to_import)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 235, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 259, in build
imp = Import(lineset.items, self.path)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 220, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 231, in build
filename = module.file
AttributeError: module 'sys' has no attribute 'file'

I modified items.py source code. Change the "module.file' as the file path that I want to compile. Then, I got below error:
RecursionError: maximum recursion depth exceeded

Detail error as below:
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 239, in build
items_to_import=self.module_items_to_import)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 235, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/module.py", line 259, in build
imp = Import(lineset.items, self.path)
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 220, in init
self.build()
File "/home/ubuntu/Downloads/neo-python-master/venv/lib/python3.5/site-packages/boa/code/items.py", line 229, in build
module = importlib.import_module(self.module_path, self.module_path)
File "/usr/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 993, in _gcd_import
File "", line 202, in _lock_unlock_module
File "", line 189, in _get_module_lock
RecursionError: maximum recursion depth exceeded

Contract Create, Migrate, Destroy signature issues?

It looks to me like the Create, Migrate, and Destroy functions in Contract.py have incorrect signatures. Specifically, I believe that Create and Migrate are missing the name argument, and Destroy has a superfluous contract argument that should be removed.

def Create(script, parameter_list, return_type, need_storage, version, author, email, description):
...
def Migrate(script, parameter_list, return_type, need_storage, version, author, email, description):
...
def Destroy(contract):

should be:

def Create(script, parameter_list, return_type, need_storage, name, version, author, email, description):
...
def Migrate(script, parameter_list, return_type, need_storage, name, version, author, email, description):
...
def Destroy():

Please correct me if I'm wrong, as I admittedly do not fully understand how exactly these methods are translated to the corresponding neo blockchain function invocations.

Built in str is not implemented

I created a file int2str.py in CLI
these are the contents:

def Main(num):
    result = ''
    result = int2str(num)
    return result

def int2str(num):
    res = ''
    lastdigit = 0
    while num > 9:
        lastdigit = num % 10
        num = num / 10
        res = str(lastdigit) + res
    res = str(num) + res
    return res

but when i build the file using the command: neo> build int2str.py test 02 07 True False 112
I got error:
Could not execute command: [Compilation error] Built in str is not implemented
File "/usr/lib/python3.6/threading.py", line 884, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.6/dist-packages/twisted/_threads/_threadworker.py", line 46, in work
task()
File "/usr/local/lib/python3.6/dist-packages/twisted/_threads/_team.py", line 190, in doWork
task()
File "/usr/local/lib/python3.6/dist-packages/twisted/python/threadpool.py", line 250, in inContext
result = inContext.theWork()
File "/usr/local/lib/python3.6/dist-packages/twisted/python/threadpool.py", line 266, in
inContext.theWork = lambda: context.call(ctx, func, *args, **kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/python/context.py", line 122, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python3.6/dist-packages/twisted/python/context.py", line 85, in callWithContext
return func(*args,**kw)
File "/neo-python/neo/bin/prompt.py", line 999, in run
traceback.print_stack()
Traceback (most recent call last):
File "/neo-python/neo/bin/prompt.py", line 948, in run
self.do_build(arguments)
File "/neo-python/neo/bin/prompt.py", line 393, in do_build
BuildAndRun(arguments, self.Wallet)
File "/neo-python/neo/Prompt/Commands/BuildNRun.py", line 46, in BuildAndRun
contract_script = Compiler.instance().load_and_save(path)
File "/usr/local/lib/python3.6/dist-packages/boa/compiler.py", line 97, in load_and_save
data = compiler.write()
File "/usr/local/lib/python3.6/dist-packages/boa/compiler.py", line 73, in write
out_bytes = bytes(self.entry_module.write())
File "/usr/local/lib/python3.6/dist-packages/boa/code/module.py", line 206, in write
self.link_methods()
File "/usr/local/lib/python3.6/dist-packages/boa/code/module.py", line 235, in link_methods
method.prepare()
File "/usr/local/lib/python3.6/dist-packages/boa/code/method.py", line 180, in prepare
exp.tokenize()
File "/usr/local/lib/python3.6/dist-packages/boa/code/expression.py", line 286, in tokenize
token.to_vm(self.tokenizer, last_token)
File "/usr/local/lib/python3.6/dist-packages/boa/code/pytoken.py", line 263, in to_vm
tokenizer.convert_method_call(self)
File "/usr/local/lib/python3.6/dist-packages/boa/code/vmtoken.py", line 464, in convert_method_call
vmtoken = self.convert_built_in(fname, pytoken)
File "/usr/local/lib/python3.6/dist-packages/boa/code/vmtoken.py", line 648, in convert_built_in
"[Compilation error] Built in %s is not implemented" % op)
NotImplementedError: [Compilation error] Built in str is not implemented

Anyone who knows how to fix it? Thanks..

Add Python 3.6 support

Currently boa only works with python 3.5 due to its use of the byteplay3 module. Options:

  • fork current byteplay3 to support 3.6
  • find another fork that already supports 3.6

testInvoke succesfull but transaction does not seem accepted by consensus nodes

Hello,

So its quite a scenario. I've private net running over consensus nodes and neo python(version 0.4.9 dev) of 3 month older versions, its actually entire docker image setup from this image ixje/precognition-poc of this git repo https://github.com/ixje/precognition-dapp-coz2 of dApp competition 2 winner.

What I'm trying to do is change contract code and build but its not working with the neo-python available in image its misses some modules like Attribute and GetTimestamp etc

So what I did is connected to private net running insider docker container with recent version of neo python (version 0.6.7 which I've installed outside image and running under global python3.6) and build and imported contract. All went well, even testInvoke is successful but it seems that contract execution is not approved by all consensus nodes.

What could be the problem?
1 Is it the private net nodes running inside docker image container while I'd built and imported smart contract from a latest neo-python so there might be any issue of both are running from different environments?

2 Is it the final built executable code of smart contract avm file which could not be executed in older version of blockchain? Not so likely though because contract would not have been imported at first place if the code can not be executed.

No module named boa.blockchain

i want to build a smart contract with neo-python and in my sc i want to have this module:

from boa.blockchain.vm.Neo.Storage import GetContext, Get, Put, Delete
i installed neo-boa in my neo-python-venv but i still get:
No module named boa.blockchain How can i get this module linked?
How can i get this fixed?

Crowdsale Demo directory shouldn't be labeled "nex"

This is more stylistic but the naming for the directory shouldn't be nex. It doesn't really describe what the files in the directory are for. Also, while many members of CoZ are a part of NEX, NEX isn't part of CoZ - this could confuse people starting out in developing NEP5 contracts.

Generate Debug map + breakpoint set for use in debugging

For use in debugging with neo-gui-developer or in a future neo-python debugging implementation, we need to generate a debug map that maps each instruction to a line number of a piece of code in each file.

This, together with a set of breakpoints that correspond to the map and instruction can be used to pause/inspect/step over or in general perform normal debugging tasks.

`is not None` problems

This source produce if (false) output

def Main(operation):

    if operation is not None:
        return True
    else:
        return False

As you can see, is impossible to return true in this opCode output

image

Could you check it @localhuman ?

Does the method "verify_signature" work when compiler SmartContract?

`
from boa.code.builtins import verify_signature

def Main(signature):
return verify_signature(signature,b'\x03\xeb\x08\x81\xd1\xd6GT\xd5\x02U\xbf\x16\x07\x9e\xd6\xcb\xc3\x98$c\xa8\x90L\xb9\x19B+9\x17\x8b\xef?')

`
I compiler a SmartContract like this ,but when I invoke ,it always return False,Why?

Issue with appending to a list

l = [1,2,3]
l.append(5)

[I 180102 11:50:35 EventHub:102] [test_mode][SmartContract.Execution.Fail] [e96952d0043006836c4d0057a68c9779af7073bd] [[[1, 2, 3], 5], None, 6]

negative shift count error when running unit test

I get a "negative shift count error" when running the unit tests. Is this supposed to happen?

python -m unittest discover boa_test

[E 180919 14:03:31 ExecutionEngine:947] COULD NOT EXECUTE OP (63): negative shift count b'\x98' SHL
[E 180919 14:03:31 ExecutionEngine:948] negative shift count
    Traceback (most recent call last):
      File "/Users/jonathan/.pyenv/versions/3.6.6/envs/venv-neo-boa/lib/python3.6/site-packages/neo/VM/ExecutionEngine.py", line 939, in StepInto
        self.ExecuteOp(op, self.CurrentContext)
      File "/Users/jonathan/.pyenv/versions/3.6.6/envs/venv-neo-boa/lib/python3.6/site-packages/neo/VM/ExecutionEngine.py", line 485, in ExecuteOp
        estack.PushT(x << n)
    ValueError: negative shift count
[I 180919 14:03:31 Invoke:586] Used 0.049 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.049 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.053 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.053 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.057 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.057 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.061 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.063 Gas 
[I 180919 14:03:31 Invoke:586] Used 0.063 Gas 
.[I 180919 14:03:40 LevelDBBlockchain:114] Created Blockchain DB at /Users/jonathan/.neopython/fixtures/test_chain 

GetCallingScriptHash from module returns incorrect value

When using GetCallingScriptHash along with RegisterAppCall or DynamicAppCall, I expected to get the hash of the contract which called the contract with GetCallingScriptHash in all cases, but it seems that when GetCallingScriptHash is used in a file that is separate from the root file that contains the Main method, it is returning the hash of itself rather that the hash of the contract that invoked it.

I have created the following example code to demonstrate this issue:
https://github.com/nickfujita/neo-examples/tree/master/smartContracts/callerHash

  • Contract B will be invoked, and will call Contract A
  • Contract A prints 2 things:
    • Return value of GetCallingScriptHash when called from the Main method
    • Return value of GetCallingScriptHash when called from the printTest method, located at src/printCaller.py

Expected result:

  • Contract A will print the script hash of Contract B when calling GetCallingScriptHash from both the Main and printTest methods

Actual result:

  • Contract A prints the script hash of Contract B when calling GetCallingScriptHash from the Main method, but prints the script hash of Contract A when called from the printTest method

Please let me know if this issue should be moved to neo-python instead.

Compiler should convert binary string to byte array

As mentioned in CityOfZion/neo-python#438 I believe neo-boa needs some improvements, and there's an opportunity here.
Currently, both codes generate the same opcodes:

OWNER=b'031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a'
OWNER="031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a"

The opcode is: PUSHBYTES66 303331613663366662626466303263613335313734356661383662396261356139343532643738356163346637666332623735343863613261343663346663663461 ### "031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a"

In other words, it assumes the input is a string composed of ascii chars. It would be nice if the binary input was treated like: OWNER=b'\x03\x1alo\xbb\xdf\x02\xca5\x17E\xfa\x86\xb9\xbaZ\x94R\xd7\x85\xacO\x7f\xc2\xb7T\x8c\xa2\xa4lO\xcfJ'
(which is the output of binascii.unhexlify(OWNER), if OWNER is binary string)

I don't know if this information is available (binary string vs pure string) for byteplay, etc, but this is possibly a transparent solution for the user.

Convert byte array to number ?

Hi,
I used function GetHeight from package from boa.interop.Neo.Blockchain
The lasted block height on my private net is 10541 and this is what I get when run this function bytearray(b',)')
I googled for a while but don't find any code to convert bytearray(b',)') = 10541
Please help !

Inconsistent representation of zero

There's an inconsistency in how zero is represented depending on if you directly assign a variable the value zero vs calculating the value zero by math operations.

Example code below shows how delta = b'' and z = bytearray(b'\x00').

Also, this can be a problem if someone tries to store (Put) the value of delta, they will end up storing nothing. So when getting the value back using Get, since delta = b'', they will think delta doesn't exist in Storage.

def Main(operation, args):
    x = 1
    y = 1
    delta = x-y
    z = 0
    Log(delta)
    Log(z)

    delta_len = len(delta)
    z_len = len(z)
    Log(delta_len)
    Log(z_len)

Log:

...[a7ec498ddf57795336bb3c8843ca36d9ec96f772] [b'']  # delta
...[a7ec498ddf57795336bb3c8843ca36d9ec96f772] [bytearray(b'\x00')]  # z
...[a7ec498ddf57795336bb3c8843ca36d9ec96f772] [b'']  # delta_len
...[a7ec498ddf57795336bb3c8843ca36d9ec96f772] [b'\x01']  # z_len

Using Inputs.GetHash and Transaction.GetHash in the same contract

I was having quite a difficult time using Input.GetHash and Transaction.GetHash in the same contract. I ended up doing the following trick to get the compiler to allow me to.

@@ -697,6 +697,9 @@ class VMTokenizer(object):
             if fname == m.name:
                 full_name = m.full_name
 
+        if fname == 'InputGetHash':
+            full_name = 'boa.blockchain.vm.Neo.Input.GetHash'
+
         # operational call like len(items) or abs(value)
         if self.is_op_call(fname):
             vmtoken = self.convert_op_call(fname, pytoken)

Then in my contract I have a dummy function called InputGetHash.

Before doing this I tried everything including separating the calls into separate files. Any clues or is this a bug?

Invoking Neo.Contract.IsPayable fails

I ran

my_hash = GetExecutingScriptHash()
Notify(my_hash.IsPayable)

and consistently received a warning message:
[W 181004 11:17:07 InteropService:537] method Neo.Contract.GetIsPayable not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.