delvingbitcoin

64 bit arithmetic soft fork

64 bit arithmetic soft fork

Original Postby ajtowns

Posted on: January 15, 2024 04:22 UTC

In the realm of Bitcoin script encoding, there appears to be some confusion regarding the endianness of CScriptNum.

The individual raising the concern suggests that the current encoding system is minimal-length big-endian, which offers the benefit of a more compact representation for literals within scripts compared to a fixed-length constant. However, this perspective is challenged by another view that points out CScriptNum is actually little endian. Supporting evidence for this assertion is found in both the Bitcoin codebase, specifically at a particular segment of the script header file on GitHub, and the definition of endianness as outlined in Wikipedia. Additionally, the Bitcoin wiki corroborates the little-endian nature of CScriptNum.

The core of the discussion hinges on two main differences between the existing CScriptNum implementation and the proposed alternative. The first difference is the method of encoding: CScriptNum employs variable-length encoding while the proposal suggests a fixed length. The second contrast lies in the handling of negative numbers; CScriptNum uses a two's complement system whereas the proposed encoding considers using a sign bit. These distinctions are critical as they directly impact the efficiency and functionality of script processing in the Bitcoin network.