strange case of Bitcoin scripts and complement two
As for cryptocurrencies, such as Bitcoin, the basic technology has been designed to be effective and scalable. However, a special problem was observed in the way of coding of bitcoin scripts, especially when it comes to the arithmetic consequence of the complement.
In this article, we will deepen in the world of Bitcoin scripts and examine why it is not in line with the method of coding the entire standard, such as rust or C-Stil compliment.
signs size coding
The numbers of Bitcoin scripts use a coding scheme for signs, which is similar to how to represent numbers in binary numbers. The idea is to encode the sign (0 for positive, 1 for negative) and the size of each byte using the decimal representation. This approach allows storage and efficient transmission of large amounts of data.
The size marking diagram assigns a unique code point for each byte value from 0 to 255, representing a positive or negative number. The size is determined by the first 7 bits of byte (i.e. the last 3 bits). This coding method ensures that all possible values are represented exactly once.
Aritmetics of Amplement of Two **
On the other hand, programming languages, such as rust, use the arithmetic of two additions to represent signed numbers. In addition to the second bit position, it is used to determine the value of the whole (0 or 1). The most significant bit represents the sign, while the other bits indicate size.
Rust format for the representation of signed numbers, the Hex representation, follows this convention: 0x ...
where...
represents the hexadecimal number. This coding scheme enables compact memory and transmission of large numbers.
problem with bitcoin scripts
As for the Bitcoin script numbers, they do not follow the coding scheme of the sizes used in arithmetic of the arithmetic of rust or style. Packed bytes. “
In coding packed bytes, each 4 -bit block is represented by a single byte, which contains both size and its sign. This enables efficient storage and transmission of large amounts of data.
However, this pattern is not in line with the method of encoding the entire signed signal, such as the complementary rust arithmetic or C-Styl C. The reason is how the Bitcoin protocol has been designed to be compatible with systems. existing.
Why does it matter?
Although the difference may seem small, it is necessary to understand why this problem matters:
* Compatibility at the back : Bitcoin has been designed to work perfectly with other systems that use two complementary arithmetic. Without observing the method of coding the standard number, the number of Bitcoin scripts is less compatible with these systems.
* Safety : Using bytes packed in Bitcoin can introduce gaps in security if it is not implemented correctly. For example, the attacker can use weaknesses in the packaging scheme to operate or theft of confidential data.
Application
To sum up, while the numbers of Bitcoins scripts do not comply with the method of encoding the entire standard, such as the complementary rust or style arithmetic, it is a deliberate selection of the project, made by a team of Bitcoin protocols, ensures compatibility to return to existing systems. Understanding this problem can provide valuable information about the functioning of the interior of the Bitcoin protocol and may emphasize the importance of taking into account security and compatibility when designing cryptographic protocols.
Update:
In 2017, the basic Bitcoin deposit introduced changes to implement a more coherent signed coding scheme on all letters.