You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since its inception, one of Counterparty's main technical challenges has been efficiently storing data in the Bitcoin blockchain. Currently, two methods are predominantly used: OP_RETURN and multi-signature 2-of-3 outputs. The OP_RETURN method is limited to 80 bytes, while the multi-signature approach is both expensive and suboptimal from an architectural perspective.
With the introduction of Taproot addresses, we now have access to significantly more efficient and cost-effective methods. This specification outlines the implementation of the "Inscription envelope" method (popularized by Ordinals) as described in the official Ordinals documentation.
Technical Approach
Unlike existing methods which store data in transaction outputs, the envelope method stores data in the witnesses of transaction inputs. This offers substantial improvements in efficiency and cost.
Key Advantages
Increased Data Capacity: Overcome the 80-byte limitation of OP_RETURN
Reduced Costs: Lower fee requirements compared to multi-signature approaches
Cleaner Architecture: More elegant solution leveraging Bitcoin's latest capabilities
Implementation Methodology
For performance optimization, we don't want to check all witnesses of all transactions. Instead, we'll only examine inputs of transactions with an OP_RETURN containing the Counterparty prefix (only the prefix, without ID or data).
Step-by-Step Process
1. Commit Transaction
Create an output containing the public key tweaked with the envelope script:
During parsing, if and only if a transaction has an OP_RETURN output containing the Counterparty prefix, retrieve the witness data:
# Extract the inscription scriptinscription_script=Script.from_raw(verify_tx.witnesses[0].stack[1])
# Join all the chunksinscription_data="".join(inscription_script.script[2:-1])
inscription_content=binascii.unhexlify(inscription_data)
# Verify data integrityassertinscription_content==original_content
Required Code Modifications
Transaction Parsing
Only RSFetcher needs to be modified:
In the parse_vout() function, when an OP_RETURN contains only the Counterparty prefix, data must be retrieved from the witnesses of the input.
Composer Changes
When encoding=p2tr is specified:
For segwit source addresses: Returns 2 transactions (Commit and Reveal) and the envelope script needed to sign the second transaction
For legacy addresses: Returns 1 transaction and the envelope script needed to sign the second transaction. The wallet will then need to use the new endpoint to compose the second transaction
New endpoint /v2/addresses/<address>/compose/reveal to compose the second transaction. The only required parameter is the txid of the commit transaction.
API Changes
Add p2tr as a valid value for the encoding parameter (will become the default in a future update)
Add envelope_script field in composition results when encoding=p2tr
Add commit_rawtransaction field in composition results when encoding=p2tr and the source is a segwit address
Add the endpoint /v2/addresses/<address>/compose/reveal
Important: The fees for the second transaction are determined when composing the first transaction. The fee configuration parameters are ignored by the /v2/addresses/<address>/compose/reveal endpoint.
Database Changes
No database changes are required for this implementation.
The text was updated successfully, but these errors were encountered:
adamkrellenstein
changed the title
Protocol Change Proposal: Taproot Data Encoding
Protocol Change Proposal: Taproot Envelope Data Encoding
Feb 27, 2025
Taproot Envelope Data Encoding
Motivation
Since its inception, one of Counterparty's main technical challenges has been efficiently storing data in the Bitcoin blockchain. Currently, two methods are predominantly used:
OP_RETURN
and multi-signature 2-of-3 outputs. TheOP_RETURN
method is limited to 80 bytes, while the multi-signature approach is both expensive and suboptimal from an architectural perspective.With the introduction of Taproot addresses, we now have access to significantly more efficient and cost-effective methods. This specification outlines the implementation of the "Inscription envelope" method (popularized by Ordinals) as described in the official Ordinals documentation.
Technical Approach
Unlike existing methods which store data in transaction outputs, the envelope method stores data in the witnesses of transaction inputs. This offers substantial improvements in efficiency and cost.
Key Advantages
OP_RETURN
Implementation Methodology
For performance optimization, we don't want to check all witnesses of all transactions. Instead, we'll only examine inputs of transactions with an
OP_RETURN
containing the Counterparty prefix (only the prefix, without ID or data).Step-by-Step Process
1. Commit Transaction
Create an output containing the public key tweaked with the envelope script:
The
value
amount will be calculated based on the data size, covering the fees necessary for the subsequent Reveal transaction.Broadcast this first transaction (Commit) containing the previously created output.
2. Reveal Transaction
Create a second transaction (Reveal) with an input and an output:
Sign the transaction including the complete envelope script that gets added to the witnesses:
Broadcast the second transaction (Reveal).
3. Parsing
During parsing, if and only if a transaction has an
OP_RETURN
output containing the Counterparty prefix, retrieve the witness data:Required Code Modifications
Transaction Parsing
Only
RSFetcher
needs to be modified:parse_vout()
function, when anOP_RETURN
contains only the Counterparty prefix, data must be retrieved from the witnesses of the input.Composer Changes
When
encoding=p2tr
is specified:New endpoint
/v2/addresses/<address>/compose/reveal
to compose the second transaction. The only required parameter is thetxid
of the commit transaction.API Changes
p2tr
as a valid value for theencoding
parameter (will become the default in a future update)envelope_script
field in composition results whenencoding=p2tr
commit_rawtransaction
field in composition results whenencoding=p2tr
and the source is a segwit address/v2/addresses/<address>/compose/reveal
Important: The fees for the second transaction are determined when composing the first transaction. The fee configuration parameters are ignored by the
/v2/addresses/<address>/compose/reveal
endpoint.Database Changes
No database changes are required for this implementation.
The text was updated successfully, but these errors were encountered: