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

Serialized transaction does not match original txJSON. #1237

Closed
tuloski opened this issue Mar 22, 2020 · 3 comments · Fixed by #1295
Closed

Serialized transaction does not match original txJSON. #1237

tuloski opened this issue Mar 22, 2020 · 3 comments · Fixed by #1295

Comments

@tuloski
Copy link
Collaborator

tuloski commented Mar 22, 2020

When I'm sending a payment this happens: Serialized transaction does not match original txJSON.
This is the transaction from preparePayment:

Payment: {
  "txJSON": "{\"TransactionType\":\"Payment\",\"Account\":\"rXXX\",\"Destination\":\"XXX\",\"Amount\":{\"currency\":\"USD\",\"issuer\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\",\"value\":\"600.00\"},\"Flags\":XXX,\"DestinationTag\":XXX,\"SendMax\":{\"currency\":\"USD\",\"issuer\":\"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B\",\"value\":\"600.00\"},\"LastLedgerSequence\":54250274,\"Sequence\":4054,\"Fee\":\"12\"}",
  "instructions": {
    "fee": "0.000012",
    "sequence": 4054,
    "maxLedgerVersion": 54250274
  }
}

This is the error reporting the difference:

Error: {
  "name": "ValidationError",
  "data": {
    "decoded": {
      "TransactionType": "Payment",
      "Flags": 2147483648,
      "Sequence": 4054,
      "DestinationTag": XXX,
      "LastLedgerSequence": 54250274,
      "Amount": {
        "value": "600",
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
      },
      "Fee": "12",
      "SendMax": {
        "value": "600",
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
      },
      "Account": "XXX",
      "Destination": "XXX"
    },
    "tx": {
      "TransactionType": "Payment",
      "Account": "XXX",
      "Destination": "XXX",
      "Amount": {
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
        "value": "600.00"
      },
      "Flags": 2147483648,
      "DestinationTag": XXX,
      "SendMax": {
        "currency": "USD",
        "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
        "value": "600.00"
      },
      "LastLedgerSequence": 54250274,
      "Sequence": 4054,
      "Fee": "12"
    },
    "diff": {
      "Amount": {
        "value": "600"
      },
      "SendMax": {
        "value": "600"
      }
    }
  }
}

It seems to me that the two are identical. I don't see the difference so maybe lodash_isequal_1.default in sign.js is doing something wrong.

@tuloski
Copy link
Collaborator Author

tuloski commented Mar 22, 2020

Actually I saw the difference...in one the amount is "600", in the other "600.00" so the string is actually different.
So maybe comparing two objects is not the best idea IMO.
Or is it conceptually wrong if I put "600.00" instead of "600" in my payment transaction? I think it should be allowed.

@intelliot
Copy link
Collaborator

We added this safety check after an earlier issue where specifying a fractional number of XRP drops could cause an incorrect number to be encoded in the serialized transaction. I think it is safest if you specify “600”. Then there is no risk that the encoded transaction would be different from what you expected.

In this case it’s probably OK that 600.00 gets encoded as 600. But the code doesn’t automatically assume that this is always safe. It returns this error so that you can truncate the value to 600 yourself.

@leobel
Copy link

leobel commented May 20, 2020

Hi @intelliot. I'm not sure if this is a bug but when I try to using preparePayment with source.amount/destination.minAmount combination it throws the same error ValidationError: Serialized transaction does not match original txJSON. See error.data. This is the error data:

{
"decoded": {
    "TransactionType": "Payment",
    "Flags": 2147614720,
    "Sequence": 7057769,
    "LastLedgerSequence": 7299386,
    "Amount": {
        "value": "999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "currency": "USD",
        "issuer": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq"
    },
    "Fee": "12",
    "SendMax": {
        "value": "5",
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH"
    },
    "DeliverMin": {
        "value": "5",
        "currency": "USD",
        "issuer": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq"
    },
    "Account": "rKSSpinGrMMPAuKBPH7Qpyxq2cMjpSgdqi",
    "Destination": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq"
},
"tx": {
    "TransactionType": "Payment",
    "Account": "rKSSpinGrMMPAuKBPH7Qpyxq2cMjpSgdqi",
    "Destination": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
    "Amount": {
        "currency": "USD",
        "issuer": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
        "value": "9999999999999999e80"
    },
    "Flags": 2147614720,
    "SendMax": {
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH",
        "value": "5"
    },
    "DeliverMin": {
        "currency": "USD",
        "issuer": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
        "value": "5"
    },
    "LastLedgerSequence": 7299386,
    "Fee": "12",
    "Sequence": 7057769
},
"diff": {
    "Amount": {
        "value": "999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000"
    }
}

}

Notice how the tx.Amount object has the maximum valid number for a NON-XRP currency. You can see the same behavior with a cross payment, the tx.Amount is the same, the currency is USD no matter the currency you use for source.amount. For example I get this from getPaths:

    "source": {
        "address": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
        "amount": {
            "currency": "GBP",
            "value": "0.1",
            "counterparty": "rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro"
    	}
    },
    "destination": {
        "address": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
        "minAmount": {
            "currency": "USD",
            "value": "0.1248548562296331",
            "counterparty": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH"
        }
    }
}

and this is the error when try to prepare the payment:

 {
"decoded": {
    "TransactionType": "Payment",
    "Flags": 2147614720,
    "Sequence": 7126179,
    "LastLedgerSequence": 7299566,
    "Amount": {
        "value": "999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000",
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH"
    },
    "Fee": "12",
    "SendMax": {
        "value": "0.1",
        "currency": "GBP",
        "issuer": "rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro"
    },
    "DeliverMin": {
        "value": "0.1248548562296331",
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH"
    },
    "Account": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
    "Destination": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq"
},
"tx": {
    "TransactionType": "Payment",
    "Account": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
    "Destination": "rEX4LtGJubaUcMWCJULcy4NVxGT9ZEMVRq",
    "Amount": {
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH",
        "value": "9999999999999999e80"
    },
    "Flags": 2147614720,
    "SendMax": {
        "currency": "GBP",
        "issuer": "rpat5TmYjDsnFSStmgTumFgXCM9eqsWPro",
        "value": "0.1"
    },
    "DeliverMin": {
        "currency": "USD",
        "issuer": "rMaa8VLBTjwTJWA2kSme4Sqgphhr6Lr6FH",
        "value": "0.1248548562296331"
    },
    "LastLedgerSequence": 7299566,
    "Fee": "12",
    "Sequence": 7126179
},
"diff": {
    "Amount": {
        "value": "999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000"
    }
}

}

Probably tx.Amount is ok, but the representation between both tx.Amount.value and decoded.Amount.value is different
9999999999999999e80 vs 999999999999999900000000000000000000000000000000000000000000000000000000000000000000000000000000

intelliot added a commit that referenced this issue May 22, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
See: #1237 (comment)

Fix #1237

Thanks to @leobel
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

Successfully merging a pull request may close this issue.

3 participants