Skip to content

Commit

Permalink
Merge bitcoin-core/gui#808: Change example address from legacy (P2PKH…
Browse files Browse the repository at this point in the history
…) to bech32m (P2TR)

c6d1b8d gui: change example address from legacy (P2PKH) to bech32m (P2TR) (Sebastian Falbesoner)

Pull request description:

  Legacy addresses are less and less common these days and not recommended to use, so it seems senseful to also reflect that in the example addresses and update to the most recent address / output type (bech32m / P2TR). Also, as I couldn't see any value in computing these at runtime, they are pre-generated. This was done with the following Python script, executed in `./test/functional` (it's also included in the commit body, though without the she-bang):
  ```python
  #!/usr/bin/env python3
  from test_framework.segwit_addr import CHARSET, decode_segwit_address, encode_segwit_address
  from test_framework.messages import sha256

  output_key = sha256(b'bitcoin dummy taproot output key')
  for network, hrp in [('mainnet', 'bc'), ('signet', 'tb'), ('testnet', 'tb'), ('regtest', 'bcrt')]:
      dummy_address = encode_segwit_address(hrp, 1, output_key)
      while decode_segwit_address(hrp, dummy_address) != (None, None):
          last_char = CHARSET[(CHARSET.index(dummy_address[-1]) + 1) % 32]
          dummy_address = dummy_address[:-1] + last_char
      print(f'{network:7} example address: {dummy_address}')
  ```

  Note that the last bech32 character is modified in order to make the checksum fail.

  master (mainnet):

  ![image](https://github.com/bitcoin-core/gui/assets/91535/8c94cc1e-5649-47ed-8b2d-33b18654f6a2)

  PR (mainnet):

  ![image](https://github.com/bitcoin-core/gui/assets/91535/1ce208a6-1218-4850-93e0-5323c73e9049)

ACKs for top commit:
  maflcko:
    lgtm ACK c6d1b8d
  pablomartin4btc:
    tACK c6d1b8d

Tree-SHA512: a53c267a3e0d29b9c41bf043b123e7152fbf297e2322d74ce047ba2582b54768187162d462cc334e91a84874731c2e0793726ad44d9970c10ecfe70a1d4f3f1c
  • Loading branch information
hebasto committed Apr 18, 2024
2 parents aaab5fb + c6d1b8d commit c05c214
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/qt/guiutil.cpp
Expand Up @@ -109,22 +109,26 @@ QFont fixedPitchFont(bool use_embedded_font)
return QFontDatabase::systemFont(QFontDatabase::FixedFont);
}

// Just some dummy data to generate a convincing random-looking (but consistent) address
static const uint8_t dummydata[] = {0xeb,0x15,0x23,0x1d,0xfc,0xeb,0x60,0x92,0x58,0x86,0xb6,0x7d,0x06,0x52,0x99,0x92,0x59,0x15,0xae,0xb1,0x72,0xc0,0x66,0x47};

// Generate a dummy address with invalid CRC, starting with the network prefix.
// Return a pre-generated dummy bech32m address (P2TR) with invalid checksum.
static std::string DummyAddress(const CChainParams &params)
{
std::vector<unsigned char> sourcedata = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
sourcedata.insert(sourcedata.end(), dummydata, dummydata + sizeof(dummydata));
for(int i=0; i<256; ++i) { // Try every trailing byte
std::string s = EncodeBase58(sourcedata);
if (!IsValidDestinationString(s)) {
return s;
}
sourcedata[sourcedata.size()-1] += 1;
}
return "";
std::string addr;
switch (params.GetChainType()) {
case ChainType::MAIN:
addr = "bc1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tq2jku9f";
break;
case ChainType::SIGNET:
case ChainType::TESTNET:
addr = "tb1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqa6qnlg";
break;
case ChainType::REGTEST:
addr = "bcrt1p35yvjel7srp783ztf8v6jdra7dhfzk5jaun8xz2qp6ws7z80n4tqsr2427";
break;
} // no default case, so the compiler can warn about missing cases
assert(!addr.empty());

if (Assume(!IsValidDestinationString(addr))) return addr;
return {};
}

void setupAddressWidget(QValidatedLineEdit *widget, QWidget *parent)
Expand Down

0 comments on commit c05c214

Please sign in to comment.