Skip to content

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

Merged
maflcko merged 6 commits into
bitcoin:0.21from
sipa:202103_bech32m_0.21
Apr 1, 2021
Merged

maflcko merged 6 commits into
bitcoin:0.21from
sipa:202103_bech32m_0.21

Conversation

@sipa

@sipa sipa commented Mar 18, 2021 •

Copy link
Copy Markdown
Member

Backport of #20861. Also includes #21471.

@sipa
sipa force-pushed the 202103_bech32m_0.21 branch from d520f73 to 28b3a32 Compare March 18, 2021 21:33
@sipa sipa changed the title Implement Bech32m encoding/decoding (0.21 backport) BIP 350: Implement Bech32m and use it for v1+ segwit addresses (0.21 backport) Mar 18, 2021
@jnewbery

Copy link
Copy Markdown
Contributor

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):

rpc_invalid_address_message.py
#!/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()

@gruve-p

gruve-p commented Mar 21, 2021

Copy link
Copy Markdown
Contributor

ACK 28b3a32

@maflcko

maflcko commented Mar 22, 2021

Copy link
Copy Markdown
Member

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

Show signature and timestamp

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 -

@sipa

sipa commented Mar 24, 2021

Copy link
Copy Markdown
Member Author

@jnewbery Added a commit that does that.

@laanwj laanwj added this to the 0.21.1 milestone Mar 24, 2021
@jnewbery

jnewbery commented Mar 25, 2021 •

Copy link
Copy Markdown
Contributor

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'

@sipa

sipa commented Mar 27, 2021

Copy link
Copy Markdown
Member Author

@jnewbery Thanks, fixed!

sipa and others added 6 commits March 27, 2021 12:09
Github-Pull: bitcoin#20861
Rebased-From: 25b1c6e
This also includes updates to the Python test framework implementation,
test vectors, and release notes.

Github-Pull: bitcoin#20861
Rebased-From: fe5e495
Github-Pull: bitcoin#20861
Rebased-From: 0334602
Reduced version of the test from master/bitcoin#20861 by John Newbery.

Github-Pull: bitcoin#20861
Rebased-From: fe5e495
@sipa
sipa force-pushed the 202103_bech32m_0.21 branch from 66009fc to f2195d7 Compare March 27, 2021 19:09
@sipa

sipa commented Mar 27, 2021

Copy link
Copy Markdown
Member Author

Updated to mention v0.21.1 in bips.md.

@jnewbery

Copy link
Copy Markdown
Contributor

utACK f2195d7

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

@fanquake fanquake left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@maflcko

maflcko commented Apr 1, 2021

Copy link
Copy Markdown
Member

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

Show signature and timestamp

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 -

@maflcko
maflcko merged commit 65fa43b into bitcoin:0.21 Apr 1, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants