cairo-lang icon indicating copy to clipboard operation
cairo-lang copied to clipboard

invoke CLI command does not work with OpenZeppelin's 0.10.0 Account contract

Open yoga-braavos opened this issue 3 years ago • 2 comments

Setup:

  1. Have an Open Zeppelin v0.10 account contract with some goerli-ETH in it deployed on alpha-goerli network
  2. Install latest cairo-lang (==0.10.0)
  3. Setup the account from (1) for CLI usage (add it to ~/.starknet_accounts/starknet_open_zeppelin_accounts.json)

BUG 🐞: Calls to starknet invoke asserts on Error message: Account: invalid tx version. For example, here's an ERC20 transfer failure: starknet --account oz_010_test invoke --address 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 --abi artifacts/abis/ERC20.json --function transfer --inputs <recipient> 5000000 0

File "cairo-contracts/venv/lib/python3.9/site-packages/services/external_api/client.py", line 117, in _send_request raise BadRequest(status_code=response.status, text=text) services.external_api.client.BadRequest: HTTP error ocurred. Status: 500. Text: {"code": "StarknetErrorCode.TRANSACTION_FAILED", "message": "Error message: Account: invalid tx versionError at pc=0:185: An ASSERT_EQ instruction failed: 1 != 340282366920938463463374607431768211457.Cairo traceback (most recent call last): Unknown location (pc=0:608) Unknown location (pc=0:554)"} Error: BadRequest: HTTP error ocurred. Status: 500. Text: {"code": "StarknetErrorCode.TRANSACTION_FAILED", "message": "Error message: Account: invalid tx version Error at pc=0:185: An ASSERT_EQ instruction failed: 1 != 340282366920938463463374607431768211457. Cairo traceback (most recent call last): Unknown location (pc=0:608) Unknown location (pc=0:554)"}

Root cause analysis:

  1. invoke() at src/starkware/starknet/cli/starknet_cli.py is triggered from starknet invoke CLI command
  2. compute_max_fee is called with invoke_tx_for_simulate
  3. invoke_tx_for_simulate is created with create_invoke_tx with query=True
  4. create_invoke_tx with query=True sets the version field as follows: version = constants.QUERY_VERSION if query else constants.TRANSACTION_VERSION where: QUERY_VERSION = QUERY_VERSION_BASE + TRANSACTION_VERSION == 340282366920938463463374607431768211457
  5. OZ account asserts on tx_info.version=1 causing the assertion above
  6. NOTE: The Account contract bundled in cairo-lang asserts on the version differently as follows: assert_not_equal(tx_info.version, 0);

yoga-braavos avatar Sep 21 '22 07:09 yoga-braavos

Which version of OZ did you use to get this? Isn't this an OpenZeppelin issue (already reported here and soon to be resolved: https://github.com/OpenZeppelin/cairo-contracts/issues/471)

FabijanC avatar Oct 12 '22 07:10 FabijanC

Which version of OZ did you use to get this? Isn't this an OpenZeppelin issue (already reported here and soon to be resolved: OpenZeppelin/cairo-contracts#471)

@FabijanC actually @martriay asked me to open this as a cairo-lang issue a while ago. In any case a fix on either side is great 👍

yoga-braavos avatar Oct 12 '22 08:10 yoga-braavos