Possible MINOR vulnerability in BIP70 implementation #5624

issue laanwj opened this issue on January 9, 2015
  1. laanwj commented at 9:25 AM on January 9, 2015: member

    (as reported by Sergio Damien Lerner)

    Bitcoin amounts are stored as uint64 in the protobuf messages. Amounts over 0x7FFFFFFFFFFFFFFF will be considered negative when this line is executed:

    QList<std::pair<CScript, CAmount> > sendingTos = request.getPayTo();   
    

    (in PaymentServer::processPaymentRequest() in qt\paymentserver.cpp)

    This does not pose a problem, since negative values should be discardedby the dust check : if (txOut.IsDust(::minRelayTxFee))

    Nevertheless recipient.amount will still accumulate all positive values and may overflow, since the payment protocol allows the merchant to specify many output addresses and each one has a separate amount. So it is still possible to create a negative total amount by overflowing the int64 range with several positive amounts. For example, (uint64) -1 + (uint64) -1 + 3 == 1. The user will be presented with a dialog asking to pay a total of 1 BTC, but internally the operation will fail, because the independent constituent payment amounts will not be able to be fulfilled.

    This has the nasty effect that the user may think he may have been robbed, because even if the user has 100 BTC, the software will tell the user "The amount exceeds your balance.".

    Correction:

    bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request,
    SendCoinsRecipient& recipient) {
        ....
       CTxOut txOut(sendingTo.second, sendingTo.first);
        // BEGIN ADD
         if (!MoneyRange(sendingTo.second)) {
            emit message(tr("Payment request rejected"),
                    tr("Invalid money range."),
                    CClientUIInterface::MSG_ERROR);
                return false;
        }
       // END ADD
      ....
        recipient.amount += sendingTo.second;
      ...
        // BEGIN ADD
         if (!MoneyRange(recipient.amount)) {
            emit message(tr("Payment request rejected"),
                    tr("Invalid  accumulated money range."),
                    CClientUIInterface::MSG_ERROR);
                return false;
        }
       // END ADD
    

    The payment request unit test should be extended to test negative and very large amounts in requests....

  2. laanwj added the label GUI on Jan 9, 2015
  3. laanwj added the label Priority Medium on Jan 9, 2015
  4. Diapolo commented at 1:19 PM on January 9, 2015: none

    Giving this a shot!

  5. Diapolo commented at 1:37 PM on January 9, 2015: none

    @laanwj Did the fix pull, but I'm not able to craft a new payment request in paymentrequestdata.h, which triggers this in a new testcase that needs to be added to paymentservertests.cpp.

  6. laanwj closed this on Feb 9, 2015

  7. lucayepa referenced this in commit adee0a0042 on Mar 9, 2015
  8. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me