Bitcoin Cash has upgraded to 64-bit integers and now with the advent of CashTokens the BCH VM enables complex applications, this poses the need both for higher-order math and for allowing overflows in intermediate calculations.
Now, shortly after the CashTokens upgrade there are already multiple different Constant ProductMarket Maker (CPMM) contracts live on the network which carefully have to consider strategies for multiplication overflows. The composite aritmathic opcode op_muldiv
allows the intermediate calculation to overflow and hence simplifies the strategies dealing with overflows, leading to simpler, more efficient and more capable smart contracts.
Moreover, the introduction of op_muldiv
and op_mulmod
is a big step towards enabling emulation of higher precision math (uint126) in BCH contracts.
This proposal adds two new math opcodes to the Bitcoin Cash Virtual Machine (BCH VM), op_muldiv
and op_mulmod
.
op_muldiv
greatly simplifies contracts using 64-bit integer multiplication in intermediate calculations. These calculations currently fail on overflow so contract authors need to either restrict input ranges or use clever math workarounds which sacrifice precision.
op_muldiv
presents a clean alternative to this and together with op_mulmod
it paves the way for emulating higher precision math in BCH contracts.
Review and feedback are appreciated!