Potential overflow of the network's hashrate indicator in the JSON-RPC API #7476

issue priiduneemre opened this issue on February 7, 2016
  1. priiduneemre commented at 12:49 PM on February 7, 2016: none

    I was calling the getnetworkhashps and getmininginfo RPCs via some Java code the other day and realized that the hashrate is getting pretty close to overflowing a signed 64-bit integer. Hence, I decided to check how bitcoind handles things (with some help from Luke Jr) and it turns out that a signed 64-bit integer (int64_t) is used indeed (at least in mining.cpp (see here)) -- potentially elsewhere as well?

    As you all know, the max value for a 64-bit signed integer is 2^63-1, or about 9223372036854775807. With the sharp increase in hashrate these past few weeks, we seem to be up to about 12.5% of the datatype's full capacity at this point. To illustrate this:

    9 223 372 036 854 775 807 (maximum value of a 64-bit signed integer) 1 126 516 160 438 311 092 (current network hashrate -- as of 2016-02-07 12:20:07 UTC)

    According to historical data, the value could wrap in maybe 1 - 1.5 years (or however long it'll take for a 1-order-of-magnitude increase in hashrate).

    Luke Jr advised me to create a PR on this in the #bitcoin-dev IRC channel the other day. However, as I don't know the codebase that well and am not very well-versed in C++ specifics & caveats, I decided to create this issue instead.

    Maybe someone smarter can take a quick look at this and prove me wrong if that's the case :).

  2. instagibbs commented at 2:47 PM on February 7, 2016: member

    Looks like it should be a pretty contained fix if you want to take a stab at it. The function doesn't seem to be used anywhere else except for RPC. Best way to learn the codebase is fix something.

  3. sipa commented at 3:03 PM on February 7, 2016: member

    It's an approximation anyway. Just turn it into a floating point result.

  4. laanwj added the label RPC on Feb 8, 2016
  5. laanwj commented at 9:03 AM on February 8, 2016: member

    Agree with @sipa. This doesn't warrant overhauling the entire RPC system to support larger integers. Floating point should never be used for monetary values, but limited-precision approximations is exactly what it was invented for.

  6. instagibbs cross-referenced this on Feb 8, 2016 from issue Changed getnetworkhps value to double to avoid overflow. by instagibbs
  7. laanwj closed this on Feb 9, 2016

  8. bitcoin 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-05-20 06:55 UTC