delvingbitcoin

PoC: Fix fee bypass bug using OP_CHECKTEMPLATEVERIFY

PoC: Fix fee bypass bug using OP_CHECKTEMPLATEVERIFY

Original Postby 40000bytes

Posted on: January 25, 2024 17:32 UTC

HodlHodl, a peer-to-peer (P2P) trading platform, leverages a 2-of-3 multisig setup for its transactions, ensuring that each trade generates a new multisig address derived from the public keys of the buyer, seller, and HodlHodl itself.

Each party has the ability to coordinate during trades, with the possibility of transferring the locked bitcoin without incurring fees from HodlHodl. To facilitate this process, an open-source tool is available at escrow_extractor. Detailed specifications of HodlHodl's multisig contracts can be found in their contract specification, and they utilize the OP_CHECKTEMPLATEVERIFY (CTV) function as outlined in the OP_CHECKTEMPLATEVERIFY documentation.

The transactional process involves the seller funding a CTV address with bitcoin, which can only be spent on two addresses: the 2-of-3 multisig or HodlHodl's own address. An example of such a transaction can be seen at this mempool link. Following this, the seller provides both the buyer and HodlHodl with an unlock_tx hex. When the buyer confirms payment through the seller's bank account, they broadcast the unlock_tx, resulting in the deduction of HodlHodl's trading fee and securing the remaining amount in the 2-of-3 multisig address. An example of this step can be viewed at another mempool transaction. The multisig can then be unlocked using two out of the three keys, allowing the transfer of the bitcoin to the buyer. In any dispute scenario, HodlHodl holds the deciding power to either return the funds to the seller or release them to the buyer.

An alternative to this method would be employing a 3-of-3 multisig; however, this would create a custodial situation, meaning users would not be able to access their bitcoins if HodlHodl were to become non-operational. The use of OP_CHECKTEMPLATEVERIFY is crucial as it ensures that HodlHodl receives its fee for every trade conducted on the platform. Although the current system serves as a proof of concept, there is potential for further optimization.

The concept and implementation have been recognized through acknowledgments to individuals and entities like Jeremy Rubin, HodlHodl, and katsu. These contributions highlight the collaborative effort behind developing secure and efficient mechanisms for facilitating bitcoin trades.