Bitcoin Forum
April 25, 2024, 01:28:03 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [script] I'm confused about negative zero!  (Read 221 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
April 02, 2019, 02:49:44 PM
Merited by Foxpup (2), bones261 (2), ABCbits (1)
 #1

All these numbers we are pushing on the stack are integers (Int32 or Int64 where there is an overflow chance). right?
There is no negative zero defined for integers! The negative zero in IEEE 754 is defined for floating point numbers (float and decimal)!
So what these lines are doing with [0, 0, 0, 0x80] is actually interpreting a completely different value (-2147483648) as so called negative zero by mistake.

What am I missing here?

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Every time a block is mined, a certain amount of BTC (called the subsidy) is created out of thin air and given to the miner. The subsidy halves every four years and will reach 0 in about 130 years.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714008483
Hero Member
*
Offline Offline

Posts: 1714008483

View Profile Personal Message (Offline)

Ignore
1714008483
Reply with quote  #2

1714008483
Report to moderator
1714008483
Hero Member
*
Offline Offline

Posts: 1714008483

View Profile Personal Message (Offline)

Ignore
1714008483
Reply with quote  #2

1714008483
Report to moderator
1714008483
Hero Member
*
Offline Offline

Posts: 1714008483

View Profile Personal Message (Offline)

Ignore
1714008483
Reply with quote  #2

1714008483
Report to moderator
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3374
Merit: 6535


Just writing some code


View Profile WWW
April 02, 2019, 05:00:22 PM
Merited by Foxpup (4), Carlton Banks (4), dbshck (4), bones261 (2), Coding Enthusiast (2), ABCbits (1)
 #2

No, Bitcoin doesn't follow existing standards for integers. Integers are not fixed length (i.e. they are not just int32 or int64). They are variable length. Any stack item of any length can be an integer. Such a stack item is interpreted as a variable length, little endian integer, with the sign determined by the most significant bit of the integer.

Due to how the script interpreter was originally implemented, negative zero is possible because the most significant bit is not part of the integer value itself and is just a sign bit. So you can have all but the MSB be 0, indicating the integer is 0, and have the MSB be 1, indicated it is negative. Hence negative zero.

Zero and negative zero have the same meaning in a script. However this means that scripts using zero can be malleated by replacing the zero with a negative zero.

apxu
Member
**
Offline Offline

Activity: 229
Merit: 13


View Profile
April 07, 2019, 03:09:58 PM
 #3

There is no negative zero defined for integers!
There is. In Bitcoin scripting and in some other places.
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!