Bitcoin Forum
November 10, 2024, 11:28:12 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Clarifying BIP62 Zero-padded number pushes  (Read 865 times)
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1111


View Profile
April 26, 2015, 06:32:14 PM
 #1

In BIP62, it says
Quote
Zero-padded number pushes Any time a script opcode consumes a stack value that is interpreted as a number, it must be encoded in its shortest possible form. 'Negative zero' is not allowed. See reference: Numbers.
Quote
The native data type of stack elements is byte arrays, but some operations interpret arguments as integers. The used encoding is little endian with an explicit sign bit (the highest bit of the last byte). The shortest encodings for numbers are (with the range boundaries encodings given in hex between ()).

0: OP_0; (00)
1..16: OP_1..OP_16; (51)..(60)
-1: OP_1NEGATE; (79)
-127..-2 and 17..127: normal 1-byte data push; (01 FF)..(01 82) and (01 11)..(01 7F)
-32767..-128 and 128..32767: normal 2-byte data push; (02 FF FF)..(02 80 80) and (02 80 00)..(02 FF 7F)
-8388607..-32768 and 32768..8388607: normal 3-byte data push; (03 FF FF FF)..(03 00 80 80) and (03 00 80 00)..(03 FF FF 7F)
-2147483647..-8388608 and 8388608..2147483647: normal 4-byte data push; (04 FF FF FF FF)..(04 00 00 80 80) and (04 00 00 80 00)..(04 FF FF FF 7F)
Any other numbers cannot be encoded.
In particular, note that zero could be encoded as (01 80) (negative zero) if using the non-shortest form is allowed.

If I try to use non-standard push in the scriptPubKey, without zero-padding, would that be allowed? For example, is the scriptPubKey "5101019C" spendable under BIP62?

Code:
OP_1 OP_PUSHDATA(01) OP_NUMEQUAL

Currently, I think this is spendable with an empty scriptSig.

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
jl2012 (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 1111


View Profile
April 27, 2015, 04:51:41 AM
 #2

There are few more edge cases I would like to clarify:

1. The use of non-standard push in scriptPubKey (Based on the BIP62 description I think this is allowed)

2. The use of non-standard push in P2SH serialized script

3. The use of zero-padded number in scriptPubKey or P2SH serialized script (I think this is not allowed)

4. The use of non-standard push but not zero-padded number in scriptPubKey (the original question)

5. The use of non-standard push but not zero-padded number in P2SH serialized script

6. The use of zero-padded number in scriptPubKey or P2SH serialized script (I think this is not allowed)

7. The use of non-DER or high-S signatures in scriptPubKey or P2SH serialized script (I think this is not allowed)

8. The use of something not an empty byte as the extra stake element for CHECKMULTISIG in scriptPubKey or P2SH serialized script (I think this is not allowed)

9. The use of empty byte, but not a direct result of OP_0 (e.g. "OP_0 OP_ABS" or "0100"), as the extra stake element for CHECKMULTISIG in scriptPubKey or P2SH serialized script .

10. Having more than one item left in the stake due to the design of scriptPubKey (e.g. scriptSig = empty; scriptPubKey = OP_1 OP_1) (I think this is not allowed)

I think all these cases are currently allowed and would not cause any malleability.

Donation address: 374iXxS4BuqFHsEwwxUuH3nvJ69Y7Hqur3 (Bitcoin ONLY)
LRDGENPLYrcTRssGoZrsCT1hngaH3BVkM4 (LTC)
PGP: D3CC 1772 8600 5BB8 FF67 3294 C524 2A1A B393 6517
johoe
Full Member
***
Offline Offline

Activity: 217
Merit: 259


View Profile
April 30, 2015, 09:50:32 AM
 #3

BIP 62 only protects scriptSig.  The other parts are not malleable by third party.

  • scriptPubKey in outputs are (usually) signed
  • P2SH script has to match its hash in the input transaction's scriptPubKey

update:  Okay I posted to fast.  There are some more checks that also apply for other script types.  I leave it to others to clarify this.

Donations to 1CF62UFWXiKqFUmgQMUby9DpEW5LXjypU3
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4270
Merit: 8805



View Profile WWW
April 30, 2015, 04:59:07 PM
 #4

No restrictions can be placed on scriptPubKeys or redeemscript-content without potentially confiscating people's Bitcoins.
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!