spesmilo / electrum

Electrum Bitcoin Wallet
https://electrum.org
MIT License
7.45k stars 3.09k forks source link

[Suggestion] Native p2sh segwit wallet #3283

Closed AbdussamadA closed 6 years ago

AbdussamadA commented 6 years ago

Hi

No other wallet supports bech32 addresses. Even Sipa, the creator of bech32, is of the opinion that there is no hurry in introducing bech32 support in bitcoin Core: https://bitcoin.stackexchange.com/a/52447/5273 . Given all of this wouldn't it be a good idea to have a native electrum wallet type that does p2sh segwit addresses? Otherwise we can't really use segwit wallets in electrum.

If electrum were to add support for this segwit could be the default type for new wallets because all wallets support p2sh addresses. The wallet creation process could be simplified and the whole segwit vs. standard step could be removed.

ecdsa commented 6 years ago
  1. "native p2sh" does not make sense. segwit addresses are either native or p2sh.
  2. p2sh-segwit scripts are wasting blockchain space.
  3. Bitcoin Core has merged bip173 (bech32 addresses)
  4. Wallets/exchanges do not need to support segwit, in order to let their users send/withdraw to bech32 addresses. While adding full segwit support is complicated, adding the functionality of sending to bech32 addresses is trivial. The only reason they do not do it at this point is lack of user demand.
  5. Whatever Pieter used to think in March, I believe we are in a hurry now. The effect of transaction size on the size of the memory pool and on fees is highly nonlinear, because of accumulation and effects and sticky price estimates.

Native segwit wallets will be default in Electrum as soon as there is reasonable support from other exchanges and wallets, and the whole segwit vs standard step will be removed, without wasting blockchain space and without requiring two wallet upgrades from our users.

neocogent commented 6 years ago

I'll second this.

Or, as an alternative that may help people use native segwit: I may be wrong, but it's my understanding that for every bech32 address there is an equivalent p2sh address encoding. If that's true then why not have a right-click address item that can provide the 3xxx equivalent address so people can send to that and receive it on their bc1 address? I think it may require scanning both addresses types for txs, and that is an extra burden, but it could flag the ones that had p2sh addresses created so that only they need double scanning, or it could just be something the server does natively and the wallet only needs to know how to handle it when given p2sh tx data.

I seriously don't know why the choice was made to only support native Segwit when the whole Bitcoin space is trying to get transition to occur. This ticket was just closed - so is it a "soft spot" for Electrum devs? Is there some reason that a more useful handling of Segwit cannot be made available?

ecdsa commented 6 years ago

@neocogent no there is no such thing as an equivalent p2sh address. Native and p2sh addresses map to different types of scripts.

neocogent commented 6 years ago

Sure, but when a tx with a p2sh script that has an address matching an equivalent bech32 address arrives it can be handled by Electrum as a p2sh tx just like one to a BIP39 wallet. The address encoding is only a way of detecting that it is for your wallet.

What I mean is: someone sends a tx to the 3xxx address using a p2wpkh-p2sh script. Electrum can handle that as it does it fine for BIP39 wallets. It only needs to know that it is for this wallet. So it re-encodes the bech32 address as the p2sh address. I believe the private key can sign and spend an output from either of those two scripts because the address is just an encoding of the corresponding public key.

ecdsa commented 6 years ago

@neocogent no that is not correct. there is no "equivalent bech32 address"

neocogent commented 6 years ago

For every private key is there not a p2wpkh-p2sh output and a p2wpkh output that it could sign?

ecdsa commented 6 years ago

that would not achieve what you describe. you cannot re-encode bech32 addresses as p2sh addresses, because your funds will not follow.

SomberNight commented 6 years ago

For every private key is there not a p2wpkh-p2sh output and a p2wpkh output that it could sign

Yes, that is correct. Those are different scripts, and hence different outputs though. So it is NOT the case that there is a base58 "3..." address and a bech32 "bc1..." address for the same output; rather you can derive two different outputs, one with a base58 "3..." address, and one with a bech32 address. We don't want to monitor two different types of scripts for every derivation though.

Raulo commented 6 years ago

@ecdsa,

I'm afraid the biggest obstacle with bech32 adoption is the lack of BIP39 standard for BIP173 wallets. You can create one in Electrum but you cannot move it anywhere. And importing of private keys does not work, either. It has to be standardized immediately or the use will not pick up.

I can see in the code that you can actually use Ledger with bech32 (if you modify the source a little, Electrum has the code to support it and the firmware is bech32-aware, except that the p2wsh addresses are cut in the display but work). But I don't want to create a non-interoperable wallet.

AbdussamadA commented 6 years ago

By native i meant a native electrum seed that created a p2sh segwit wallet. Right now people are restoring from bip39 to get that feature in electrum!

Of course it is @ecdsa prerogative. I just wanted to clarify what I meant.

neocogent commented 6 years ago

I know I've tested BIP39 segwit in Electrum with outside creation, and a lot of others are discussing it. I'd be worried that you start to get a lot of users who are using questionable seed creation methods (maybe online) to use Electrum as a BIP39 wallet for Segwit regardless of it being the best possible route forward. And it would be better if they were making native Electrum seeds in the program as it's safer and the wallet is more future proof.

ecdsa commented 6 years ago

That's fine with me. I want to favor a fast transition of the bitcoin ecosystem to native segwit, because I believe it is urgent. It is trivial for exchanges to support withdrawal to native segwit addresses, but they will not do it without user pressure. (the hard part will be to support deposits with segwit addresses, because it means that they need to run a segwit wallet internally, but that is their problem)

ecdsa commented 6 years ago

Someone should set up a list of Exchanges that support withdrawal to native segwit addresses. Electrum will be happy to advertise it.

shtirlic commented 6 years ago

Is it possible to convert Bech32 address to original P2PKH and make payment to it, will electron accept this transaction?

ecdsa commented 6 years ago

@shtirlic no

shtirlic commented 6 years ago

Is it possible to recover P2PKH from new WIF private key, as I understand that common keyhash is RIPEMD160(SHA256) of a compressed public key, and it should be possible ?

shtirlic commented 6 years ago

Actually I managed to get the private key and imported it back to electrum and transaction appeared

  1. Export new WIF key
  2. Via tools decoded it and changed version 81 to 80
  3. Generated new WIF key and imported in Electrum
ecdsa commented 6 years ago

@shtirlic what is the point of doing that?