Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmJS cannot parse Tx results in v0.46: Invalid string. Length must be a multiple of 4 #11997

Closed
4 tasks
nooomski opened this issue May 19, 2022 · 16 comments
Closed
4 tasks
Assignees
Labels

Comments

@nooomski
Copy link
Contributor

Summary of Bug

The response of any Tx cannot be parsed by CosmJS in v0.46.0-beta2. This worked fine in v0.45.x and below. Not sure if this is a bug or due to a breaking change.

After signing and broadcasting the following Tx using CosmJS:

const result = await signingClient.sendTokens(
        alice,
        bob,
        [{ denom: "stake", amount: "100000" }],
        {
            amount: [{ denom: "stake", amount: "500" }],
            gas: "200000",
        },
    )

The result throws an error after the Tx has successfully executed:

/Users/noam/Code/cosmjs-sandbox/node_modules/base64-js/index.js:26
    throw new Error('Invalid string. Length must be a multiple of 4')
          ^
Error: Invalid string. Length must be a multiple of 4
    at getLens (/Users/noam/Code/cosmjs-sandbox/node_modules/base64-js/index.js:26:11)
    at Object.toByteArray (/Users/noam/Code/cosmjs-sandbox/node_modules/base64-js/index.js:55:14)
    at fromBase64 (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/encoding/src/base64.ts:11:19)
    at decodeAttribute (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:103:20)
    at Array.map (<anonymous>)
    at decodeAttributes (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:109:34)
    at decodeEvent (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:120:17)
    at Array.map (<anonymous>)
    at decodeEvents (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:125:30)
    at decodeTxData (/Users/noam/Code/cosmjs-sandbox/node_modules/@cosmjs/tendermint-rpc/src/tendermint34/adaptor/responses.ts:145:27)

Version

v0.46.0-beta2

Steps to Reproduce

Get a response from any Tx using CosmJS. You can clone this repo and `npm run experiment-local to try it out for yourself.


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@nooomski nooomski added the T:Bug label May 19, 2022
@julienrbrt julienrbrt self-assigned this May 20, 2022
@julienrbrt
Copy link
Member

julienrbrt commented May 23, 2022

It fails because it uses a tendermint 0.34 client and the sdk uses a tendermint 0.35 since 0.46.
Tendermint's changelog shows a few breaking changes.

The relevant one here is the change in the EventAttribute type in tendermint.

tendermint/tendermint#6408
https://github.com/cosmos/cosmjs/blob/main/packages/tendermint-rpc/src/tendermint34/adaptor/responses.ts#L101

When cosmjs has upgraded its implementation, we can see if it still happens.

@webmaster128

@julienrbrt julienrbrt added S:blocked Status: Blocked and removed S:blocked Status: Blocked labels May 23, 2022
@julienrbrt
Copy link
Member

Closing for now. Let's see if it happens again when cosmjs is up-to-date.

@nooomski
Copy link
Contributor Author

Thanks @julienrbrt !!

@webmaster128
Copy link
Member

Thanks for the ping and checking this issue. See cosmos/cosmjs#1154 (comment) for the state of things in CosmJS.

@julienrbrt
Copy link
Member

julienrbrt commented Dec 18, 2022

Hey @webmaster128, I am getting this when using v0.47 (TM v0.37). Is there a TM v0.37 client coming?

@webmaster128
Copy link
Member

Hey @julienrbrt, so far I am not aware of any Tendermint change. We have a working TM 0.34 client and a private unused TM 0.35 client. Could you open a ticket in CosmJS, please?

@julienrbrt
Copy link
Member

Hey @julienrbrt, so far I am not aware of any Tendermint change. We have a working TM 0.34 client and a private unused TM 0.35 client. Could you open a ticket in CosmJS, please?

Sure, opened cosmos/cosmjs#1353!

@triccs
Copy link

triccs commented Dec 22, 2023

I'm trying to update the package to fix this issue since Osmosis upgraded to the 0.47 SDK but I can't get it to work without additional errors. When switching to 0.32.2 I get RPC can't connect errors & when switching to 0.31.3 I get nest node_modules that create cascading errors.
image
image

@daniel-farina
Copy link

Same here when using web3auth and Osmosis. the transaction goes through but the result is invalid. I'm trying to figure out how to replicate this in a simple example.

This happens only when using web3auth, it works fine when signing with Keplr but the message is exactly the same. I'll see what else i can find :/

@triccs
Copy link

triccs commented Jan 1, 2024 via email

@daniel-farina
Copy link

I ended up upgrading again and it worked fine for me, not sure what the intermittent nested node_module errors were but they are gone. Edit: Some people are reporting they are still getting the string error post-upgrades.

very interesting, seems intermittent on my end too.

Error was gone yesterday after removing node_modules and reinstalling but the issues started to occur again today. Now I'm suspecting the rpc node is returning different responses. I'll start logging them.

app-index.js:32 Mint operation failed: Error: Invalid string. Length must be a multiple of 4
    at getLens (index.js:26:1)
    at Object.toByteArray (index.js:55:1)
    at fromBase64 (base64.js:36:1)
    at decodeAttribute (responses.js:45:1)
    at Array.map (<anonymous>)
    at decodeAttributes (responses.js:50:1)
    at decodeEvent (responses.js:55:1)
    at Array.map (<anonymous>)
    at decodeEvents (responses.js:60:1)
    at decodeTxData (responses.js:69:1)
    at decodeTxResponse (responses.js:319:1)
    at Array.map (<anonymous>)
    at decodeTxSearch (responses.js:329:1)
    at decodeTxSearch (responses.js:437:1)
    at Tendermint34Client.doCall (tendermint34client.js:310:1)
    at async Tendermint34Client.txSearchAll (tendermint34client.js:257:1)
    at async SigningCosmWasmClient.txsQuery (cosmwasmclient.js:321:1)
    at async SigningCosmWasmClient.getTx (cosmwasmclient.js:99:1)
    at async pollForTx (cosmwasmclient.js:162:1)

@daniel-farina
Copy link

daniel-farina commented Jan 2, 2024

This payload when executing a message with using @cosmos-kit/keplr works:

{"jsonrpc":"2.0","id":369391345853,"method":"broadcast_tx_sync","params":{"tx":"Cs0BCsEBCiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSmAEKK29zbW8xenByZjJ0aDVtMDNmNG1wbndlcWtmcXgybTB2aG1oNjdrNnF0NHYSP29zbW8xd2NycGEzaDdmcmF1MGc0emRtdG10Z2x2aG50M2hybHM0YWVhdzR5Y21lajVwbXQ5YWFzczc3MjR1cBoXeyJtaW50Ijp7ImFtb3VudCI6IjEifX0qDwoFdW9zbW8SBjQwNDAwMBIHd2F0Y2htZRJoClEKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECKfUL+gse+bID4d5TpDcjZQciuskPhSkdfRFA0cWxAycSBAoCCH8YgQMSEwoNCgV1b3NtbxIENjM2MRDSww8aQCOznSlV0QGPuxxquoscQCJvytaqe/LGeMxlyjlaTNxERAlYfnFN7S1CnpvEWCPjxzE/3nlTyQnebqkTcxxQRKk="}}

Base64 decoded looks like:

$/cosmwasm.wasm.v1.MsgExecuteContract��
+osmo1zprf2th5m03f4mpnweqkfqx2m0vhmh67k6qt4v�?osmo1wcrpa3h7frau0g4zdmtmtglvhnt3hrls4aeaw4ycmej5pmt9aass7724up��{"mint":{"amount":"1"}}*�
�uosmo��404000��watchme�h
Q
F
�/cosmos.crypto.secp256k1.PubKey�#
!�)����S7#e�"�)�}�@ű�'��
�������

�uosmo��6361���@#)U��j�@"o֪{xe9ZLDD	X~qM-BX#1?yS	n�s�PD

This does not work using cosmos-kit-web3auth

{"jsonrpc":"2.0","id":682581239289,"method":"broadcast_tx_sync","params":{"tx":"Cs0BCsEBCiQvY29zbXdhc20ud2FzbS52MS5Nc2dFeGVjdXRlQ29udHJhY3QSmAEKK29zbW8xbWY5Z3JzdGg0cG5kYW56aHg2bnp5MHNnZXNxN3Rkbmd4cmE3ZmYSP29zbW8xd2NycGEzaDdmcmF1MGc0emRtdG10Z2x2aG50M2hybHM0YWVhdzR5Y21lajVwbXQ5YWFzczc3MjR1cBoXeyJtaW50Ijp7ImFtb3VudCI6IjEifX0qDwoFdW9zbW8SBjQwNDAwMBIHd2F0Y2htZRJoClAKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiECPhaaoTVeqt0GDdIGhe9BfjdVtiaJYorRzKs8RTu+RvASBAoCCAEYOBIUCg4KBXVvc21vEgUxMTgwMBDasw4aQAhKhJiMRyXMtYRxS8mCRAPlmtxOnmZXKj7OmThynId4Qrasmv12wx5G4woOJm1+rYPCTItmVHRh0YWzqwnJ7Bo="}}

base64 decoded


�
�
$/cosmwasm.wasm.v1.MsgExecuteContract��
+osmo1mf9grsth4pndanzhx6nzy0sgesq7tdngxra7ff�?osmo1wcrpa3h7frau0g4zdmtmtglvhnt3hrls4aeaw4ycmej5pmt9aass7724up��{"mint":{"amount":"1"}}*�
�uosmo��404000��watchme�h
P
F
�/cosmos.crypto.secp256k1.PubKey�#
!�>�5^�
�A~7U&b̫<E;F��
����8��
�
�uosmo��11800�ڳ��@�JG%̵qKɂD�NfW*>Ι8rxBv�F
�&m~LfTtaх	�

It's looks a bit different at the end, but I'm having a hard debugging locally. I've been trying to update all dependencies of packages locally but no luck.
so I guess it's something wrong with the web3auth on cosmos-kit. I'll keep on looking for now.

@julienrbrt
Copy link
Member

Hi, you will have more luck posting your issue in the cosmjs repo or https://github.com/orgs/cosmos/discussions

@Srivastava57Harsh
Copy link

Hey there
am facing the same issue and this is my package.json and the error am facing

# package.json

  "dependencies": {
    "@cosmjs/launchpad": "^0.27.1",
    "@cosmos-kit/keplr": "^2.6.9",
    "@cosmos-kit/react": "^2.10.11",
    "@interchain-ui/react": "^1.22.1",
    "@nibiruchain/nibijs": "^3.3.2",
    "chain-registry": "^1.29.1",
    "cosmos-kit": "^2.9.4",
    "cosmwasm": "^1.1.1",
    "next": "14.1.0",
  },

  
# Error: 
 
 
  Error increasing allowance: Error: Invalid string. Length must be a multiple of 4
    at getLens (index.js:20:15)
    at Object.toByteArray (index.js:44:16)
    at fromBase64 (base64.js:44:21)
    at decodeAttribute (responses.js:41:40)
    at Array.map (<anonymous>)
    at decodeAttributes (responses.js:46:53)
    at decodeEvent (responses.js:51:40)
    at Array.map (<anonymous>)
    at decodeEvents (responses.js:56:49)
    at decodeTxData (responses.js:64:31)
    at decodeTxResponse (responses.js:311:17)
    at Array.map (<anonymous>)
    at decodeTxSearch (responses.js:321:53)
    at decodeTxSearch (responses.js:429:16)
    at Tendermint34Client.doCall (tendermint34client.js:352:16)
    at async Tendermint34Client.txSearchAll (tendermint34client.js:298:26)
    at async SigningCosmWasmClient.txsQuery (cosmwasmclient.js:298:25)
    at async SigningCosmWasmClient.getTx (cosmwasmclient.js:91:25)
    at async pollForTx (cosmwasmclient.js:152:28)

@webmaster128
Copy link
Member

Both cosmwasm and @cosmjs/launchpad are not maintained anymore. They use a Tendemint 0.34 client but for the encoding change you need a Tendermint 0.37 client. More recent versions of CosmJS do auto-detection to get you the right one.

@ManoharGajangi-1037
Copy link

May I know what are the required changes made you people to solve the issue and getting the response properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

7 participants