In recent years, the Bitcoin ecosystem has developed rapidly but still faces many technical challenges and bottlenecks. As the number of users and transaction volumes increase, issues related to the efficiency, privacy, and flexibility of the Bitcoin network have become more prominent. To address these issues, the Bitcoin community introduced Bitcoin Improvement Proposals (BIPs) to add new features and improvements to the Bitcoin network.
At the end of 2021, Bitcoin underwent the Taproot upgrade, aiming to significantly enhance Bitcoin's performance and user experience. The Taproot upgrade is a collection of three BIPs, including Schnorr Signatures (BIP 340), Taproot (BIP 341), and TapScript (BIP 342), collectively known as BIP Taproot.
The principle of Taproot is to define an output and two spending paths. As illustrated above, with two participants, Alice and Bob, the Taproot operation process is as follows:
When spending in signature mode, multiple participants and single participants appear indistinguishable on the blockchain, making many blockchain analyses ineffective and preserving privacy for all Taproot users. The script spending mode of Taproot provides a solution for cases where some signers cannot or refuse to sign, allowing participants to complete transactions through predefined conditions and script paths. This way, even if not all signers agree to the transaction, the remaining participants can still spend according to preset conditions.
The Huffman Tree, proposed by David Huffman in 1952, is an optimal binary tree used for data compression. Its main application is in the field of data compression, such as file compression and image compression. It achieves data compression by assigning shorter codes to frequently occurring characters and longer codes to less frequent characters.
The Huffman Tree is the tree with the shortest weighted path length, where nodes with larger weights are closer to the root, and nodes with smaller weights are farther from the root. Its construction process uses a greedy approach, selecting the two nodes with the smallest weights each time to combine into a new node, adding it to the original set, and repeating the process until completion. As illustrated above, with a weight set of (1, 2, 3, 4, 5), the Huffman Tree construction process is as follows:
Compared to ECDSA (Elliptic Curve Digital Signature Algorithm), a major advantage of Taproot is that Schnorr aggregate signatures can compress multiple signature data into a single aggregate signature. After using aggregate signature technology, the byte size of the transaction script is significantly reduced, effectively lowering the transaction fees.
In signature mode, as the number of participants increases, the size of ECDSA transaction scripts grows linearly, while the size of Taproot transaction scripts remains unchanged. In script mode, as the number of scripts increases, the size of ECDSA transaction scripts grows linearly, while the size of Taproot transaction scripts grows logarithmically.
When spending in script mode, using the tree structure of MAST, the size of Taproot transaction scripts grows logarithmically with the number of scripts. However, by using the Huffman Tree, we can improve the construction process of MAST, helping to further reduce the byte size of witness scripts in script spending mode, ultimately achieving lower transaction fees.
As mentioned earlier, when spending in script mode with Taproot, proof of the script in MAST is required. As illustrated above, when we want to spend using script_A, the witness script needs to provide:
Ignoring the byte size of the first two items, it can be seen that the byte size of the last item can be represented as 32*(d-1), where d=3 represents the height of script_A in MAST. In other words, the byte size of the last item is linearly related to the height of the script in MAST. Therefore, for scripts script_A, script_B, and script_C, we can assign weights based on their usage frequency and construct a Huffman Tree. This can place frequently used scripts at lower heights, reducing the byte size of witness scripts and ultimately lowering transaction fees.
In summary, transaction fees are closely related to the byte size of transaction scripts.
The introduction of Taproot marks an important step forward for the Bitcoin network in terms of efficiency, privacy, and flexibility. By adopting new technologies such as Schnorr signatures, MAST, and TapScript, Taproot not only significantly reduces the byte size of transaction scripts and lowers transaction fees but also enhances user privacy. The strategy of using Huffman Tree to optimize MAST construction further reduces the byte size of witness scripts in script spending mode, providing Bitcoin users with a more efficient transaction experience.
Bitcoin Layer 2 solution BEVM uses Taproot as one of the core architectures of its "Taproot Consensus" technology, bringing explosive growth to the Bitcoin ecosystem. As these improvements gradually become widespread, the Bitcoin network will be able to handle larger-scale users and transaction volumes, providing global users with more secure and convenient encryption services.