neo: JSON-RPC NEP-5 invokefunction calls returning incorrect results

There is an issue with every single JSON-RPC node (seedX.neo.org, seedX.cityofzion.io, seed8.antshares.org) that is resulting in out-of-date values being returned by invokescript and invokefunction calls.

I believe this to be the cause of the myriad of NEP-5 token complaints on https://github.com/CityOfZion/neon-wallet about balances not showing.

I’ve confirmed this issue exists for, at a minimum, totalSupply and balanceOf NEP-5 functions.

Here’s the simplest example:

{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","totalSupply",[]],"id":1234}

cURL:

curl -H 'Content-Type: application/json' -v -d '{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","totalSupply",[]],"id":1234}' http://seed2.neo.org:10332

This returns:

{"jsonrpc":"2.0","id":1234,"result":{"state":"HALT, BREAK","gas_consumed":"0.628","stack":[{"type":"ByteArray","value":"00c0a9a4aa8b01"}]}}

That hex value (00c0a9a4aa8b01) corresponds to 435040000000000. This is not the correct value for totalSupply, however. In reality, the totalSupply is 1233800000000000, as evidenced by neo-python:

neo> testinvoke 2e25d2127e0240c6deaf35394702feb236d4d7fc totalSupply []
[test_mode][SmartContract.Execution.Success] [2e25d2127e0240c6deaf35394702feb236d4d7fc] [b'\x00P\xb9r"b\x04']
Results ['ByteArray: bytearray(b\'\\x00P\\xb9r"b\\x04\')']

Here’s one example of balanceOf that is actually working:

{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","balanceOf",[{"type":"Hash160","value":"d450b6c2d3f1ff1dff00307dceab009d1f5115e0"}]],"id":1234}

cURL:

curl -H 'Content-Type: application/json' -v -d '{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","balanceOf",[{"type":"Hash160","value":"d450b6c2d3f1ff1dff00307dceab009d1f5115e0"}]],"id":1234}' http://seed2.cityofzion.io:8080

That returns the proper value:

{"jsonrpc":"2.0","id":1234,"result":{"script":"14e015511f9d00abce7d3000ff1dfff1d3c2b650d451c10962616c616e63654f6667fcd7d436b2fe02473935afdec640027e12d2252e","state":"HALT, BREAK","gas_consumed":"0.675","stack":[{"type":"ByteArray","value":"00805fad236d"}]}}

But here is one that does not:

{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","balanceOf",[{"type":"Hash160","value":"e57d3afa4d95af5186121099fb5b55b7366aa8af"}]],"id":1234}

cURL:

curl -H 'Content-Type: application/json' -v -d '{"jsonrpc":"2.0","method":"invokefunction","params":["2e25d2127e0240c6deaf35394702feb236d4d7fc","balanceOf",[{"type":"Hash160","value":"e57d3afa4d95af5186121099fb5b55b7366aa8af"}]],"id":1234}' http://seed2.cityofzion.io:8080

That returns a balance of zero:

{"jsonrpc":"2.0","id":1234,"result":{"script":"14afa86a36b7555bfb9910128651af954dfa3a7de551c10962616c616e63654f6667fcd7d436b2fe02473935afdec640027e12d2252e","state":"HALT, BREAK","gas_consumed":"0.675","stack":[{"type":"ByteArray","value":""}]}}

but the actual balance:

neo> testinvoke 2e25d2127e0240c6deaf35394702feb236d4d7fc balanceOf ['AXnfejvXc7zoWD7reJ8hB3QUQd7jeCpLn1']
[test_mode][SmartContract.Execution.Success] [2e25d2127e0240c6deaf35394702feb236d4d7fc] [b'\x00\x00QJ\x8d\x0e']
Results ["ByteArray: bytearray(b'\\x00\\x00QJ\\x8d\\x0e')"]

which corresponds to a real value of 16000000000000.

Some NEP-5 tokens don’t seem to have this issue, but it does seem to affect quite a few ICOs based on the number of complaints in https://github.com/CityOfZion/neon-wallet.

Is there something in the JSON-RPC node implementation that results in the queried data potentially being out of date? The one address that balanceOf is returning properly for happens to be the first ICO contribution, so I don’t know if that has anything to do with it.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 37 (13 by maintainers)

Most upvoted comments

Application log for tx 01f992be33dcc8ebe1dd51058a2b8f511c9088a8d541a72c829382600c736640:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "txid": "0x01f992be33dcc8ebe1dd51058a2b8f511c9088a8d541a72c829382600c736640",
    "vmstate": "FAULT, BREAK",
    "gas_consumed": "10.177",
    "stack": [
      {
        "type": "Integer",
        "value": "1"
      },
      {
        "type": "ByteArray",
        "value": "6b79635f6f6bace575f6847bc025bb30d752d73892bbb875e8d2"
      },
      { "type": "InteropInterface" }
    ],
    "notifications": [
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "5c2721a33bf665880fb2c1c0d504d92dcfe1616f"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "03a8b007549dd4d19f367d6b71ed5c6fe9aa8272"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "98d3602f1e4f5ba179481398e55593862a0df92c"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "62b9d04e2d8b2a989d72c3c9478c18f2ef714cf2"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "c2c1bac70b182dbf8434323013c72d66c57591d8"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "49b197c38b07107c7ac4097ba47c1c9c39a04409"
            }
          ]
        }
      },
      {
        "contract": "0x2e25d2127e0240c6deaf35394702feb236d4d7fc",
        "state": {
          "type": "Array",
          "value": [
            {
              "type": "ByteArray",
              "value": "6b79635f726567697374726174696f6e"
            },
            {
              "type": "ByteArray",
              "value": "dbfae7df8d49ad1319079604318ba12252ace7f1"
            }
          ]
        }
      }
    ]
  }
}

@erikzhang

It returns false because a previous transaction for kyc_register failed, so the tokens were never minted properly. That previous transaction failed because of a GAS issue.

2e25d2127e0240c6deaf35394702feb236d4d7fc.log I’ve uploaded the log of all storage operations of NRV. Please check it.

I’m replaying all the NRV transactions locally to see how their execution is different from the python nodes. Can someone give me the logs of all the NRV transactions that executed on python node?