Bitcoin Forum
November 17, 2024, 09:48:04 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: What's stopping OP_CHECKMULTISIG extra pop bug from being fixed?  (Read 193 times)
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 7389


Top Crypto Casino


View Profile WWW
August 26, 2020, 05:20:08 PM
Merited by Welsh (3), ABCbits (2), ranochigo (2), vapourminer (1)
 #1

OP_CHECKMULTISIG opcode has a bug where N, the public keys, M and the signatures are popped from the stack, it pops an extra unnecessary item off the stack. This forces all multisig transactions to have a dummy value at the beginning of the unlocking script like OP_0 or something. Since it's only one byte, the space saved by fixing this is negligible and not much of a big deal but this is a long standing bug. The only explanation I found is that it's consensus-critical code. So what will happen to the consensus if this is fixed?

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3542
Merit: 6886


Just writing some code


View Profile WWW
August 26, 2020, 05:37:29 PM
Merited by Welsh (3), ABCbits (1)
 #2

Changing this is a hard fork, so everyone needs to upgrade their node to one which doesn't have this bug. This is difficult to do and not very worthwhile.

pooya87
Legendary
*
Offline Offline

Activity: 3640
Merit: 11039


Crypto Swap Exchange


View Profile
August 27, 2020, 03:39:15 AM
 #3

a dummy value at the beginning of the unlocking script like OP_0 or something.

there is a partial fix for this in BIP-147 that was deployed with SegWit soft-fork that forces this dummy value to be OP_0 whereas before it could be anything and waste more bytes.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
BrewMaster
Legendary
*
Offline Offline

Activity: 2128
Merit: 1293


There is trouble abrewing


View Profile
August 27, 2020, 01:24:17 PM
Merited by vapourminer (1), ABCbits (1)
 #4

Changing this is a hard fork, so everyone needs to upgrade their node to one which doesn't have this bug. This is difficult to do and not very worthwhile.

On a side note, what would happen to old P2SH/P2WSH addres which uses OP_0 at the beginning of multisig script if hard fork which fixed the bug happened?
Would it become invalid or the client explicitly check when the input is created just like other fork?

any standard multisig redeem-script that is created by any wallet only contains the public keys and the m and n values. the OP_0 is always part of the signature that will be included after the signatures were produced and the transaction is ready to be included in a block and it is placed all the way at the beginning of the scriptsig like this:
Code:
OP_0 <m*signatures> <redeemscript>
after such a hard fork the above simply becomes the following spending the same P2SH or P2WSH output:
Code:
<m*signatures> <redeemscript>

it is highly unlikely that an un-revealed redeem script has both the signature and the OP_0 inside in which case such redeem script can be spent by anyone as soon as it is revealed. and it will become unspendable after such hard fork.

There is a FOMO brewing...
NotATether (OP)
Legendary
*
Offline Offline

Activity: 1792
Merit: 7389


Top Crypto Casino


View Profile WWW
August 27, 2020, 02:33:18 PM
 #5

it is highly unlikely that an un-revealed redeem script has both the signature and the OP_0 inside in which case such redeem script can be spent by anyone as soon as it is revealed. and it will become unspendable after such hard fork.

So it looks like that after a hard fork, the nodes which haven't updated and still send redeem scripts with OP_0 will be rejected by updated nodes. I wonder if theoretically there is a way to signal that such scripts come from older node versions and still be processed equivalently? Normally, and not in OP_CHECKMULTISIG special case, does an OP_0 at the beginning make the script evaluate to true?

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
BrewMaster
Legendary
*
Offline Offline

Activity: 2128
Merit: 1293


There is trouble abrewing


View Profile
August 27, 2020, 03:21:01 PM
 #6

So it looks like that after a hard fork, the nodes which haven't updated and still send redeem scripts with OP_0 will be rejected by updated nodes.
yes but also the old nodes will reject any similar thing without the OP_0 coming from the new nodes. that is why it is called hard fork and needs the entire network to upgrade.

Quote
I wonder if theoretically there is a way to signal that such scripts come from older node versions and still be processed equivalently?
the problem is transaction ID. the new node could technically add the OP_0 (it is malleable) and send it to the old node so that it doesn't fail while evaluating that tx but it will also change the txid and when someone spends that transaction with the different txid the old node won't be able to verify that new tx and fails there.

Quote
Normally, and not in OP_CHECKMULTISIG special case, does an OP_0 at the beginning make the script evaluate to true?
normally if after there is one last OP_0 left it has to push an empty array to the stack so the top stack item is converted (CastToBool) to false hence the evaluation fails.

in case of OP_CHECKMULTISIG, it pops that extra item and throws it away then pushes the result of signature verification to the stack.
this is also why P2WSH scripts don't fail since they expect a clean stack after evaluation, that dummy item is already popped and thrown away.

There is a FOMO brewing...
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4284
Merit: 8808



View Profile WWW
August 27, 2020, 11:21:41 PM
Last edit: August 28, 2020, 12:03:03 PM by gmaxwell
Merited by ABCbits (2), vapourminer (1), BrewMaster (1)
 #7

I think it is probably wrong to describe it as a bug.  I think it was intended to indicate which signatures were present to fix the otherwise terrible performance of checkmultisig.

Regardless, there is no real point to fixing it:  Any 'fix' would require that all software using checkmultisig get an incompatible change (as part of a highly disruptive hard fork).  Because the extra value is now always zero (and was pretty much always, or was actually always zero before)  you can compress it out  completely over the wire or on disk if you really care-- so the only effect it has is its weight in transactions and the one or so extra cpu cycle going into a hash.

Instead a new operation can be introduced that just doesn't have that behaviour-- and that would be compatible, software that wants the new behaviour would just upgrade when it wants it,  no flag day, no disruption.

BIP342 replaces checkmultisig entirely with something that is more computationally efficient and more flexible (and more space/weight efficient too, once you count that the signatures are 9 bytes shorter and the pubkeys are 1 bytes shorter).
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!