Bitcoin Forum
May 10, 2024, 08:22:22 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: theoretical code limit on handling values  (Read 546 times)
bumbacoin (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 1036



View Profile
February 13, 2017, 02:58:26 AM
Last edit: February 13, 2017, 03:20:23 AM by bumbacoin
 #1

ignoring the obvious 21mill projected coin supply,

what is the theoretical max value that the code base can handle ?

is it int64 ?
or
9223372036854775807

divided by satoshi ofc, so just over 92 billion coins ?


edit.
i see dogecoin has over 100 billion coins :p


edit.
i've just been looking further and i see int64 max is 2^63, as 1 bit is used for +/-

💦☔️🐳💚💖💛
go to
cryptobetfair.com
ask for a voucher

████████████████
██████████████
█████████████
██████████████
██████████████
███████████
█████████
███████████
████████████
████████████
███████████
█████████████
██████████████
███████████████
████████████████
████████████████
🐠👻🍗🌳🐵
1715329342
Hero Member
*
Offline Offline

Posts: 1715329342

View Profile Personal Message (Offline)

Ignore
1715329342
Reply with quote  #2

1715329342
Report to moderator
1715329342
Hero Member
*
Offline Offline

Posts: 1715329342

View Profile Personal Message (Offline)

Ignore
1715329342
Reply with quote  #2

1715329342
Report to moderator
"Bitcoin: the cutting edge of begging technology." -- Giraffe.BTC
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715329342
Hero Member
*
Offline Offline

Posts: 1715329342

View Profile Personal Message (Offline)

Ignore
1715329342
Reply with quote  #2

1715329342
Report to moderator
1715329342
Hero Member
*
Offline Offline

Posts: 1715329342

View Profile Personal Message (Offline)

Ignore
1715329342
Reply with quote  #2

1715329342
Report to moderator
1715329342
Hero Member
*
Offline Offline

Posts: 1715329342

View Profile Personal Message (Offline)

Ignore
1715329342
Reply with quote  #2

1715329342
Report to moderator
bumbacoin (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 1036



View Profile
February 13, 2017, 03:08:39 AM
 #2

curiously enough,
21 million is allegedly close to a 64 bit floating point number ?
2^52 = 2251799813685248 satoshis



https://en.bitcoin.it/wiki/Controlled_supply#Currency_with_Finite_Supply
"Speculated justifications for the unintuitive value "21 million" are that it matches a 4-year reward halving schedule; or the ultimate total number of Satoshis that will be mined is close to the maximum capacity of a 64-bit floating point number. Satoshi has never really justified or explained many of these constants."



obviously there are some programming limitations on what a 64 bit integer can usefully represent,
this has confused me no end. lol

💦☔️🐳💚💖💛
go to
cryptobetfair.com
ask for a voucher

████████████████
██████████████
█████████████
██████████████
██████████████
███████████
█████████
███████████
████████████
████████████
███████████
█████████████
██████████████
███████████████
████████████████
████████████████
🐠👻🍗🌳🐵
Foxpup
Legendary
*
Offline Offline

Activity: 4354
Merit: 3044


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
February 13, 2017, 03:33:56 AM
 #3

The main limitation is that JSON, being JavaScript-based, interprets numbers as double-precision floating point. The largest value that can be thus represented correct to 8 decimal places is 67,108,863.99999999. But even if nothing in Bitcoin Core used floating points, it's highly likely that other Bitcoin software still would (eg, web wallets using JavaScript), so it's not a simple matter to use larger number formats.

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
February 13, 2017, 04:02:40 AM
 #4

The main limitation is that JSON, being JavaScript-based
What does JSON have to do with any of this? The Bitcoin protocol does not use JSON anywhere.


The field for the value of an output is an int64 so its max value is 2^(64-1). That is how many satoshis you can specify in one output.

bumbacoin (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 1036



View Profile
February 13, 2017, 04:57:14 AM
Last edit: February 13, 2017, 05:11:29 AM by bumbacoin
 #5

i notice doge has over 100 billion coins,
and 2 ^63 is around 92 billion coins (9.22337203685478E18 satoshi),
so seemingly as long as they're not all in one tx, it's possible because any individual case will not exceed int64 limits.

i wonder how PoS coins with their moneysupply rpc would handle that.

seems like that 'd be the first thing to break.

💦☔️🐳💚💖💛
go to
cryptobetfair.com
ask for a voucher

████████████████
██████████████
█████████████
██████████████
██████████████
███████████
█████████
███████████
████████████
████████████
███████████
█████████████
██████████████
███████████████
████████████████
████████████████
🐠👻🍗🌳🐵
achow101
Staff
Legendary
*
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
February 13, 2017, 05:09:31 AM
 #6


i notice doge has over 100 billion coins,
and 2 ^63 is around 92 billion,
No it isn't. 2^63 is 9.223372e+18, which is several orders of magnitude than the billions. Where did you get the billion number?

bumbacoin (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 1036



View Profile
February 13, 2017, 05:10:54 AM
 #7


sorry, 9.22337203685478E18 satoshis (or dogetoshis, or bumbatoshis lol),

which is ~92 billion coins,


Smiley fixed above also

💦☔️🐳💚💖💛
go to
cryptobetfair.com
ask for a voucher

████████████████
██████████████
█████████████
██████████████
██████████████
███████████
█████████
███████████
████████████
████████████
███████████
█████████████
██████████████
███████████████
████████████████
████████████████
🐠👻🍗🌳🐵
Foxpup
Legendary
*
Offline Offline

Activity: 4354
Merit: 3044


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
February 13, 2017, 05:33:58 AM
 #8

The main limitation is that JSON, being JavaScript-based
What does JSON have to do with any of this? The Bitcoin protocol does not use JSON anywhere.
No, but the RPC interface does, and enough programs are still treating bitcoin amounts as floats that floating-point precision is the limit of what numbers are "safe".

In fact, I predict that within a year of fractional satoshis being introduced (by a protocol extension or second layer or whatever), someone will lose a significant amount of money due to a floating-point rounding error in third-party software.

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
bumbacoin (OP)
Legendary
*
Offline Offline

Activity: 1638
Merit: 1036



View Profile
February 14, 2017, 01:12:37 AM
Last edit: February 14, 2017, 06:58:08 AM by bumbacoin
 #9

The main limitation is that JSON, being JavaScript-based
What does JSON have to do with any of this? The Bitcoin protocol does not use JSON anywhere.
No, but the RPC interface does, and enough programs are still treating bitcoin amounts as floats that floating-point precision is the limit of what numbers are "safe".

In fact, I predict that within a year of fractional satoshis being introduced (by a protocol extension or second layer or whatever), someone will lose a significant amount of money due to a floating-point rounding error in third-party software.

i've been looking at Stronghands (PPC clone) because it can't handle a transaction value close to MAX_MONEY,
it appears to pass a pre-check, then is entered into wallet db, then fails a post-check breaking the wallet.dat

i'm not sure what's going on, but at some point tx out value is handled by JSON.
i'm wondering if this is causing the problem through slight variations in value.

there are a bunch of checks arounds MAX_MONEY (including MoneyRange).
i changed one of the error checks to (MAX_MONEY - 1),
and it still allows .00000011 over that value so there is some obvious looseness around these values. (edited, too many zeroes)
https://github.com/bumbacoin/stronghands/commit/8bc58843f43012e142beff29a8fcbb7a37c8ed5b

on a cursory glance the code is the same as PPC, BTC has changed a lot since then.

💦☔️🐳💚💖💛
go to
cryptobetfair.com
ask for a voucher

████████████████
██████████████
█████████████
██████████████
██████████████
███████████
█████████
███████████
████████████
████████████
███████████
█████████████
██████████████
███████████████
████████████████
████████████████
🐠👻🍗🌳🐵
Foxpup
Legendary
*
Offline Offline

Activity: 4354
Merit: 3044


Vile Vixen and Miss Bitcointalk 2021-2023


View Profile
February 14, 2017, 04:29:51 AM
 #10

there are a bunch of checks arounds MAX_MONEY (including MoneyRange).
i changed one of the error checks to (MAX_MONEY - 1),
and it still allows .000000011 over that value so there is some obvious looseness around these values.
https://github.com/bumbacoin/stronghands/commit/8bc58843f43012e142beff29a8fcbb7a37c8ed5b
You seem to have snuck in an extra decimal place there:
Code:
>>> 1999999999.00000011 > 1999999999
False
But there's no inherent "looseness" here; remember that floating points are simply integers multiplied by an integer power of two, eg, the decimal fraction 0.5 is represented as 1x2-1. Binary scientific notation, in other words. Double-precision floats (which is what you're dealing with) use 11 bits to store the exponent, which leaves only 53 bits bits for the mantissa (including the sign bit). That's just not enough for a number like 1999999999.00000011, so the least significant bits are lost:
Code:
>>> 1999999999.00000011
1999999999.0
This isn't really a problem with floating points per se; you're fundamentally trying to squeeze a too big number into too few bits, which will naturally give erroneous results no matter what method you use. Nothing you can do except use 64-bit integers everywhere (and convince everyone else writing software for your coin to do the same; good luck).

Will pretend to do unspeakable things (while actually eating a taco) for bitcoins: 1K6d1EviQKX3SVKjPYmJGyWBb1avbmCFM4
I am not on the scammers' paradise known as Telegram! Do not believe anyone claiming to be me off-forum without a signed message from the above address! Accept no excuses and make no exceptions!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!