Bitcoin Forum
March 29, 2020, 07:09:47 PM *
News: Latest Bitcoin Core release: 0.19.0.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [script] I'm confused about negative zero!  (Read 157 times)
Coding Enthusiast
Hero Member
*****
Offline Offline

Activity: 758
Merit: 1450


Novice C♯ Coder


View Profile WWW
April 02, 2019, 02:49:44 PM
Merited by Foxpup (2), bones261 (2), ETFbitcoin (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.1.1)Ann-git
Denovo(0.0.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.1.0)Ann-git
SharpPusher(0.10.0)Ann-git
1585508987
Hero Member
*
Offline Offline

Posts: 1585508987

View Profile Personal Message (Offline)

Ignore
1585508987
Reply with quote  #2

1585508987
Report to moderator
1585508987
Hero Member
*
Offline Offline

Posts: 1585508987

View Profile Personal Message (Offline)

Ignore
1585508987
Reply with quote  #2

1585508987
Report to moderator
1585508987
Hero Member
*
Offline Offline

Posts: 1585508987

View Profile Personal Message (Offline)

Ignore
1585508987
Reply with quote  #2

1585508987
Report to moderator
AWARD-WINNING
CRYPTO CASINO
ASKGAMBLERS
PLAYERS CHOICE 2019
PROUD
PARTNER OF
1500+
GAMES
2 MIN
CASH-OUTS
24/7
SUPPORT
100s OF
FREE SPINS
PLAY NOW
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 2086
Merit: 3187


bc1qshxkrpe4arppq89fpzm6c0tpdvx5cfkve2c8kl


View Profile WWW
April 02, 2019, 05:00:22 PM
Merited by Foxpup (4), Carlton Banks (4), dbshck (4), bones261 (2), Coding Enthusiast (2), ETFbitcoin (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: 230
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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!