BIP 350: Implement Bech32m and use it for v1+ segwit addresses (0.21 backport) #21469

pull sipa wants to merge 6 commits into bitcoin:0.21 from sipa:202103_bech32m_0.21 changing 16 files +750 −425
  1. sipa commented at 8:54 PM on March 18, 2021: member

    Backport of #20861. Also includes #21471.

  2. fanquake added the label Backport on Mar 18, 2021
  3. sipa force-pushed on Mar 18, 2021
  4. sipa renamed this:
    Implement Bech32m encoding/decoding (0.21 backport)
    BIP 350: Implement Bech32m and use it for v1+ segwit addresses (0.21 backport)
    on Mar 18, 2021
  5. jnewbery commented at 9:58 AM on March 19, 2021: member

    utACK 28b3a32060

    I repeated the backport myself and got the same result.

    You could also pick the rpc_invalid_address_message.py functional test, removing the precise error messages (which aren't returned in v0.21):

    <details> <summary>rpc_invalid_address_message.py</summary>

    #!/usr/bin/env python3
    # Copyright (c) 2020 The Bitcoin Core developers
    # Distributed under the MIT software license, see the accompanying
    # file COPYING or http://www.opensource.org/licenses/mit-license.php.
    """Test error messages for 'getaddressinfo' and 'validateaddress' RPC commands."""
    
    from test_framework.test_framework import BitcoinTestFramework
    
    from test_framework.util import (
        assert_equal,
        assert_raises_rpc_error,
    )
    
    BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'
    BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'
    BECH32_INVALID_BECH32M = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd'
    BECH32_INVALID_VERSION = 'bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk'
    BECH32_INVALID_SIZE = 'bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr'
    BECH32_INVALID_V0_SIZE = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kqqq5k3my'
    BECH32_INVALID_PREFIX = 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx'
    
    BASE58_VALID = 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn'
    BASE58_INVALID_PREFIX = '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem'
    
    INVALID_ADDRESS = 'asfah14i8fajz0123f'
    
    class InvalidAddressErrorMessageTest(BitcoinTestFramework):
        def set_test_params(self):
            self.setup_clean_chain = True
            self.num_nodes = 1
    
        def skip_test_if_missing_module(self):
            self.skip_if_no_wallet()
    
        def test_validateaddress(self):
            node = self.nodes[0]
    
            # Bech32
            info = node.validateaddress(BECH32_INVALID_SIZE)
            assert not info['isvalid']
    
            info = node.validateaddress(BECH32_INVALID_PREFIX)
            assert not info['isvalid']
    
            info = node.validateaddress(BECH32_INVALID_BECH32)
            assert not info['isvalid']
    
            info = node.validateaddress(BECH32_INVALID_BECH32M)
            assert not info['isvalid']
    
            info = node.validateaddress(BECH32_INVALID_V0_SIZE)
            assert not info['isvalid']
    
            info = node.validateaddress(BECH32_VALID)
            assert info['isvalid']
            assert 'error' not in info
    
            # Base58
            info = node.validateaddress(BASE58_INVALID_PREFIX)
            assert not info['isvalid']
    
            info = node.validateaddress(BASE58_VALID)
            assert info['isvalid']
            assert 'error' not in info
    
            # Invalid address format
            info = node.validateaddress(INVALID_ADDRESS)
            assert not info['isvalid']
    
        def test_getaddressinfo(self):
            node = self.nodes[0]
    
            assert_raises_rpc_error(-5, "Invalid address", node.getaddressinfo, BECH32_INVALID_SIZE)
    
            assert_raises_rpc_error(-5, "Invalid address", node.getaddressinfo, BECH32_INVALID_PREFIX)
    
            assert_raises_rpc_error(-5, "Invalid address", node.getaddressinfo, BASE58_INVALID_PREFIX)
    
            assert_raises_rpc_error(-5, "Invalid address", node.getaddressinfo, INVALID_ADDRESS)
    
        def run_test(self):
            self.test_validateaddress()
            self.test_getaddressinfo()
    
    
    if __name__ == '__main__':
        InvalidAddressErrorMessageTest().main()
    

    </details>

  6. MarcoFalke commented at 7:24 AM on March 22, 2021: member

    cherry-pick-only ACK 28b3a3206097b89c7cf5f510e83f6027324b51c8 did not review code nor test 👓

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    cherry-pick-only ACK 28b3a3206097b89c7cf5f510e83f6027324b51c8 did not review code nor test 👓
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUjqXwwAgZwS8RcAWCviu1/EEdYDtAtrYxN5lH74nOV564EM+1VVLdhd+vfoI1Yh
    fDziALpjLgqDKAOV1ItgX974pfR9Tf8ZUfrAMJc9Gh4e9qfQwu2xxNOnQ7ULNs48
    GMpYyebKhtl+1Srh5R/Edfb3wrOQ4DBUIuflq5sReYsqOlmNTPTm9nt5Fj174he5
    wmNn0z2NER7ROsB5fVtUNuRVVjNmfPkukUpkUs0qJb42oYWUgG6UyMksB7I0MmkK
    3mQO6eYa/Rmh2fZdwoN/agS5uKvPumv51mXg8AXBoOAEtndw+lpZlSbZIsiC4+yY
    LZbbQdM3DzJSstQtqqrQPyTZ9NwXjYpJIlQpTUru4a0XkDHsm+fF6Yf4YWLbA3qz
    L2JnGOLJmHwrhYMkykB5XyAAhbsBV9DYzsu0T7fK8aDuJpqKsYOvZu3zie+G/KcK
    gqxK3T16pqfWqtgBslOZ/BZ6Lykk6/zcMkDI+fSC3Zv0XVyohMLuEiH3431PZsz+
    OSp9T+Dy
    =z0EU
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash f15d8f2dd34efe4f3f1fb17b1645f6fb3541a505d0c1a3d25a6c888cd487a5f9 -

    </details>

  7. sipa commented at 8:45 AM on March 24, 2021: member

    @jnewbery Added a commit that does that.

  8. laanwj added this to the milestone 0.21.1 on Mar 24, 2021
  9. jnewbery commented at 7:46 PM on March 25, 2021: member

    Oops. Sorry. I think the linter is failing because of an unused import:

    diff --git a/test/functional/rpc_invalid_address_message.py b/test/functional/rpc_invalid_address_message.py
    index 4626f62b0f..814f50c9e6 100755
    --- a/test/functional/rpc_invalid_address_message.py
    +++ b/test/functional/rpc_invalid_address_message.py
    @@ -6,10 +6,7 @@
     
     from test_framework.test_framework import BitcoinTestFramework
     
    -from test_framework.util import (
    -    assert_equal,
    -    assert_raises_rpc_error,
    -)
    +from test_framework.util import assert_raises_rpc_error
     
     BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'
     BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'
    
  10. sipa force-pushed on Mar 27, 2021
  11. sipa commented at 7:06 PM on March 27, 2021: member

    @jnewbery Thanks, fixed!

  12. Implement Bech32m encoding/decoding
    Github-Pull: #20861
    Rebased-From: da2bb6976dadeec682d163c258c9afecc87d6428
    1485533092
  13. Add Bech32m test vectors
    Github-Pull: #20861
    Rebased-From: 25b1c6e13ddf1626210d5e3d37298d1f3a78a94f
    8944aaa6d6
  14. Use Bech32m encoding for v1+ segwit addresses
    This also includes updates to the Python test framework implementation,
    test vectors, and release notes.
    
    Github-Pull: #20861
    Rebased-From: fe5e495c31de47b0ec732b943db11fe345d874af
    593e206627
  15. Add signet support to gen_key_io_test_vectors.py
    Github-Pull: #20861
    Rebased-From: 2e7c80fb5be82ad4a3f737cab65b31f70a772a23
    7dfe406e20
  16. naming nits
    Github-Pull: #20861
    Rebased-From: 03346022d611871f2cc185440b19d928b9264d9d
    1e9671116f
  17. Backport invalid address tests
    Reduced version of the test from master/#20861 by John Newbery.
    
    Github-Pull: #20861
    Rebased-From: fe5e495c31de47b0ec732b943db11fe345d874af
    f2195d7c4a
  18. sipa force-pushed on Mar 27, 2021
  19. sipa commented at 7:10 PM on March 27, 2021: member

    Updated to mention v0.21.1 in bips.md.

  20. jnewbery commented at 12:48 PM on March 28, 2021: member

    utACK f2195d7c4aa45f5168ec55b14406aeaf970adcb1

    Verified the range-diff. Only difference is the versions in bips.md and removing the unnecessary import in rpc_invalid_address_message.py.

  21. fanquake approved
  22. fanquake commented at 7:47 AM on March 31, 2021: member

    ACK f2195d7c4aa45f5168ec55b14406aeaf970adcb1 - performed the backport, changes look sane. Have not tested extensively.

  23. MarcoFalke commented at 10:33 AM on April 1, 2021: member

    cherry-pick re-ACK f2195d7c4aa45f5168ec55b14406aeaf970adcb1 , only change is version number in doc/bips and new test commit 🍝

    <details><summary>Show signature and timestamp</summary>

    Signature:

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512
    
    cherry-pick re-ACK f2195d7c4aa45f5168ec55b14406aeaf970adcb1 , only change is version number in doc/bips and new test commit 🍝
    -----BEGIN PGP SIGNATURE-----
    
    iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
    pUgENwwAh5tTK73Rq9Xgvnt3A3rDkdON3qGFcLPxyZfyEniRgkIpA/bjFwTbRr73
    sPw2fJLG3gZtvFLprSns0J+HxYWbBll+c1WWyBD/5Dct/qiDWDOi72E4O5HMD7L5
    h+hJunE/jIo5LizuG468HQdiPrqbcM3lUXhwH32ovG8oePLIaEo1CV8gTZpZMdWg
    mzW4JdjHVtf5q/zn3XKTOy6v7GoS9F/Z2/GbXAXkHuddU1c9sZtvkoEvGLjHsvPP
    QwaWLs0G9XJ7n7SZZPOrX/7TXoMn1klKRMydpwE3ZBl4pKgKRi7Dw2Ccvu9VTiJn
    +tVmKRJQS8KMgfZavoCMZ14R6EtloAuSAeOzWYOaKoPQ1KvfGUYumiXWFgWTQ3VC
    OJmvifun9GQmY4R25El9S2PRpfCmBRIpRDU8dNXfdOKO+6jnTXFMiHDVoZShJYx7
    u/iDzm3GsxdKbu7oQ/vFzF+4RcKdPhIUrxdWUZc3ZzHLxWSRxkjLG8YytmicaA+d
    hp61NnXE
    =y603
    -----END PGP SIGNATURE-----
    

    Timestamp of file with hash ba4c4b4eae9f449f1acbdb456b67bb75fc44f409fb63b3ab5b9c63aa98bb8190 -

    </details>

  24. MarcoFalke merged this on Apr 1, 2021
  25. MarcoFalke closed this on Apr 1, 2021

  26. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 09:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me