This article is a mirror article of machine translation, please click here to jump to the original article.

View: 259|Reply: 0

Detailed explanation of blockchain Base58, Base58Check, Bech32, and Bech32m coding

[Copy link]
Posted on 2025-10-17 09:01:55 | | | |
Base58, Base58Check, Bech32, and Bech32m are commonly used encoding formats in blockchain technology, primarily used to improve readability, reduce errors, and ensure data integrity. These four codes have their own advantages in ensuring security, compatibility, and error correction capabilities, and are important cornerstones of modern blockchain address systems.

Base58

"Base58" is an encoding method invented by Satoshi Nakamoto, which is adapted from a well-known encoding method "Base64". The Base64 character set includes: all numbers and uppercase and lowercase letters, as well as two symbols ("+" and "/"); A total of 64 characters. Satoshi Nakamoto removed the number 0, the uppercase letters I and O, the lowercase letter l, and the symbol, and it became Base58.

Character set: 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz



Base58Check

Compared to Base58, Base58Check encoding only has one more checksum computation. As shown below:



Base58Check solves the problems of error-prone, difficult to recognize, and unverified in traditional coding methods, providing a secure, compact, human-friendly, and error-detecting representation method for key data in the blockchain (such as addresses and private keys). Although it is now gradually being replaced by the more advanced Bech32/Bech32m (for SegWit addresses), it played a crucial role in the early Bitcoin ecosystem.

Bech32

"Bech32" is an encoding method defined by BIP 0173, which was authored by Pieter Wuille and Greg Maxwell. However, this coding also has its origins: "Bech" refers to "BCH", a cyclic error correction coding algorithm invented by three mathematicians in 1959 and 1960 respectively (the name BCH comes from the names of these three mathematicians). "32" means that the character set of the encoding method has only 32 characters: lowercase letters and numbers, excluding the numbers "1", the letters "b", "i" and "o".



At the beginning of BIP 0173, the authors point out the undesirable aspects of Base58:

  • Base58 uses both large and small case English letters, which makes its data drawn into QR codes not in the smaller "numeric alphabet" mode, but only in the larger "byte data" mode.
  • The use of both case and case also makes it difficult to transcribe, type and read on the phone keyboard.
  • The checksum required two consecutive SHA256 operations, which were slow and had no ability to locate the wrong placement.
  • Most localizable error encoding methods only work if the character set size is of prime power, and 58 is not a prime power.
  • Base58 is more complex to decode and slower to decode.

As a result, Bech32's new approach uses only lowercase letters and numbers; When needed, such as when drawing a QR code, these letters can all be replaced with capital letters for a more compact representation. Smaller QR codes, since Bech32 addresses are singular, you can encode them as QR codes using alphanumeric mode. This means you can create a more compact QR code because Base58 requires uppercase and lowercase letters (meaning you can't use alphanumeric mode), while Bech32 doesn't. As shown below:



As you can see, despite the Bech32 addressContains more characters, but the ability to use alphanumeric patterns means that QR codes use less data overall

At the same time, Bech32 has the ability to locate errors: it can not only find that you have made a copy error, but also point out which bits you have copied incorrectly (this ability to find errors is far superior to Base58).

In fact, the BCH algorithm also has an "error correction" function: it can not only indicate which bits you have copied incorrectly, but also what characters it should be. However, the authors of BIP 0173 found its inherent dangers: on the one hand, strengthening error correction weakens the ability to locate errors; On the other hand, if the user trusts too much in the software's error correction capabilities, the software may correct the erroneous data entered by the user into a "valid but useless" piece of data - although it is valid as a piece of BCH encoded data; However, it is possible that the restored Bitcoin script is not within the control of the recipient, or even anyone. This is extremely dangerous. Therefore, BIP 0173 cautions: "In addition to reminding users which bits may have been copied incorrectly, the software should not implement error correction capabilities (give correction suggestions)." ”

In addition, Bech32 follows the pattern found in Base58 encoding:

1. Bech32 data will start with a paragraph "data with meaning (hrp)", similar to the prefix in Base58, which can indicate what kind of data it is.
HRP can use far more than 32 characters; Bech32 also uses the number "1" as a separator to separate the HRP from the data that is actually to be decoded.
In addition to Bitcoin, there are many other projects that have also adopted Bech32; HRP is used to distinguish data from different items. Here's a list of registered HRPs, which is very interesting (but only interesting).
2. Bech32 also designed a checksum that occupies the last 6 characters of the encoded data.

Bech32m

"Bech32m" is an encoding method defined by BIP 0350. Link:The hyperlink login is visible.It was proposed because developers discovered a vulnerability in Bech32 coding:

When the last character is "p", inserting or removing any number of "q" in front of that character will not cause a checksum error (the data will still be considered valid), thenThe checksum mechanism completely loses its functionFinish.

If you don't add a standardized Bitcoin script, this problem can be easily solved: both the P2WPKH address and the P2WSH address have a certain length, just add the length check. However, considering that we will also be adding new standardized scripts in the future, the address length may change, so it is necessary to fix this issue.

Bech32m fixes this issue by changing a parameter in the Bech32 checksum generator.

Currently, Bech32m is only used to encode addresses for "P2TR" scripts that are added with the "Taproot" upgrade. It may be used in the address encoding of other standardized scripts in the future.

Reference:

The hyperlink login is visible.
The hyperlink login is visible.
The hyperlink login is visible.




Previous:tiktok, Douyin capture the package and kill the Frida script, which can locate the location of the SO file patch
Next:Introduction to Bitcoin address types Legacy, Nested SegWit, Native SegWit, and Taproot
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com