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

Issues with floating point precision #70

Open
cebe opened this issue Aug 19, 2018 · 3 comments
Open

Issues with floating point precision #70

cebe opened this issue Aug 19, 2018 · 3 comments

Comments

@cebe
Copy link

cebe commented Aug 19, 2018

When sending high amounts of assets, multichain may reject transactions due to rounding errors in floating point calculation. I was trying to work around this by adding additional outputs that would correct the error, but internal calculations seem to add additional errors.

Steps to reproduce:

  1. create a blockchain alpcointest with asset alpcointest
    (issue <adminaddress> '{"name":"alpcointest","open":true}' 1 0.00000001)
  2. Issue 132463363.16643485 coins to an address
  3. Try to send 30000000 to another address using the above amount as input (I am using raw transactions)
  4. sendrawtransaction fails with
    error 500 Internal Server Error: {"result":null,"error":{"code":-26,"message":"64: Asset transfer script rejected - mismatch in input/output quantities"},"id":"bo5b79fd2b28f59"}
    

The raw transaction is:

0100000002c62fc6bb2d9e2c55c7cf570ab9746c8b32b3e85012cdbbacb16a690be128298d000000006b483045022100bcd897b01b0893563b8fadc9f05314275ac9c5866ea924ae04645ef0f3d3476402201ce59042f5c4fdd1b4a29d86921bb83c64f6cd9be63ffba26f69bf5e0298b4cd012103ac43252d0ffe7bf6d037e071f5633e918ea8c566a8520fad602b8a281dba9a41ffffffff76f52585f69116c1d49c39efe0e5eaa1d883f485eee0691042efb0162324c6ea000000006b483045022100e72e5a2b5fb0260be2e6981e9063462e0e12f3562757e1a45ee542cf8772703202207835584a9c74e4c770b10f17e3126ae63109df97906f6b6c0aacacb23c6ac900012102c48536111bdf048dbaba4359385f0f858678c19e47c7819ed7fca06a7853588fffffffff0400000000000000003776a914ddfd520187cbb74acf415f7b190c400a3034b89f88ac1c73706b71f212ea472d620aecb9655431691af945008053ee7ba80a007500000000000000003776a9147bbc3a30edef5d56f11032d747e6039f81cb071088ac1c73706b71f212ea472d620aecb9655431691af94568ce889cf74e26007500000000000000003776a9146aafe02b1faccce7c1bd0f1203759abdc2974fa888ac1c73706b71f212ea472d620aecb9655431691af94501000000000000007500000000000000000e6a0c74657374207061796d656e7400000000

output of decoderawtransaction:

{
    "txid" : "b215d5dd0c214d22e3e1493354a71ccd87a997a159736e97b12d4927f42c4f2b",
    "version" : 1,
    "locktime" : 0,
    "vin" : [
        {
            "txid" : "16dd6507862ffea2813a0dbc818fad964e63e78721854803096061ed51ad1213",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "3045022100d61ee93a282fc7896d80bf67dc0e53a1564f4cd6b44b6dd11acafc2f9422754602205e277dfd00178a7d90b3c92e26439eec0f647dbe3566d046d4cdf4f11f55f9fb01 02e479c3db581bbd95a1a6ca5f67ed64805d2c2a7a374810b44002e0c7071cd069",
                "hex" : "483045022100d61ee93a282fc7896d80bf67dc0e53a1564f4cd6b44b6dd11acafc2f9422754602205e277dfd00178a7d90b3c92e26439eec0f647dbe3566d046d4cdf4f11f55f9fb012102e479c3db581bbd95a1a6ca5f67ed64805d2c2a7a374810b44002e0c7071cd069"
            },
            "sequence" : 4294967295
        },
        {
            "txid" : "c7d88d8e7e13db441688d5b5dca29c1090b65772842e7fa3d2a8c7332d44b7b0",
            "vout" : 0,
            "scriptSig" : {
                "asm" : "3045022100c851ecb052bed1fc74011d7a98a2454dd15b645620bb0f40eb95eaad376ce2c902204c25f6b1a6baf7be798672648c5fd43f20599b44039f1b12d5421601c099fab401 0261cf770703bb8a7f57df7a20c4344216c24ca7847d7678a0671109537094b0d4",
                "hex" : "483045022100c851ecb052bed1fc74011d7a98a2454dd15b645620bb0f40eb95eaad376ce2c902204c25f6b1a6baf7be798672648c5fd43f20599b44039f1b12d5421601c099fab401210261cf770703bb8a7f57df7a20c4344216c24ca7847d7678a0671109537094b0d4"
            },
            "sequence" : 4294967295
        }
    ],
    "vout" : [
        {
            "value" : 0.00000000,
            "n" : 0,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 91bb0191a1913b2c68e788be254afd8b5a3d7ff2 OP_EQUALVERIFY OP_CHECKSIG 73706b71f212ea472d620aecb9655431691af945008053ee7ba80a00 OP_DROP",
                "hex" : "76a91491bb0191a1913b2c68e788be254afd8b5a3d7ff288ac1c73706b71f212ea472d620aecb9655431691af945008053ee7ba80a0075",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1LhNuwE8ppQzcVqC5VRViJGPzQ5Ao4wMEaz6QV"
                ]
            },
            "assets" : [
                {
                    "name" : "alpcointest",
                    "issuetxid" : "45f91a69315465b9ec0a622d47ea12f21c4372bf337f7b38a52b8df4dc029b05",
                    "assetref" : "4-264-63813",
                    "qty" : 30000000.00000000,
                    "raw" : 3000000000000000,
                    "type" : "transfer"
                }
            ],
            "permissions" : [
            ],
            "items" : [
            ]
        },
        {
            "value" : 0.00000000,
            "n" : 1,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 785b4f13f8985aa34dbab4a61375741a067633cc OP_EQUALVERIFY OP_CHECKSIG 73706b71f212ea472d620aecb9655431691af94568ce889cf74e2600 OP_DROP",
                "hex" : "76a914785b4f13f8985aa34dbab4a61375741a067633cc88ac1c73706b71f212ea472d620aecb9655431691af94568ce889cf74e260075",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "1HGUSPfRHhvgE32ese2LkubkUaNgQqJcejSkYg"
                ]
            },
            "assets" : [
                {
                    "name" : "alpcointest",
                    "issuetxid" : "45f91a69315465b9ec0a622d47ea12f21c4372bf337f7b38a52b8df4dc029b05",
                    "assetref" : "4-264-63813",
                    "qty" : 107828745.05105001,
                    "raw" : 10782874505105000,
                    "type" : "transfer"
                }
            ],
            "permissions" : [
            ],
            "items" : [
            ]
        },
        {
            "value" : 0.00000000,
            "n" : 2,
            "scriptPubKey" : {
                "asm" : "OP_DUP OP_HASH160 1876f33c88cdc19b6ccf98a122315b06470acf97 OP_EQUALVERIFY OP_CHECKSIG 73706b71f212ea472d620aecb9655431691af9450100000000000000 OP_DROP",
                "hex" : "76a9141876f33c88cdc19b6ccf98a122315b06470acf9788ac1c73706b71f212ea472d620aecb9655431691af945010000000000000075",
                "reqSigs" : 1,
                "type" : "pubkeyhash",
                "addresses" : [
                    "14Jn7VQtc5XH4KdXBf87R4UEbhrtcXDgFPdvxg"
                ]
            },
            "assets" : [
                {
                    "name" : "alpcointest",
                    "issuetxid" : "45f91a69315465b9ec0a622d47ea12f21c4372bf337f7b38a52b8df4dc029b05",
                    "assetref" : "4-264-63813",
                    "qty" : 0.00000001,
                    "raw" : 1,
                    "type" : "transfer"
                }
            ],
            "permissions" : [
            ],
            "items" : [
            ]
        },
        {
            "value" : 0.00000000,
            "n" : 3,
            "scriptPubKey" : {
                "asm" : "OP_RETURN 74657374207061796d656e74",
                "hex" : "6a0c74657374207061796d656e74",
                "type" : "nulldata"
            },
            "assets" : [
            ],
            "permissions" : [
            ],
            "items" : [
            ]
        }
    ],
    "data" : [
        "74657374207061796d656e74"
    ]
}

The problem seems to be related to the conversion from raw and qty here:

                    "qty" : 107828745.05105001,
                    "raw" : 10782874505105000,
@cebe
Copy link
Author

cebe commented Aug 20, 2018

Reading https://en.bitcoin.it/wiki/Proper_Money_Handling_(JSON-RPC) I wonder if I could fix this from the client library. but given the ouput difference from multichain above, I doubt it.

@dsharhon
Copy link

In my experience, Multichain can't reliably handle more than 21 million coins, nor do you want to change the decimal place from Bitcoin's default.
Good luck with Alpcoin!

@gidgreen
Copy link
Contributor

There's an issue with accuracy in JSON (and general double floating point) representations past 16 significant digits. Please try using a method which enables MultiChain to calculate the change itself – either using createrawsendfrom or appendrawchange – instead of trying to pass the change amount in createrawtransaction.

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

3 participants