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

Fail to unmarshal tx data from a block #14

Open
Caveman07 opened this issue Apr 6, 2020 · 10 comments
Open

Fail to unmarshal tx data from a block #14

Caveman07 opened this issue Apr 6, 2020 · 10 comments

Comments

@Caveman07
Copy link

Using:
[email protected]
@tendermint/[email protected]
@tendermint/[email protected]

Trying to decode tx from block with:


import { decodeString, unmarshalTx } from '@tendermint/amino-js';
import { base64ToBytes } from '@tendermint/belt'; 

  decodeTx(txHash) {
    try {
      const decoded = base64ToBytes(txHash); 
      const unmarshaled = unmarshalTx(decoded);
      return decoded
    }
    catch (error) {
      console.log(error)
      return null
    }
  }

Throws this error on every tx data string from blocks:
For example:

3wEoKBapCluclZNGChRm0QXKCIrFakuLzpL0oqW3MHzH/RIUyTRRx8hJmGRpUL1G+yw8xXQRSHsaFE3H7L64W8UP7sICyw32yIwMNrM6IhMKBXVhdG9tEgoyMDQ5ODQ5MTQwEhAKCgoFdWF0b20SATEQgNMOGmoKJuta6YchAzpqNiIl4AIZl3rIYeUHLU10NyCNiEapGx3SKZ338sTwEkDgs/cND/XjaiNySQxrLQRGbgaLqhyyjozvYozBqvmAiEVxiG5W63DzhGm8UeMxXDh3zemjyMfkZB0XAGqcjs8V

at block 1416024

Error: unmarshal to types.Tx failed after 4 bytes (unrecognized prefix bytes 282816A9): 282816A90A5B9C9593460A1466D105C.....6A9C8ECF15
@jordaaash
Copy link
Contributor

Thanks for the report! Can you show me how you're getting the base64 data?

@Caveman07
Copy link
Author

Thanks for the report! Can you show me how you're getting the base64 data?

by fetching block data from any lcd REST server
Example: GET request to https://api.cosmos.network/blocks/{block_height}

then I get tx_data from block["block]["data"]["txs"]

@cryptophonic
Copy link

can confirm this is happening for Microtick as well on the hub-3-gaia-2-alpha branch, hub-3-gaia-2, and extend branches

@cryptophonic
Copy link

const { marshalTx, unmarshalTx } = require('./node.js')

const obj = {
   'type':  'cosmos-sdk/StdTx',
   'value': {
       'msg':        [{
           'type':  'cosmos-sdk/MsgSend',
           'value': {
               'from_address': 'cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r',
               'to_address':   'cosmos1z7g5w84ynmjyg0kqpahdjqpj7yq34v3suckp0e',
               'amount':       [{
                   'denom':  'uatom',
                   'amount': '11657995'
               }]
           }
       }],
       'fee':        {
           'amount': [{
               'denom':  'uatom',
               'amount': '5000'
           }],
           'gas':    '200000'
       },
       'signatures': [{
           'pub_key':   {
               'type':  'tendermint/PubKeySecp256k1',
               'value': 'AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP'
           },
           'signature': '1nUcIH0CLT0/nQ0mBTDrT6kMG20NY/PsH7P2gc4bpYNGLEYjBmdWevXUJouSE/9A/60QG9cYeqyTe5kFDeIPxQ=='
       }],
       'memo':       '1122672754'
   }
};

const m = marshalTx(obj)
console.log("bytes=" + JSON.stringify(m))

const u = unmarshalTx(m)
console.log(JSON.stringify(u, null, 2))

Error: unmarshal to types.Tx failed after 102 bytes (error reading array contents: expected field number: 1; got: 4): 282816A90A43A8A3619A0A14B9DFAC7AD79B372F91CD1D9A8B2983E908ADED8912141791471EA49EE4443EC00F6ED90032F1011AB2301A110A057561746F6D1208313136353739393512130A0D0A057561746F6D12043530303010C09A0C1A6A0A26EB5AE9872102D41A0AA167B21699429EAB224BC03F2CD386F0AF5D20CEFBD0336F1544AEA24F1240D6751C207D022D3D3F9D0D260530EB4FA90C1B6D0D63F3EC1FB3F681CE1BA583462C46230667567AF5D4268B9213FF40FFAD101BD7187AAC937B99050DE20FC5220A31313232363732373534
at $callDeferred (/home/mjackson/cosmos/amino-js/go/src/github.com/cosmos/amino-js/dist/node.js:1544:17)
at $panic (/home/mjackson/cosmos/amino-js/go/src/github.com/cosmos/amino-js/dist/node.js:1583:3)
at DecodeTx (/home/mjackson/cosmos/amino-js/go/src/github.com/cosmos/amino-js/dist/node.js:69725:4)
at Module.v.$externalizeWrapper (/home/mjackson/cosmos/amino-js/go/src/github.com/cosmos/amino-js/dist/node.js:1996:22)
at unmarshalTx (/home/mjackson/cosmos/amino-js/go/src/github.com/cosmos/amino-js/dist/node.js:77090:66)

@cryptophonic
Copy link

also happens if we call marshal, unmarshal with 'false' as the second parameter for length prefixed encoding

@cryptophonic
Copy link

I've tracked this issue down to the pub_key field for a Secp256k1 signature. In the JSON example above if you omit the following, it works.

           'pub_key':  {
               'type':  'tendermint/PubKeySecp256k1',
               'value': 'AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP'
           }

Specifically, it appears to be having trouble with the base64 byte array in the pub_key.value. I don't have a good idea why yet.

@dangquan-quoine
Copy link

I have the same issue, when i parse the transaction D11E6BD640D9B5F1A5C5C39E03C75CFAD519CD45FE415D082A79421D9483C8B9 in block 1861036 with raw: iBgoKBapCv8WtC1hTgrQFuaBeAcKMUNvc21XYXNtIEludGVncmF0aW9uIDEgLSBQZXJtaXNzaW9ucyBhbmQgVXBncmFkZXMS6hVDb3NtV2FzbSBJbnRlZ3JhdGlvbiAxIC0gUGVybWlzc2lvbnMgYW5kIFVwZ3JhZGVzCgpDb21tdW5pdHktc3BlbmQgcHJvcG9zYWwgc3VibWl0dGVkIGJ5IEV0aGFuIEZyZXkgKGh0dHBzOi8vZ2l0aHViLmNvbS9ldGhhbmZyZXkpIG9mIENvbmZpbyBVTyAoaHR0cDovL2NvbmZpby50ZWNoLykgYW5kIENvc21XYXNtIChodHRwczovL3d3dy5jb3Ntd2FzbS5jb20pCgotPS09LQoKRnVsbCBwcm9wb3NhbDogaHR0cHM6Ly9pcGZzLmlvL2lwZnMvUW1iRDNiTWFqUUNGbXREbWt1UlZXaG1NV1ZkTjJzSzhRUDJGb0ZDejljalBpQwpGb3J1bSBQb3N0OiBodHRwczovL2ZvcnVtLmNvc21vcy5uZXR3b3JrL3QvcHJvcG9zYWwtY29zbX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zbXdhc20uY29tCkdpdGh1YjogaHR0cHM6Ly9naXRodWIuY29tL0Nvc21XYXNtGhQkTeB7yuHgqmKCZktSpv2Y7s2ufCIUCgV1YXRvbRILMjUwMDAwMDAwMDASEAoFdWF0b20SBzEwMDAwMDAaFNLeTkR7r4sZBGNww1wp6GKnFM8jEhQKDgoFdWF0b20SBTc1MDAwEKDCHhpqCibrWumHIQPV9nf5JdcbunAdCyEux+ZHFqRY1VezQ7CoWte2jIpzBxJAb6fNnsKfFqxNwZJwzrMDfdDLxxh4I7jlIIK/p5TCjUceB1UhhZbNq3NPRkkC1ojv5F27qru/7wBgHbzJOCxMIQ==. it doesn't work, i can see it on https://hubble.figment.network/cosmos/chains/cosmoshub-3/blocks/1861036/transactions/D11E6BD640D9B5F1A5C5C39E03C75CFAD519CD45FE415D082A79421D9483C8B9?format=json.

@cryptophonic
Copy link

I made some progress on this. the old pub_key format no longer works. instead, the pubkey is a base64 encoded value of the following format:

0xEB5AE987 + 0x21 + pubkey bytes

The first two values are amino headers discussed here: https://docs.tendermint.com/master/spec/blockchain/encoding.html

Once I made this change I was able to successfully sign Tx's and decode transactions as well.

@cetgames
Copy link

Is there a work around regarding this issue? I think I'm seeing similar issue...

@ysfaran
Copy link

ysfaran commented Nov 6, 2021

Any update on this?

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

No branches or pull requests

6 participants