relaypriority calculation error #8334

issue maiiz opened this issue on July 12, 2016
  1. maiiz commented at 8:43 AM on July 12, 2016: contributor

    relaypriority calculation error

    CCoinsViewCache::GetPriority has an overflow bug that affects the relaypriority calculation. The way the arithmetic works in that function is

    dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight); 
    

    the nValue variable type is int64_t, and the int64_t max value is 9223372036854775807 for example

    nValue value  is 40000000000000
    (nHeight->coins - nHeight )value is 300000 
    40000000000000 * 300000 > 9223372036854775807 
    

    so the dResult will be negative number! and the AllowFree function will return False, and the high priority transaction with low fee will be reject by node with error insufficient priority!

    I found this bug when I send a transaction with rpc api sendrawtransaction,i debug the source code find it.

    and int64_t convert double also will loss accuracy!

  2. jonasschnelli added the label Bug on Jul 12, 2016
  3. jonasschnelli added the label Priority Medium on Jul 12, 2016
  4. jonasschnelli added the label TX fees and policy on Jul 12, 2016
  5. jonasschnelli commented at 12:11 PM on July 12, 2016: contributor

    @maiiz Thanks for reporting. Are you working on a fix for that particular overflow?

  6. maiiz commented at 7:22 AM on July 13, 2016: contributor

    @jonasschnelli i just make a simple pull request for this issues, this my first commit~~

  7. gmaxwell commented at 7:33 AM on July 13, 2016: contributor

    Just cast to double inside the expression... 400,000 BTC in a free transaction, must be nice! :P (in the bitcoin network there really is no free transactions anymore, and I expect all the priority code will be removed soon, but while its there no reason to not fix it.)

  8. MarcoFalke added the label Priority Low on Aug 29, 2016
  9. MarcoFalke removed the label Priority Medium on Aug 29, 2016
  10. laanwj closed this on Sep 27, 2016

  11. DrahtBot 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 21:15 UTC

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