64 bit arithmetic soft fork

Posted by Chris_Stewart_5

Feb 28, 2024/14:12 UTC

The implementation of OP_INOUT_AMOUNT in Bitcoin as explored involves several intricate steps to handle satoshi values within transaction scripts. Initially, an int64_t value representing satoshis is retrieved from the BaseTransactionSignatureChecker.GetTransactionData() function. This value is then converted into a minimally encoded CScriptNum, a process that doesn't necessarily require a separate opcode but can be executed within the OP_INOUT_AMOUNT implementation itself.

A significant adjustment is made by modifying the nMaxNumSize parameter in the CScriptNum constructor to accommodate 8 bytes instead of the previous limit, allowing for the handling of larger numeric values pertinent to Bitcoin transactions (modification reference). Following this adjustment, the CScriptNum is pushed onto the stack for subsequent use.

However, challenges arise when other opcodes consume the satoshi value at the stack's top, necessitating a mechanism to support an nMaxNumSize of 8 bytes. This requirement stems from the historical limitation where numeric opcodes interpreted CScriptNum with a nMaxNumSize of only 4 bytes, leading to potential overflow exceptions. An example of such an overflow exception can be found in the codebase (overflow exception reference). The issue extends to any opcode that utilizes CScriptNum to interpret stack top values, including OP_WITHIN, indicating a broader impact on script processing and necessitating careful consideration in the implementation of OP_INOUT_AMOUNT to avoid these pitfalls.

Link to Raw Post

Thread Summary (52 replies)

Jan 10 - Jun 20, 2024

Bitcoin Logo

TLDR

Join Our Newsletter

We’ll email you summaries of the latest discussions from authoritative bitcoin sources, like bitcoin-dev, lightning-dev, and Delving Bitcoin.

Explore all Products

ChatBTC imageBitcoin searchBitcoin TranscriptsSaving SatoshiBitcoin Transcripts Review
Built with 🧡 by the Bitcoin Dev Project
View our public visitor count

We'd love to hear your feedback on this project?

Give Feedback