Bitcoin Forum
June 15, 2024, 04:51:35 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Questions about generic signmessage (BIP322)  (Read 198 times)
tiagocs (OP)
Newbie
*
Offline Offline

Activity: 28
Merit: 24


View Profile
July 11, 2020, 07:45:44 PM
Merited by dbshck (4), ABCbits (2), o_e_l_e_o (2), pooya87 (1), The Cryptovator (1), Heisenberg_Hunter (1)
 #1

I have two questions regarding the generalization of message signing/verification that has until recently only been done with legacy addresses through the RPC commands signmessage/verifymessage.

1 - Why was it chosen to prepend the scriptPubKey (when not P2PKH) to the preimage? To me, this adds unnecessary complexity which will slow down the adoption of BIP 322 by bitcoin libraries.

2 - In https://bitcoinops.org/en/topics/generic-signmessage , it can be read "This means a signed message can be produced for any script or address that a wallet would be able to spend. Additionally, two or more wallets can cooperate to create a BIP322 signed message for multisig scripts.". Additionally, BIP322 states that in order to sign: (https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki#signing) "Derive the private key privkey for the scriptPubKey". I just don't know how this is possible, it should be impossible to derive a private key from a scriptPubKey of a multisig for example. For a multisig there are a set of private and public keys of the owners, can there be a single private key of the whole multisig that can sign anything without the other's approval? And even if yes, how can the public key of this derived master multisig private key match the public key hash which is a hash of the locking script?
pooya87
Legendary
*
Offline Offline

Activity: 3486
Merit: 10641



View Profile
July 12, 2020, 03:37:29 AM
 #2

i find BIP322 generally bad because it is focusing too much on how it can use the bitcoin core code-base instead of coming up with an algorithm to sign messages in general. in fact i believe that is why it is using a field called "witness" in a message signature where it is not needed at all. it also has some flaws and doesn't address certain cases for example when the script contains locktime related OP codes.
this may be the reason why it was not adopted even though it is ~2 years old.

"Derive the private key privkey for the scriptPubKey". I just don't know how this is possible, it should be impossible to derive a private key from a scriptPubKey of a multisig for example.

it is either talking about "fetching" the private key for that script from the wallet or it is referring to the "ephemeral elliptic curve key pair" usually referred to as "k" for the signing process.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4200
Merit: 8440



View Profile WWW
July 12, 2020, 05:57:52 AM
Merited by ABCbits (2), o_e_l_e_o (2), NotATether (1)
 #3

focusing too much on how it can use the bitcoin core code-base instead of coming up with an algorithm to sign messages in general.
I think you're mistaken.

If you want something that signs messages in general use GPG.  It would be an extremely bad practice to come up with some novel cryptosystem just to sign messages when established audited and mature alternatives exists.

Bitcoin uses a novel cryptosystem for signing transactions called Bitcoin Script which allows all sorts of complex constraints on the signatures.  It's why with Bitcoin you can do multisig-- but for GPG and whatnot, you can't really (technically it could be done, but would need complex MPC crypto which no one implements).

Sometimes you want to sign messages with bitcoin addresses, e.g. to have the operator of an address attest to something.

If you're going to do that and support all addresses, then you need to use Bitcoin script to do it. In doing so, you pick up some of the structure that goes around script-- some of which may not be as useful outside of the blockchain.

So I don't think anyone particularly wants to use the bitcoin core code base-- but rather they want a signmessage that works for all Bitcoin addresses.

1 - Why was it chosen to prepend the scriptPubKey (when not P2PKH) to the preimage? To me, this adds unnecessary complexity which will slow down the adoption of BIP 322 by bitcoin libraries.
I'm not sure, but I could speculate:

Because that's how signing works in Bitcoin so it should make it simpler for existing code. Also signatures generally must commit to their public keys or weird vulnerabilities crop up where you think you're signing with one key, but you're really signing for a related key.
pooya87
Legendary
*
Offline Offline

Activity: 3486
Merit: 10641



View Profile
July 12, 2020, 06:50:05 AM
 #4

Bitcoin uses a novel cryptosystem for signing transactions called Bitcoin Script which allows all sorts of complex constraints on the signatures.
each implementation of bitcoin should have a way of producing and verifying ECDSA signatures and work with scripts to some extent (usually standard ones only) but they don't have to have the flags used in bitcoin core specially when it comes to message verification. for example none of these exist in SPV clients such as Electrum so their code has to significantly change if they wanted to implement this I.P.:
Verifying
Verify a proof, given a standard flags value, a script sig, an optional witness, and a derived sighash as described above.
1. Verify Script with flags=consensus flags (currently P2SH, DERSIG, NULLDUMMY, CLTV, CSV, WITNESS), scriptSig=script sig, scriptPubKey=scriptPubKey, witness=witness, and sighash=sighash
3. Verify Script with flags=standard flags (above plus STRICTENC, MINIMALDATA, etc.), scriptSig=script sig, scriptPubKey=scriptPubKey, witness=witness, and sighash=sighash
also these flags are used during block verification and most of them are there for backward compatibility (eg. whether BIP-66 is enabled to use DERSIG or BIP-112 for OP_CSV), i don't see why they should be used in a message signature verification.

not to mention that certain things from bitcoin scripts can not even be imported into message verification. some are addressing malleability issues, some OP codes such as those involving locktimes cause a lot of problems as there is no transaction or block to use for verification, the "signature" that is popped from the stack in transaction during script evaluation has a sighash flag which makes no sense in a message since there is no txout/ins to sign based on that,...

So I don't think anyone particularly wants to use the bitcoin core code base-- but rather they want a signmessage that works for all Bitcoin addresses.
then the proposal could have been a lot simpler or even expand on BIP-137 instead.
for instance as i said above there is no reason to use "witness" in a message signature from a bitcoin address since we are not producing a transaction and backward compatibility of SegWit is not needed here.

take P2PKH and P2WPKH, both of them are the exact same thing there is a pubkey that is hashed using HASH160 and there is a signature that matches that pubkey. in a transaction it makes a difference when creating the hash digest for verification and where the "stack items" are placed, but it is the same when verifying a message.
same with P2SH and P2WSH.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
gmaxwell
Moderator
Legendary
*
expert
Offline Offline

Activity: 4200
Merit: 8440



View Profile WWW
July 12, 2020, 07:48:48 AM
 #5

each implementation of bitcoin should have a way of producing and verifying ECDSA signatures and work with scripts to some extent (usually standard ones only) but they don't have to have the flags used in bitcoin core specially when it comes to message verification. for example none of these exist in SPV clients such as Electrum so their code has to significantly change if they wanted to implement this I.P.:

SPV clients don't verify transactions-- they can't because they don't have access to scriptpubkeys.   This means that I wouldn't expect SPV clients to already contain the relevant code.

Quote
also these flags are used during block verification and most of them are there for backward compatibility (eg. whether BIP-66 is enabled to use DERSIG or BIP-112 for OP_CSV), i don't see why they should be used in a message signature verification.


Yucky for the spec to be described in terms of those flags which are presumably not adequately documented.

But the behaviour they signify has to be handled correctly to use generic Bitcoin addresses to process messages.

Quote
not to mention that certain things from bitcoin scripts can not even be imported into message verification. some are addressing malleability issues, some OP codes such as those involving locktimes cause a lot of problems as there is no transaction or block to use for verification, the "signature" that is popped from the stack in transaction during script evaluation has a sighash flag which makes no sense in a message since there is no txout/ins to sign based on that,...
The strategy there should be to operate with a dummy, and the spec should be describing it that way.

Quote
take P2PKH and P2WPKH, both of them are the exact same thing there is a pubkey that is hashed using HASH160 and there is a signature that matches that pubkey. in a transaction it makes a difference when creating the hash digest for verification and where the "stack items" are placed, but it is the same when verifying a message.
same with P2SH and P2WSH.

That sounds like just falling into the same trap of only supporting an absurdly narrow subset of keys users use which then stands in the way of new use cases.  I think that's just a total waste of time, and actually harmful for the industry.

For example, there have been users that refused to change to multisig-- when they could have otherwise used it,  because they couldn't signmessage with it and they'd adopted some workflow that required them to signmessage with their addresses.  The old signmessage format has turned out to be a boat anchor that has actually slow the adoption of new techniques and better security in Bitcoin.  In hindsight, I think we made a mistake in ever implementing it in the first place.

There is certainly a place in the world for message signing systems that are simpler and less -- well-- weird than Bitcoin script but for those you should use something like PGP or signify.

And I don't intend to defend the BIP322 specifics -- only the general motivation of using script so that you can sign with arbitrary addresses.

It's not done that way because the authors wanted to use some bitcoin core internals, it's that way because its intended to be a generic mechanism that works for _every_ address, unconditionally, even ones that aren't widely in use right now-- and can be easily extended as bitcoin's consensus rules are. The easiest way to do that is to use a bunch of bitcoin internals, but it sounds like it's currently resulting in an unclear spec. -- apparently unclear enough that it didn't make its motivation and justifications clear enough.

Inherently though, anything generic is going to be more work to support for something that doesn't actually support verifying bitcoin signatures.  There really isn't any way around that-- but fortunately no one is required to implement it!
andytoshi
Full Member
***
Offline Offline

Activity: 179
Merit: 151

-


View Profile
November 28, 2020, 09:11:06 PM
 #6

tiagocs, pooya87, I think it's important that BIP322 work with arbitrary scripts, for the reasons that gmax has stated. But I also agree that BIP322 is written currently to require very heavy machinery (basically, linking to libbitcoinconsensus to do absolutely anything, and goes out of its way to expose sharp edges of Script. For example, allowing non-low-S signatures and then requiring verifiers to mark this as "inconclusive" appears to serve no purpose.

I wonder if you would support a version of BIP322 which:

1. Required all standardness rules be obeyed (and allowed as an "extension" to validate such signatures, somewhere cordoned off at the end of the BIP where nobody needs to see it)
2. Specified what these standardness rules were/meant
3. Allowed implementations to return "inconclusive" for scripts they did not understand, while still permitting them to implement only templates if they really want.
4. Cleaned up the prose a bunch

The first two rules would let you use off-the-shelf Minscript software (such as this implementation in Python to support all widely used scripts except HTLCs, so even if you did not write a full BIP-322 verifier (which would require libbitcoinconsensus or Core) you would still be able to support a wide array of real-world usecases.
pooya87
Legendary
*
Offline Offline

Activity: 3486
Merit: 10641



View Profile
November 29, 2020, 06:48:34 AM
 #7

tiagocs, pooya87, I think it's important that BIP322 work with arbitrary scripts, for the reasons that gmax has stated.
I never disagreed with that, in fact that's the whole point of the new BIP.

Quote
But I also agree that BIP322 is written currently to require very heavy machinery
The part I always had an issue with was that the BIP was tightly coupled with bitcoin core and was treating message signatures as transactions instead of just focusing on scripts. However the BIP was changed some time ago after we discussed it here.

Quote
I wonder if you would support a version of BIP322 which:
A good BIP for message signing would be a BIP that focuses on answering this question: How does other implementations of bitcoin sign/verify messages with our proposal. For example how should Electrum implement BIP322 without needing to add new libraries (dependencies)?

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
andytoshi
Full Member
***
Offline Offline

Activity: 179
Merit: 151

-


View Profile
December 18, 2020, 03:29:29 PM
Merited by NotATether (1)
 #8

I have proposed a rewrite of BIP-322 on the ML:

https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2020-December/018313.html

Full text (also included in the ML post, but rendered here)

https://github.com/apoelstra/bips/blob/2020-12--bip322-overhaul/bip-0322.mediawiki
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!