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

Improper interpretation for big token amounts #1900

Closed
kushti opened this issue Nov 8, 2022 · 13 comments
Closed

Improper interpretation for big token amounts #1900

kushti opened this issue Nov 8, 2022 · 13 comments
Assignees
Labels
B-1000 SigUSD C-bug Category: This is a bug

Comments

@kushti
Copy link
Member

kushti commented Nov 8, 2022

Example:

{
  "tx" : {
    "id" : "5e8419ecae7adabfae9135149568c44ada7fa1c04edc5545dff1ab119959a43b",
    "inputs" : [
      {
        "boxId" : "0e9c050bfe7650d695f6354b48f1d1d5b915dcdfc48f6948c6cf86843ef25a0e",
        "extension" : {
          
        }
      },
      {
        "boxId" : "b908ffb2344b53956795ce8c599e2eb15711f8fa570aea48fe81b3461231a6c5",
        "extension" : {
          
        }
      },
      {
        "boxId" : "231fd3a0714a37dd131cab9e3b52d0fc5f9c21e775eef1788418e87e74efe17a",
        "extension" : {
          
        }
      }
    ],
    "dataInputs" : [
    ],
    "outputs" : [
      {
        "boxId" : "ef06793ee9ff928357939cc34113f1ee12b20df19796eee84a46f45e636fe217",
        "value" : 103038213932058,
        "ergoTree" : "1999030f0400040204020404040405feffffffffffffffff0105feffffffffffffffff01050004d00f040004000406050005000580dac409d819d601b2a5730000d602e4c6a70404d603db63087201d604db6308a7d605b27203730100d606b27204730200d607b27203730300d608b27204730400d6099973058c720602d60a999973068c7205027209d60bc17201d60cc1a7d60d99720b720cd60e91720d7307d60f8c720802d6107e720f06d6117e720d06d612998c720702720fd6137e720c06d6147308d6157e721206d6167e720a06d6177e720906d6189c72117217d6199c72157217d1ededededededed93c27201c2a793e4c672010404720293b27203730900b27204730a00938c7205018c720601938c7207018c72080193b17203730b9593720a730c95720e929c9c721072117e7202069c7ef07212069a9c72137e7214067e9c720d7e72020506929c9c721372157e7202069c7ef0720d069a9c72107e7214067e9c72127e7202050695ed720e917212730d907216a19d721872139d72197210ed9272189c721672139272199c7216721091720b730e",
        "assets" : [
          {
            "tokenId" : "9916d75132593c8b07fe18bd8d583bda1652eed7565cf41a4738ddd90fc992ec",
            "amount" : 1
          },
          {
            "tokenId" : "303f39026572bcb4060b51fafc93787a236bb243744babaa99fceb833d61e198",
            "amount" : 9223371997709984332
          },
          {
            "tokenId" : "03faf2cb329f2e90d6d23b58d91bbb6c046aa143261cc21f52fbe2824bfcbf04",
            "amount" : 20000488
          }
        ],
        "creationHeight" : 0,
        "additionalRegisters" : {
          "R4" : "04c60f"
        },
        "transactionId" : "5e8419ecae7adabfae9135149568c44ada7fa1c04edc5545dff1ab119959a43b",
        "index" : 0
      },
      {
        "boxId" : "3a5907febf1652be129c615cf72198bcdae9549753d7b0036ca48cd7b43c8e6b",
        "value" : 409430000,
        "ergoTree" : "10090402040005c801040205c8010500040004000e2003faf2cb329f2e90d6d23b58d91bbb6c046aa143261cc21f52fbe2824bfcbf04d807d601e4c6a70408d602b2a5730000d603e4c6a70601d604e4c6a7080ed605e4c6a70505d606e4c6a70705d60795720399c1a7c1720299c17202c1a7eb027201d1ededededededededed93c27202c2a793e4c672020408720193e4c6720205059572039d9c72057eb272047301000573029d9c72057eb2720473030005730494e4c672020601720393e4c672020705720693e4c67202080e720493e4c67202090ec5a7929c720672057207917207730595ef720393b1db630872027306d801d608b2db63087202730700ed938c7208017308938c7208027206",
        "assets" : [
          {
            "tokenId" : "03faf2cb329f2e90d6d23b58d91bbb6c046aa143261cc21f52fbe2824bfcbf04",
            "amount" : 100
          }
        ],
        "creationHeight" : 0,
        "additionalRegisters" : {
          "R4" : "08cd030c8f9c4dc08f3c006fa85a47c9156dedbede000a8b764c6e374fd097e873ba04",
          "R5" : "058caadf05",
          "R6" : "0100",
          "R7" : "05c801",
          "R8" : "0e026663",
          "R9" : "0e20b908ffb2344b53956795ce8c599e2eb15711f8fa570aea48fe81b3461231a6c5"
        },
        "transactionId" : "5e8419ecae7adabfae9135149568c44ada7fa1c04edc5545dff1ab119959a43b",
        "index" : 1
      },
      {
        "boxId" : "7b483b8ba0bdfc461f43d93388a6faebcb749346b4b32fc4e234f47ed76f1c9d",
        "value" : 10488000000,
        "ergoTree" : "0008cd030c8f9c4dc08f3c006fa85a47c9156dedbede000a8b764c6e374fd097e873ba04",
        "assets" : [
        ],
        "creationHeight" : 0,
        "additionalRegisters" : {
          
        },
        "transactionId" : "5e8419ecae7adabfae9135149568c44ada7fa1c04edc5545dff1ab119959a43b",
        "index" : 2
      },
      {
        "boxId" : "55a458e94dd46f2222070a6510a8359d880497407cf886baa3a705afbb6b5173",
        "value" : 1000000,
        "ergoTree" : "1005040004000e36100204a00b08cd0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ea02d192a39a8cc7a701730073011001020402d19683030193a38cc7b2a57300000193c2b2a57301007473027303830108cdeeac93b1a57304",
        "assets" : [
        ],
        "creationHeight" : 0,
        "additionalRegisters" : {
          
        },
        "transactionId" : "5e8419ecae7adabfae9135149568c44ada7fa1c04edc5545dff1ab119959a43b",
        "index" : 3
      }
    ]
  },
  "secrets" : {
    "dlog" : [
    ],
    "dht" : [
    ]
  },
  "hints" : {
    "secretHints" : {
      
    },
    "publicHints" : {
      
    }
  },
  "inputsRaw" : null,
  "dataInputsRaw" : null
}

Instead of 9223371997709984332 for asset 303f39026572bcb4060b51fafc93787a236bb243744babaa99fceb833d61e198 in the first output, parser returns another value. Seems like JSON big int issue like , see e.g. https://jsoneditoronline.org/indepth/parse/why-does-json-parse-corrupt-large-numbers/

@kushti kushti added C-bug Category: This is a bug B-1000 SigUSD labels Nov 8, 2022
@pragmaxim
Copy link
Collaborator

pragmaxim commented Nov 11, 2022

@kushti I'm not quite sure what am I supposed to do here, do we want to have lower Max limit for tokens so that it does not cause problems in Javascript ?

@kushti
Copy link
Member Author

kushti commented Nov 15, 2022

@pragmaxim No, we can not lower down limits.

If fixing JSON decoders not possible, maybe let decode accept number or string and change openapi.yaml description to suggest strings by default . Article above suggests to fix codecs

@pragmaxim
Copy link
Collaborator

pragmaxim commented Nov 18, 2022

@kushti Where does this happen? Sending tx? As we use Circe for ser/deser and it does not have this problem, I just tried having tokens with Long.MaxValue in TXs and ser/deser works fine.

@kushti
Copy link
Member Author

kushti commented Nov 18, 2022

@pragmaxim that was input for /wallet/transactions/sign, but I guess other methods using assets decoder have the same issue.

As a test, have you tried to send Long.MaxValue? Was exactly the same value sent ?

@pragmaxim
Copy link
Collaborator

pragmaxim commented Nov 19, 2022

@kushti I changed the Token generators in WalletApiRouteSpec."sign a transaction" to return always Long.MaxValue as asset value and the response is as expected, if you pass TX (as json string) with 9223372036854775807 it returns signed TX with 9223372036854775807 asset value :

        {
            "boxId" : "1cb00cae4d72aac60e17792a9abe41e781be8fb4b218ea6eb113e30e7542d230",
            "value" : 6556616428,
            "ergoTree" : "0008cd02fb2ab225cb6ee8e8e1f02e5be1e9aa288c8cad7c27751631d231d9c6e8f8e0f0",
            "assets" : [
                {
                    "tokenId" : "e7d40a98598fce5c0202e1a706c69350d9a15fb319ab4f268abc156aac4c1b88",
                    "amount" : 9223372036854775807
                }
            ],
            "creationHeight" : 0,
            "additionalRegisters" : {
                
            },
            "transactionId" : "c59d1201965668ccdec1fc8fde5267562e76fb1021f8055e2e1b4f19b1cb4c91",
            "index" : 5
        },

@kushti
Copy link
Member Author

kushti commented Nov 21, 2022

@kushti I changed the Token generators in WalletApiRouteSpec."sign a transaction" to return always Long.MaxValue as asset value and the response is as expected, if you pass TX (as json string) with 9223372036854775807 it returns signed TX with 9223372036854775807 asset value :

        {
            "boxId" : "1cb00cae4d72aac60e17792a9abe41e781be8fb4b218ea6eb113e30e7542d230",
            "value" : 6556616428,
            "ergoTree" : "0008cd02fb2ab225cb6ee8e8e1f02e5be1e9aa288c8cad7c27751631d231d9c6e8f8e0f0",
            "assets" : [
                {
                    "tokenId" : "e7d40a98598fce5c0202e1a706c69350d9a15fb319ab4f268abc156aac4c1b88",
                    "amount" : 9223372036854775807
                }
            ],
            "creationHeight" : 0,
            "additionalRegisters" : {
                
            },
            "transactionId" : "c59d1201965668ccdec1fc8fde5267562e76fb1021f8055e2e1b4f19b1cb4c91",
            "index" : 5
        },

Do you send tx as a string to be parsed as JSON, or ready-made JSON? Maybe you can share the test?

@pragmaxim
Copy link
Collaborator

@kushti Yeah d64a246#diff-693aa4b3e942c2e0a731d61a70b822ef9477d0e0229d413cdedfd6ae88ce6b70R107

I modified Generators to return Long.MaxValue and the println before and after contains both Long.MaxValue

@kushti
Copy link
Member Author

kushti commented Nov 21, 2022

@pragmaxim maybe swagger issue then swagger-api/swagger-ui#7478 . Update to 3.0.3 should help it seems

@pragmaxim
Copy link
Collaborator

@kushti Never done this, something like ./openapi-generator-cli.sh generate -i openapi.yaml must be done, right ?

@ghost

This comment was marked as spam.

@pragmaxim
Copy link
Collaborator

@abebeos Please go on, just remember that this is just a swagger issue, not Node issue.

@ghost

This comment was marked as spam.

@SethDusek
Copy link
Contributor

I would like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-1000 SigUSD C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

3 participants