You mean P2WPKH?
Wait, P2WPKH stands for “Pay To Witness Public Key Hash” and an example is:
bc1qs9p7wkudkknd2u7p7rtmtxgpr9ca0z9wk6fl9y
P2WSH stands for “Pay To Witness Script Hash” and an example is:
bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3
Yes, my bad. P2WPKH is what I meant.
The scriptPubKey occupies 34 bytes, as opposed to 23 bytes of BIP16 P2SH. The increased size improves security against possible collision attacks, as 2^80 work is not infeasible anymore (By the end of 2015, 284 hashes have been calculated in Bitcoin mining since the creation of Bitcoin). The spending script is same as the one for an equivalent BIP16 P2SH output but is moved to witness.
So we have the witness script hash (P2WSH) and the witness public key hash (P2WPKH). This Bitcoin improvement proposal says that it will improve the security by increasing the size, from 160 bits to 256, because it'll be harder to find a collision. Isn't this a little ironic for the already existent address types? I'm trying to understand what's going on here, but it seems that I fail to.
If you increase the address size, then the transaction will also weight more, but it'll be more secure against a collision attack. But why did the developers change it to SHA256 since every other address type uses the HASH160? Making such announcement is like contending that HASH160 isn't strong
enough, but it is. The fact that they did it exclusively for P2WSH seems weird to me.
Nested Segwit (Multisig or not) is P2SH, not P2WSH. The standard is defined before we've decided on this and is different, there is no need to change that. There is no need for us to introduce a longer Segwit address for P2WPKH as well.
Question: Is there a P2WPKH corresponding to P2SH? Or if I didn't place it properly: An address type that is longer than P2SH, but starts with “3”?
You need to do so in the exact order. As you've said, the script is hashed and changing the order also changes the hash. That is why we rely on the redeem script.
Oh, okay, thanks. So electrum doesn't sort them ascendingly.