OP_AMOUNT Discussion



Summary:

In a recent post, Jeremy Rubin shared some preliminary thoughts on OP_AMOUNT. The opcode could come in several variants such as OP_PUSHAMOUNT, OP_AMOUNTVERIFY, OP_PUSHAMOUNTSPLIT and OP_SPLITAMOUNTVERIFY. If they want to do a NOP upgrade, the *VERIFY formats can be preferred while if they want to do a SUCCESSX upgrade, the PUSH format can be used. The SplitAmount format is required because amounts are > 5 bytes (51 bits needed max), unless we also do some sort of OP_UPGRADEMATH semantic whereby presence of an Amount opcode enables 64 bit (or 256 bit?) math opcodes.The OP_AMOUNT opcode has several use cases, for instance, it can be used to create a non-recursive covenant that there must be an output which exactly matches the sats in the input at the same index. This could be used for colored coins, statechains, TLUV/EVICT based payment pools, etc. It is also useful in making a static address / descriptor that disables low-security spends if more coins are the input. Another use case could be to enable pay-what-you-want options, where depending on how much gets paid into an address different behaviors are permitted. Lastly, as noted in BIP-119, you can make a belt-and-suspenders value check in CTV contracts to enable a backup withdrawal should you send the wrong amount to a vault.Jeremy Rubin suggests that the most straightforward path would be to work only on tapscript and not legacy, then spec out upgraded math operations, and then use OP_PUSHAMOUNT, which is pretty straightforward & low technical risk. However, upgraded math and exact semantics are highly bikesheddable. Blockstream liquid has some work in this regard that may be copyable for the math part, but likely not the amount opcode. They chose to do only 64 bit arithmetic, but the community might prefer wider operations. Jeremy Rubin designed some logic for a split amount verifying opcode, which can be found at https://gist.github.com/JeremyRubin/d9f146475f53673cd03c26ab46492504. He also mentions that he would be happy to review/advise on this if anyone is interested in working on this.


Updated on: 2023-05-22T18:11:33.523049+00:00