arith_uint256 minus operation differs from CBigNum #11088

issue Bushstar opened this issue on August 18, 2017
  1. Bushstar commented at 2:00 PM on August 18, 2017: contributor

    Using the 0.8 codebase compiled with mingw and the 0.13 codebase cross compiled for Windows on Ubuntu. With some bespoke code the same values for a minus operation differ between arith_uint256 and CBigNum, I'm getting positive arith_uint256 values where as with CBigNum in older codebases returns negative. I assume that the arith_uint256 is wrapping around, CBigNum being a uint should not have gone negative.

    0.8

    CBigNum mathsInputOne;
    CBigNum mathsInputTwo;
    CBigNum mathsOne;

    0.13

    arith_uint256 mathsInputOne;
    arith_uint256 mathsInputTwo;
    arith_uint256 mathsOne;

    The operation is a simple one.

    mathsOne = mathsInputTwo - mathsInputOne;

    Value for mathsInputOne = 00000ec639000000000000000000000000000000000000000000000000000000 Value for mathsInputTwo = 00000ec302000000000000000000000000000000000000000000000000000000

    The results are below.

    0.8 CBigNum (Converted to hexidecimal)

    -337000000000000000000000000000000000000000000000000000000

    0.13 arith_uint256

    fffffffcc9000000000000000000000000000000000000000000000000000000

    CBigNum used OpenSSL BN_sub for minus operations where as arith_uint256 is implemented locally in arith_uint256.h. Unfortunately the project I'm working with expects the negative values rather than the wrapped ones, not exactly sure what to do except for restore CBigNum along with OpenSSL bn.h.

  2. gmaxwell commented at 8:59 AM on August 20, 2017: contributor

    It's a uint. Our behavior is correct. If you need signed numbers, you need something else-- or rework your arithmetic to not need signed numbers.

  3. Bushstar commented at 9:11 AM on August 20, 2017: contributor

    Thanks. I've added CBigNum into the project to get it working as it use to.

  4. Bushstar closed this on Aug 20, 2017

  5. 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-05-02 15:15 UTC

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