Comparison of base_blob (uint256) starts from the most right bits #9515

issue mezrin opened this issue on January 11, 2017
  1. mezrin commented at 2:14 AM on January 11, 2017: none

    I faced very strange problem with the base_blob. Example:

    LogPrintf("Start to test uint256.\n");
    auto targetValue = uint256S("0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
    auto testValue01 = uint256S("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
    auto testValue02 = uint256S("0x69143d2202526eaa843cddbeb8c08ae66d61c73a63ecf5b762d107dd07fe5c3e");
    auto testValue03 = uint256S("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000");
    auto testValue04 = uint256S("0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff0000");
    auto testValue05 = uint256S("0x0000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffff");
    LogPrintf("Test 01 - %d\n", (testValue01 < targetValue));
    LogPrintf("Test 02 - %d\n", (testValue02 < targetValue));
    LogPrintf("Test 03 - %d\n", (testValue03 < targetValue));
    LogPrintf("Test 04 - %d\n", (testValue04 < targetValue));
    LogPrintf("Test 05 - %d\n", (testValue05 < targetValue));
    LogPrintf("Finished to test uint256\n\n\n");
    

    Result - 0, 1, 1, 1, 1. I.e. testValue01bigger, testValue02..05 smaller than targetValue. But correct values - 0, 0, 0, 1, 1

    Seems that comparison of uint256 starts from the most right bits. I have no other explanation of test results. Is it a bug? What am I misreading?

    Tested commit - most recent in the branch 0.13 (77eaadb) Ubuntu 16.04

  2. mezrin renamed this:
    bug in base_blob
    Comparison of base_blob starts from the most right bits ?
    on Jan 11, 2017
  3. mezrin renamed this:
    Comparison of base_blob starts from the most right bits ?
    Comparison of base_blob starts from the most right bits
    on Jan 11, 2017
  4. mezrin renamed this:
    Comparison of base_blob starts from the most right bits
    Comparison of base_blob (uint256) starts from the most right bits
    on Jan 11, 2017
  5. laanwj commented at 1:29 PM on January 11, 2017: member

    The comparison of base_blob compares the internal binary representation lexicographically - which is fast and good enough for maps and such. There it doesn't matter what the sorting is, as long as there is some order.

    If you intend to compare 256-bit integers you should use arith_uint256.

  6. mezrin commented at 5:49 PM on January 11, 2017: none

    ooops. sorry

  7. mezrin closed this on Jan 11, 2017

  8. MarcoFalke locked this on Sep 8, 2021
Contributors

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-21 18:15 UTC

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