Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

abi_json_to_bin for Action newaccount Returns Incorrect Value #5629

Closed
deckb opened this issue Sep 12, 2018 · 5 comments
Closed

abi_json_to_bin for Action newaccount Returns Incorrect Value #5629

deckb opened this issue Sep 12, 2018 · 5 comments
Assignees
Labels

Comments

@deckb
Copy link
Contributor

deckb commented Sep 12, 2018

The issue appears to only happen with the newaccount action. It can be reproduced using

import requests

url = "https://eos.greymass.com/v1/chain/abi_json_to_bin"

payload = {"code":"eosio","args": {'creator': 'eosio', 'name': 'testtesttest', 'owner': 'EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq', 'active': 'EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq'},"action":"newaccount"}
response = requests.request("POST", url, json=payload)

print(response.text)

The output from above

{"binargs":"0000000000ea305590b1ca19ab9cb1ca"}

The expected output via the cleos command

cleos system newaccount eosio testtesttest EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq --stake-net '1.0000 EOS' --stake-cpu '1.0000 EOS' --buy-ram-kbytes 8 --json -d

"actions": [{
      "account": "eosio",
      "name": "newaccount",
      "authorization": [{
          "actor": "eosio",
          "permission": "active"
        }
      ],
      "data": "0000000000ea305590b1ca19ab9cb1ca0100000001000255fe1065407389fb7289347759ad884f0b792291c91ebddde702aea8339f6bcf010000000100000001000255fe1065407389fb7289347759ad884f0b792291c91ebddde702aea8339f6bcf01000000"
    }

It looks like creator and name are correctly processed but the keys are not returned.

@ARoomWithABue
Copy link

ARoomWithABue commented Sep 12, 2018

I'm actually having the same issue. I'm also writing a python library for the RPC API. Creating an account is the first action that I tried to write.

Command that I ran:
cleos --url http://127.0.0.1:8888 system newaccount eosio --transfer testtesttest EOS6tz6NzPEoeHp7AfKP4SVYjQBgbxBJYSjBJD2PXjMWtc8FXgShV --stake-net "100.0000 EOS" --stake-cpu "100.0000 EOS" --buy-ram "100.0000 EOS"

Below are the http requests sent by cleos that I've captured in wireshark when the above command was ran. abi_json_to_bin isn't used to encode any of the actions for the above command.
screen shot 2018-09-12 at 10 57 27 am

My code is nearly identical to @deckb's in this instance. I've looked over the cleos system newaccount subcommand, is either push_action or push_transaction method manually encoding action arguments?

Below is the information returned from the RPC API when I run @deckb's or my code.

{"binargs":"0000000000ea305590b1ca19ab9cb1ca"}

Below is the information I scrapped from wireshark when running the above cleos command. The bin data is much larger.

{
  "account": "eosio",
  "name": "newaccount",
  "authorization": [
    {
      "actor": "eosio",
      "permission": "active"
    }
  ],
  "data": "0000000000ea3055302e8588c69328650100000001000219ae5dc5057eedcdfa1a80481d86c6fc0d82a277357ed2d0e28b28bba53b7122010000000100000001000219ae5dc5057eedcdfa1a80481d86c6fc0d82a277357ed2d0e28b28bba53b712201000000"
}

When executing @deckb's create action I receive the following exception from the RPC API.

{
  "code": 500,
  "message": "Internal Service Error",
  "error": {
    "code": 8,
    "name": "out_of_range_exception",
    "what": "Out of Range",
    "details": [
      {
        "message": "read datastream of length 16 over by 1",
        "file": "datastream.cpp",
        "line_number": 6,
        "method": "throw_datastream_range_error"
      },
      {
        "message": "error unpacking uint32_t",
        "file": "raw.hpp",
        "line_number": 616,
        "method": "unpack"
      },
      {
        "message": "Error unpacking field threshold",
        "file": "raw.hpp",
        "line_number": 368,
        "method": "operator()"
      },
      {
        "message": "error unpacking eosio::chain::authority",
        "file": "raw.hpp",
        "line_number": 616,
        "method": "unpack"
      },
      {
        "message": "Error unpacking field owner",
        "file": "raw.hpp",
        "line_number": 368,
        "method": "operator()"
      },
      {
        "message": "error unpacking eosio::chain::newaccount",
        "file": "raw.hpp",
        "line_number": 616,
        "method": "unpack"
      },
      {
        "message": "error unpacking eosio::chain::newaccount",
        "file": "raw.hpp",
        "line_number": 660,
        "method": "unpack"
      },
      {
        "message": "pending console output: ",
        "file": "apply_context.cpp",
        "line_number": 61,
        "method": "exec_one"
      }
    ]
  }
}

I also checked the bin data returned by cleos convert pack_action_data, see the below cleos command:

cleos convert pack_action_data eosio newaccount '{"creator": "eosio", "name": "testtesttest", "owner": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb", "active": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb"}'

This is the bin data returned by the above command:
0000000000ea305590b1ca19ab9cb1ca

As you can see from the below output that characters 1-16 and 17-32 are the creator and name arguments respectively as seen in the eosio.system abi. It appears that the owner and active arguments are not being packed in either the cleos convert pack_action_data command, or the abi_json_to_bin RPC endpoint. It seems like they may be using the same algorithm.

cleos convert pack_action_data eosio newaccount '{"creator": "eosio", "name": "testtesttest", "owner": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb", "active": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb"}'
0000000000ea305590b1ca19ab9cb1ca
cleos convert pack_action_data eosio newaccount '{"creator": "eosio", "name": "testtesttest", "owner": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb", "active": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb"}'
0000000000ea305590b1ca19ab9cb1ca
cleos convert pack_action_data eosio newaccount '{"creator": "blahblahblah", "name": "testtesttest", "owner": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb", "active": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb"}'
d04c3ccdc4d34c3c90b1ca19ab9cb1ca
cleos convert pack_action_data eosio newaccount '{"creator": "blahblahblah", "name": "barkbarkbark", "owner": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb", "active": "EOS8eDxLdfzrDknFVm7EH3pxKqJC9gXGanRFxNyErVHsBZWwpGmcb"}'
d04c3ccdc4d34c3c00af39f09a03af39

@ARoomWithABue
Copy link

ARoomWithABue commented Sep 12, 2018

I figured it out. If you look at the abi for the eosio.system contract it's expecting an eosio::chain::authority and not a public_key_type. I ran the following command on the bin data scrapped from the cleos commands. As you can see below the owner and active parameters have been populated with an authority type. I was able to successfully run my code when modeling my arguments in the same way.

teclos convert unpack_action_data eosio newaccount '0000000000ea3055302e8588c69328650100000001000219ae5dc5057eedcdfa1a80481d86c6fc0d82a277357ed2d0e28b28bba53b7122010000000100000001000219ae5dc5057eedcdfa1a80481d86c6fc0d82a277357ed2d0e28b28bba53b712201000000'
{
  "creator": "eosio",
  "name": "goodblockor3",
  "owner": {
    "threshold": 1,
    "keys": [{
        "key": "TLOS55oLsFKcv3EEcJfDK81CX7UrbL8T9zfuLZHMXoSJSXBpvX4kxd",
        "weight": 1
      }
    ],
    "accounts": [],
    "waits": []
  },
  "active": {
    "threshold": 1,
    "keys": [{
        "key": "TLOS55oLsFKcv3EEcJfDK81CX7UrbL8T9zfuLZHMXoSJSXBpvX4kxd",
        "weight": 1
      }
    ],
    "accounts": [],
    "waits": []
  }
}

Now i'm getting the correct output from abi_json_to_bin, but shouldn't I have received an exception when trying to pack a eosio::chain::newaccount struct without the appropriate type?

@deckb
Copy link
Contributor Author

deckb commented Sep 12, 2018

After correcting my python to use the Authority it worked but I agree with @ARoomWithABue that it should have failed when not given the correct data.

@tbfleming tbfleming added the bug label Sep 12, 2018
@taokayan
Copy link
Contributor

The correct command parameter should be something like:

curl --data-binary '{"code":"eosio","args": {"creator": "eosio", "name": "testtesttest", "owner":{"threshold":1,"keys":[{"key":"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq", "weight":1}], "accounts":[], "waits":[]}, "active":{"threshold":1,"keys":[{"key":"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq", "weight":1}], "accounts":[], "waits":[]}}, "action":"newaccount"}' http://localhost:8888/v1/chain/abi_json_to_bin

This is the output:

{"binargs":"0000000000ea305590b1ca19ab9cb1ca0100000001000255fe1065407389fb7289347759ad884f0b792291c91ebddde702aea8339f6bcf010000000100000001000255fe1065407389fb7289347759ad884f0b792291c91ebddde702aea8339f6bcf01000000"}

@arhag
Copy link
Contributor

arhag commented Sep 14, 2018

After correcting my python to use the Authority it worked but I agree with @ARoomWithABue that it should have failed when not given the correct data.

I agree. This bug and a few others in abi_serializer were fixed in PR #5680. I verified that running that python script against a local node with the changes in PR #5680 now correctly returns an error:

{
  "code": 500,
  "message": "Internal Service Error",
  "error": {
    "code": 3015014,
    "name": "pack_exception",
    "what": "Pack data exception",
    "details": [
      {
        "message": "Failed to serialize struct 'authority' in variant object",
        "file": "abi_serializer.cpp",
        "line_number": 407,
        "method": "_variant_to_binary"
      },
      {
        "message": "",
        "file": "abi_serializer.cpp",
        "line_number": 410,
        "method": "_variant_to_binary"
      },
      {
        "message": "",
        "file": "abi_serializer.cpp",
        "line_number": 410,
        "method": "_variant_to_binary"
      },
      {
        "message": "",
        "file": "abi_serializer.cpp",
        "line_number": 426,
        "method": "_variant_to_binary"
      },
      {
        "message": "'{\"creator\":\"eosio\",\"name\":\"testtesttest\",\"owner\":\"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq\",\"active\":\"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq\"}' is invalid args for action 'newaccount' code 'eosio'. expected '[{\"name\":\"creator\",\"type\":\"account_name\"},{\"name\":\"name\",\"type\":\"account_name\"},{\"name\":\"owner\",\"type\":\"authority\"},{\"name\":\"active\",\"type\":\"authority\"}]'",
        "file": "chain_plugin.cpp",
        "line_number": 1717,
        "method": "abi_json_to_bin"
      },
      {
        "message": "code: eosio, action: newaccount, args: {\"creator\":\"eosio\",\"name\":\"testtesttest\",\"owner\":\"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq\",\"active\":\"EOS5YMv2UBcuiExv1C8fZjjnE4evofRdBh5Nrt8TYz44G7KC5tZNq\"}",
        "file": "chain_plugin.cpp",
        "line_number": 1723,
        "method": "abi_json_to_bin"
      }
    ]
  }
}

@arhag arhag closed this as completed Sep 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants