PSBT Support via attaching assets to UTXOs #134
Replies: 6 comments 9 replies
-
We can employ Atomic Swaps to conduct trades without the need for trust. In this implementation of Atomic Swaps, we utilize the Partially Signed Bitcoin Transaction. We have the potential to expand it to include Lightning Network implementation, aiming to minimize friction.
What is the main purpose of this proposal? Does it seek to align Counterparty with a rival protocol, possibly granting it legitimacy? Considering Counterparty's substantial historical presence in the crypto space and its pioneering role in the NFT/cryptocurrency movement, Counterparty stands as a protocol that others should align with. It's important to avoid engaging with proponents of false narratives and individuals who have exhibited hostility towards Counterparty and XCP. |
Beta Was this translation helpful? Give feedback.
-
|
Clever and elegant. I love this. ❤️ |
Beta Was this translation helpful? Give feedback.
-
100% agree, this will truly benefit Counterparty! We need to be careful with the implementation though. If the UTXO is treated as an address format:
Maybe better introduce a separate message type only for this? Call it "UTXO Wrapper".
|
Beta Was this translation helpful? Give feedback.
-
Am I reading that right, or does Ordinals require a third-party to hold the data in a way that Counterparty wouldn't? Couldn't Ordinals do the same thing with an inscription? |
Beta Was this translation helpful? Give feedback.
-
|
I really like the idea! I think there are 3 very distinct and independent subjects here, each of which deserves particular attention.
We can decide to implement atomic swap without 2 and 3 in the same way that we can decide to implement UTXOs for asset ownership without atomic swap and/or PSBT. For atomic swap what is needed is a transaction signed by the buyer and the seller. For example: Inputs:
Outputs:
Once Counterparty supports this type of transaction we could stop there and leave it to the wallet developer to set up a process (centralized or not) to generate this type of transaction, for example using PSBT. Then we can decide to integrate PSBT into the Counterparty protocol but this normally involves including a raw transaction in the data of another transaction. We must carry out tests beforehand to know what is the minimum size of the data that we must store on-chain and if this is possible/reasonable. For the third point (attaching assets to UTXOs) I am not convinced that the game is worth the effort. It seems to me that the discussion already took place about ten years ago but at the time it was called Colored Coins. The only advantage I see is being compatible with Ordinals. This seems to me to be more of a political discussion than a technical one. |
Beta Was this translation helpful? Give feedback.
-
|
Currently atomic swaps can be done with low probability of frontrunning, one of them is to make sure that the parties exchanging the assets have only one utxo to spend, the only attack vector is to use the CPFP, but that can also be solved using CLTV.... of course this requires dapps to implement stricter measures in the Swap using PSBT...... |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Definitions
PSBT- Partially signed bitcoin transactionUTXO- Unspent Transaction OutputUI/UX- User Interface / User ExperienceAPI- Application Programming InterfaceAbstract
This CIP is intended to add new functionality to the Counterparty send function that allows assets to be bound to and unbound from UTXOs. This functionality will allow for interoperability of counterparty assets in the ordinals ecosystem.
Rationale
Counterparty is unnecessarily cumbersome for newcomers. The UI/UX challenges with BTCPay make trading difficult in a high fee environment. Additionally, dispensers rely on buyers to trust that the seller wont front run their transaction. The ordinals ecosystem has shown that simple deterministic methods are needed to lower the onboarding friction of new users. Additionally, modern Bitcoin web based wallets are largely used as part of this onboarding process. These browser based wallets rely on PSBTs with single transaction finality for the trading of ordinals, and as such, the ability to sign a PSBT and create a deterministic swap of an ordinal for BTC is simple and straight forward.
With Ordinals, a user who does not own an ordinal cannot create a valid bitcoin transaction to move an ordinal that is not in their wallet. This is because the user must possess the UTXO that holds the "sat". Unlike Ordinals, Counterparty as a metaprotcol is entirely detached from layer 1 consensus rules. This allows counterparty to be much more versatile and extendable, however there is one large drawback. It is possible for a user to create a valid layer 1 bitcoin transaction to do any number of things that will not be valid on counterparty. The transaction can be created and mined, and still rejected as an invalid transaction by counterparty (think of dispensers being front run). The solution to this problem is to create a mechanism for using layer 1 consensus rules with counterparty assets.
In order to do that, the asset needs to be attached to a UTXO. A system that allows for attaching assets to UTXOs allows for single transaction finality in trades between counterparty assets and BTC. This also allows counterparty assets to be compliant with the ordinals trading transactional structure, allowing the large players in the ordinals ecosystem to seamlessly integrate counterparty assets.
Limitations
Current PSBT trading utilizes an intermediary to hold your signed PSBT and find another party to finalize the trade. Although the intermediary cannot steal any assets, signed PSBT based transactions can be executed as long as the UTXO used in the PSBT exists. If users are utilizing PSBTs to trade assets and they want to cancel an order, the UTXO must be spent to ensure that a user cannot execute the PSBT. So creating a DEX without a third party would be possible by embedding the PSBT as part of opreturn data (or in the witness), but all operations (listing, remove listing, and trading) would require an on chain transaction transaction.
Implementation
NOTE: I need some help from those familiar with the specifics of the send function and db to add more detailed information here
An update to the send function to allow assets to be attached to a UTXO will be implemented. The send/multisend function will deduct an asset or assets from the users wallet and attach it to the first output of the transaction. The transaction structure will be as follows:
In the database, this UTXO will be treated as its own account, and txHash_utxoNumber can be used instead of a users wallet address. (This allows for an arbitrary number of assets to be attached to a single UTXO to perform more complex transactions)
Do we need a new table with the tx_hash, assets, and spent to make looking this up easier?
The counterparty node will need to check every transaction hash in every bitcoin transaction in each block against the list of UTXOs holding assets to see if the asset has been moved. When a UTXO containing assets is spent, all assets in that UTXO are transferred to the first output of that transaction
Using the structure of considering a UTXO to be an account of its own, it is possible for a user to combine multiple assets into a single UTXO. (including ones holding other cp assets and ordinals)
When the asset is attached to a UTXO and it moves to the first output, it's movement from wallet to wallet is functionally identical to an ordinal and in this state will be easily integrated into all current ordinals infrastructure.
Since Counterparty assets used in this way aren't permanently tied a sat, but optionally bound and unbound, when it comes time to move an asset out of a UTXO and back into a users wallet, the updated send function will be used. It will take the asset containing UTXO and user payments as input. Outputs will include the function to move the asset from the UTXO to the users wallet and the users change output.
Direct trades between Counterparty and Ordinals
It may be possible to do this in a single PSBT maintaining assets tied to UTXOs, but im not a sighash expert, if you have a good way to do this please add it in the comments.
API TX Generation
In order to easily facilitate adoption, the counterparty API will be updated such that it can generate the transactions needed to easily facilitate trading.
- Generate a Sell PSBT
When a user desires to put an asset up for sale, they will need to generate a transaction that contains an input containing the UTXO holding the asset, and a payment output to their desired address with the value in BTC required to complete the trade.
The API will generate a SELL transaction in the following format:
In most situations, the user will sign this transaction and provide it to a website that will find another user to finalize the sale.
- Generate a Buy PSBT
When a user desires to buy an asset that is up for sale, the will need to generate a transaction that contains the sale PSBT, and add to that an input with value greater than the payment_utxo amount, an output that the asset will be moved into, and an output for their change.
The API will take as an input the PSBT from Generate a Sell PSBT and using the buyers UTXOs generate a BUY transaction in the following format:
- PSBT for all other transactions
To maximize interoperability with the ordinals infrastructure, it is necessary to allow all counterparty transactions to be generated as PSBTs. In counterparty-lib in the file lib/transactions.py an additional function called constructPsbt will be created. It will take the same parameters as the construct function. This function will call construct and with the result it will use the bitcoin backend to call the function converttopsbt to generate the hex. Then as a safety measure, the psbt will be deconstructed to verify the parameters match those expected before returning the psbt.
Copyright
This document is placed in the public domain.
Beta Was this translation helpful? Give feedback.
All reactions