Skip to content

Commit a8bb0a4

Browse files
committed
Include Optional Encoded Outpoints
With thanks to Daniel Pape for the work behind this idea. Please not that the test-vectors still need to be updated (again).
1 parent e78c384 commit a8bb0a4

File tree

2 files changed

+100
-68
lines changed

2 files changed

+100
-68
lines changed

README.mediawiki

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ Those proposing changes should consider that ultimately consent may rest with th
662662
| [[bip-0136.mediawiki|136]]
663663
| Applications
664664
| Bech32 Encoded Tx Position References
665-
| Велеслав, Jonas Schnelli
665+
| Велеслав, Jonas Schnelli, Daniel Pape
666666
| Informational
667667
| Draft
668668
|- style="background-color: #cfffcf"

bip-0136.mediawiki

Lines changed: 99 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Title: Bech32 Encoded Tx Position References
55
Author: Велеслав <[email protected]>
66
Jonas Schnelli <[email protected]>
7+
Daniel Pape <[email protected]>
78
Comments-Summary: No comments yet.
89
Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0136
910
Status: Draft
@@ -15,10 +16,9 @@
1516
== Introduction ==
1617

1718
=== Abstract ===
19+
This document proposes a convenient human useable format, '''"TxRef"''', as a standard way to refer to a transaction position within the Bitcoin Blockchain, and optionally a particular outpoint index with the referred transaction. The primary purpose of this format is to allow users to refer to a confirmed transaction (and optionally an outpoint index within) in a standard reliable and concise way.
1820

19-
This document proposes a human useable format: '''"TxRef"''' as a standard way of referencing transaction positions within the Bitcoin Blockchain. The primary purpose of this format is to allow end-users an effective and convenient way of referencing transactions that have been confirmed within the blockchain.
20-
21-
''Please note: that a TxRef does not reference an actual transaction itself, rather it references a possible location within a blockchain for a transaction, that may or may not, point to an actual transaction and may change with reorganisations. We recommend that TxRef's should be not used for positions within the blockchain with a maturity less than 100 blocks.''
21+
''Please note: Unlike TxID where there is strong cryptographic link between the ID and the actual transaction. TxRef only provide a weak link to a particular transaction. TxRef locates an offset within a blockchain for a transaction, that may - or may not - point to an actual transaction, which fact may change with reorganisations. We recommend that TxRef's should be not used for positions within the blockchain having a maturity less than 100 blocks.''
2222

2323
=== Copyright ===
2424

@@ -32,24 +32,25 @@ However, for many use-cases they have practical limitations:
3232
* TxIDs require third-party service for SPV wallets to lookup.
3333
* TxIDs are very long HEX encoded values (64 characters long).
3434
35-
For transactions that have been embedded in the blockchain, it is possible to reference them not by their TxID, but by their location within the blockchain itself. In this document, we propose a standard for doing this.
35+
For transactions that have been embedded in the blockchain, it is possible to reference them not by their TxID, but by their location within the blockchain itself. The encoding can be made friendly for occasional human transcription. In this document, we propose a standard for doing this.
3636

3737
=== Examples ===
3838
These examples are for Bitcoin Transactions.
39-
* Genesis Coinbase Transaction: <tt>tx1:rqqq-qqqq-qmhu-qk (need to update)</tt>
40-
* Transaction #2205 of Block #466793: <tt>tx1:rjk0-u5ng-4jsf-mc (need to update)</tt>
39+
* Genesis Coinbase Transaction: <tt>tx1:rqqq-qqqq-qmhu-qhp</tt>
40+
* Transaction #2205 of Block #466793: <tt>tx1:rjk0-uqay-zsrw-hqe</tt>
4141
4242
== Specification ==
4343

44-
A '''confirmed transaction position reference''', or '''TxRef''' is reference to a particular location within the blockchain specified by the block height and a index within the block.
44+
A '''confirmed transaction position reference''', or '''TxRef''', is a reference to a particular location within the blockchain, specified by the block height and a transaction index within the block, and optionally a outpoint index within the transaction.
4545

4646
''Please Note: All values in this specification are encoded in little-endian format.''
4747

4848
=== Transaction Position Reference Considerations ===
4949
A TxRef may reference a location that doesn't exist because:
5050

51-
* The block height hasn't been mined. Or,
52-
* The index is more than the total number of transactions included within the specified block.
51+
* The specified block hasn't yet been mined. Or,
52+
* The transaction index is greater than the total number of transactions included within the specified block.
53+
* The optional outpoint index is greater than the total outpoints contained within the transaction.
5354
5455
Therefore, implementers must be careful not to display TxRef's to users prematurely:
5556

@@ -62,21 +63,23 @@ Therefore, implementers must be careful not to display TxRef's to users prematur
6263
TxRef uses standard Bech32<ref name=":0">'''Why use Bech32 Encoding for Confirmed Transaction References?''' The error detection and correction properties of this encoding format make it very attractive. We expect that it will be reasonable for software to correct a maximum of two characters; however, we haven’t specified this yet.</ref> encoding as defined in [https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki BIP-173] and therefore consists of:
6364

6465
* Human-readable Part, or "HRP", that provides namespacing. We have chosen to distinguish between Main and Test Networks:
65-
**For Any Mainnet Network: '''"tx"'''.
66-
**For Any Testnet Network: '''"txtest"'''.
67-
**Please see [https://github.com/satoshilabs/slips/blob/master/slip-0173.md SLIP-0173 : Registered human-readable parts for BIP-0173] for a full list of HRP's including these two and other relating to other projects.
66+
** For Any Mainnet Network: '''"tx"'''.
67+
** For Any Testnet Network: '''"txtest"'''.
68+
** Please see [https://github.com/satoshilabs/slips/blob/master/slip-0173.md SLIP-0173 : Registered human-readable parts for BIP-0173] for a full list of HRP's including these two and others relating to other projects.
6869
* Separator: '''"1"'''.
6970
* Data Part.
7071
72+
Please node: other specifcations, such as [https://w3c-ccg.github.io/did-spec/ Decentralized Identifier syntax] , have implicitly encoded the information contained within the HRP elsewhere. In this case they may choose not include the HRP as specified here.
73+
7174
To increase portability and readability additional separators SHOULD be added:
7275

7376
* A Colon<ref>'''Why add a colon here?''' This allows it to conform better with W3C URN/URL standards.</ref> '''":"''' added after '1'.
74-
* Hyphens<ref>'''Why hyphens to the TxRef?''' As TxRef's are short, we expect that they will be quoted via voice or written by hand. The inclusion of hyphens every 4 characters breaks the string and means people don't loose their place so easily.</ref> '''"-"''' added after every 4 characters beyond the colon.
77+
* Hyphens<ref>'''Why hyphens to the TxRef?''' As TxRef's are short, we expect that they will be quoted via voice or written by hand. The inclusion of hyphens every 4 characters breaks the string and means people don't lose their place so easily.</ref> '''"-"''' added after every 4 characters beyond the colon.
7578
7679
All non-bech32-alphabet characters after the bech32 code separator MUST be ignored/removed when parsing (except for terminating characters).<ref>'''Why strip all non-bech32-alphabet characters?''' We do not wish to expect the users to keep their TxRef's in good unicode form (hyphens, colons, invisible spaces, random unicode characters, etc). We expect them to copy, paste, write by-hand, write in a mix of character sets, etc. Parsers should automatically correct for all sorts of these common errors.
7780
</ref>
7881
{| class="wikitable"
79-
|+TxRef String Format for Bitcoin Mainnet and Bitcoin Testnet:
82+
|+Text Encoding of the TxRef
8083
!
8184
!Bit
8285
!Character
@@ -112,39 +115,12 @@ All non-bech32-alphabet characters after the bech32 code separator MUST be ignor
112115
|9
113116
|1
114117
|"'''-'''"
115-
|-
116-
|Data
117-
|20 – 39
118-
|10 – 13
119-
|4
120-
|
121-
|-
122-
|Hyphen
123-
|
124-
|14
125-
|1
126-
|"'''-'''"
127-
|-
128-
|Data
129-
|40 – 59
130-
|15 – 18
131-
|4
132-
|
133-
|-
134-
|Hyphen
135-
|
136-
|19
137-
|1
138-
|"'''-'''"
139-
|-
140-
|Data
141-
|60 – 74
142-
|20 – 22
143-
|3
144-
|
145118
|}
119+
The Data - Hyphen patten is repeated for the entire length of data, ( a hyphen is inserted after every encoded 20 bits or 4 data characters).
120+
=== Data ===
121+
122+
The 75 or 90 bits of data encoded in the string above are defined in this manner:
146123

147-
=== Data Part ===
148124
{| class="wikitable"
149125
|+TxRef Binary Format for Bitcoin Mainnet and Bitcoin Testnet:
150126
!
@@ -158,7 +134,10 @@ All non-bech32-alphabet characters after the bech32 code separator MUST be ignor
158134
|0 – 4
159135
|5
160136
|Chain Namespacing Code
161-
|'''0x3''' for Bitcoin Mainnet, or '''0x6''' for Bitcoin Testnet
137+
|'''0x3''' for Bitcoin Mainnet.
138+
'''0x4''' for Bitcoin Mainnet with Outpoint.
139+
'''0x6''' for Bitcoin Testnet.
140+
'''0x7''' for Bitcoin Testnet with Outpoint.
162141
|
163142
|-
164143
|Version
@@ -181,37 +160,71 @@ All non-bech32-alphabet characters after the bech32 code separator MUST be ignor
181160
|The index of the Tx inside the block
182161
|Tx 0 (coinbase) to Tx position 32767
183162
|Max Tx's in block is 16665
163+
|}
164+
If the magic is '''0x4''' or '''0x7''', an optional outpoint is included in the encoding:
165+
166+
{| class="wikitable"
167+
|+Optional Outpoint Index Encoding:
168+
!
169+
!'''Bit'''
170+
!'''Bit(s)'''
171+
!'''Type'''
172+
!'''Values'''
173+
!'''Notes'''
174+
|-
175+
|Outpoint Index
176+
|45 – 59
177+
|15
178+
|The index of the Outpoint inside the Tx
179+
|Outpoint 0 to Outpoint Position 32767
180+
|
181+
|}
182+
183+
We include the 30-bit checksum last:
184+
{| class="wikitable"
185+
|+Bech32 Checksum Encoding:
186+
!
187+
!'''Bit'''
188+
!'''Bit(s)'''
189+
!'''Type'''
190+
!'''Values'''
191+
!'''Notes'''
184192
|-
185193
|Checksum
186-
|45 – 74
194+
|45 – 74 or 60 – 89
187195
|30
188196
|Bech32 Checksum
189197
|
190198
|
191199
|}
200+
192201
==== Magic Notes: ====
193202
The magic code provides namespacing between chains. 5-bit magic codes are used for the Bitcoin Mainnet and the Bitcoin Testnet. (it may be significantly longer for other projects/chains):
194203

195-
* For Bitcoin Mainnet the magic code is: '''0x3''', leading to a '''"r"''' character.
196-
* For Bitcoin Testnet the magic code is: '''0x6''', leading to a '''"x"''' character.
204+
* For Bitcoin Mainnet the magic code is: '''0x3''', leading to an '''"r"''' character when encoded.
205+
* For Bitcoin Mainnet with Outpoint Encoded the magic code is: '''0x4''', leading to an '''"y"''' character when encoded.
206+
* For Bitcoin Testnet the magic code is: '''0x6''', leading to an '''"x"''' character when encoded.
207+
* For Bitcoin Testnet with Outpoint Encoded the magic code is: '''0x7''', leading to an '''"8"''' character when encoded.
197208
198-
Codes '''0x0''', '''0x1''', '''0x2''' are also reserved for future use within the Bitcoin project.
209+
Codes '''0x0''', '''0x1''', '''0x2''', '''0x5''', are also reserved for future use within the Bitcoin project.
199210

200-
''Any other chain MUST NOT start their magic code with any value between 0x0 and 0x6 inclusive.''
211+
''Any other chain MUST NOT start their magic code with any value between 0x0 and 0x7 inclusive.''
201212

202213
Other magic codes will be specified in SLIP-XXXX "TxRef for Non-Bitcoin Chains and Networks".
203214

204-
=== Compatibly ===
215+
=== Compatibility ===
205216
There are no known compatibility issues.
206217

207218
== Rationale ==
208219

209220
<references />
210221

211222
== Reference implementations ==
212-
C Reference Implementation: https://github.com/jonasschnelli/bitcoin_txref_code
223+
C Reference Implementation (supports version 0): https://github.com/jonasschnelli/bitcoin_txref_code
213224

214-
Go Reference Implementation: https://github.com/kulpreet/txref
225+
Go Reference Implementation (supports version 0): https://github.com/kulpreet/txref
226+
227+
C++ Reference Implementation (support versions 0 and 1): https://github.com/dcdpr/btcr-DID-method/blob/master/libtxref
215228

216229
== Appendices ==
217230

@@ -234,24 +247,24 @@ The following list gives invalid TxRef's and the reason for their invalidity.
234247
* <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty</tt>: Invalid human-readable part
235248
* <tt>tx1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5</tt>: Invalid checksum
236249
237-
==== Bitcoin TxRef <u>(out of date, need to be amended).</u> ====
250+
==== Bitcoin TxRef ====
238251
The following list gives properly encoded Bitcoin TxRef's and the values in hex. (block height, transaction index)
239252

240-
* <tt>tx1:rqqq-qqqq-qmhu-qk</tt>: <tt>(0x0, 0x0)</tt>
241-
* <tt>tx1:rqqq-qull-6v87-r7</tt>: <tt>(0x0, 0x1FFF)</tt>
242-
* <tt>tx1:r7ll-lrqq-vq5e-gg</tt>: <tt>(0x1FFFFF, 0x0)</tt>
243-
* <tt>tx1:r7ll-llll-khym-tq</tt>: <tt>(0x1FFFFF, 0x1FFF)</tt>
253+
* <tt>tx1:rqqq-qqqq-qmhu-qhp</tt>: <tt>(0x0, 0x0)</tt>
254+
* <tt>tx1:rqqq-qqll-l8xh-jkg</tt>: <tt>(0x0, 0x7FFF)</tt>
255+
* <tt>tx1:r7ll-llqq-qghq-qr8</tt>: <tt>(0xFFFFFF, 0x0)</tt>
256+
* <tt>tx1:r7ll-llll-l5xt-jzw</tt>: <tt>(0xFFFFFF, 0x7FFF)</tt>
244257
245-
The following list give valid Bitcoin TxRef's and the values in hex. (block height, transaction index)
246-
* <tt>tx1:rjk0-u5ng-4jsf-mc</tt>: <tt>(0x71F69, 0x89D)</tt>
247-
* <tt>TX1RJK0U5NG4JSFMC</tt>: <tt>(0x71F69, 0x89D)</tt>
248-
* <tt>TX1R1JK0--U5bNG4JSb----FMC</tt>: <tt>(0x71F69, 0x89D)</tt>
249-
* <tt>tx1 rjk0 u5ng 4jsfmc</tt>: <tt>(0x71F69, 0x89D)</tt>
250-
* <tt>tx1!rjk0\u5ng*4jsf^^mc</tt>: <tt>(0x71F69, 0x89D)</tt>
258+
The following list gives valid Bitcoin TxRef's and the values in hex. (block height, transaction index)
259+
* <tt>tx1:rjk0-uqay-zsrw-hqe</tt>: <tt>(0x71F69, 0x89D)</tt>
260+
* <tt>TX1RJK0UQAYZSRWHQE</tt>: <tt>(0x71F69, 0x89D)</tt>
261+
* <tt>TX1RJK0--UQaYZSRw----HQE</tt>: <tt>(0x71F69, 0x89D)</tt>
262+
* <tt>tx1 rjk0 uqay zsrw hqe</tt>: <tt>(0x71F69, 0x89D)</tt>
263+
* <tt>tx1!rjk0\uqay*zsrw^^hqe</tt>: <tt>(0x71F69, 0x89D)</tt>
251264
252265
The following list gives invalid Bitcoin TxRef's and the reason for their invalidity.
253-
* <tt>tx1:t7ll-llll-gey7-ez</tt>: Magic 0xB instead of 0x3. <tt>(0x1FFFFF, 0x1FFF)</tt>
254-
* <tt>tx1:rlll-llll-cgqu-n2</tt>: Version 1 instead of 0. <tt>(0x1FFFFF, 0x1FFF)</tt>
266+
* <tt>tx1:t7ll-llll-ldup-3hh</tt>: Magic 0xB instead of 0x3. <tt>(0xFFFFFF, 0x7FFF)</tt>
267+
* <tt>tx1:rlll-llll-lfet-r2y</tt>: Version 1 instead of 0. <tt>(0xFFFFFF, 0x7FFF)</tt>
255268
* <tt>tx1:rjk0-u5ng-gghq-fkg7</tt>: Valid Bech32, but 10x5bit packages instead of 8.
256269
* <tt>tx1:rjk0-u5qd-s43z</tt>: Valid Bech32, but 6x5bit packages instead of 8.
257270
@@ -272,5 +285,24 @@ Some calculations showing why we chose these particular bit-length of the block
272285
*The ''extreme'' smallest Tx is 60 Byte's: Max 16665 tx in a block.
273286
**4B version + 1B tx_in count + 36B previous_output + 1B script length + 0B signature script + 4B sequence + 1B tx_out count + 8B amount + 1B script length + 0B pubkey script + 4B lock_time = 60B
274287
288+
=== Test Vectors (version 1) ===
289+
These test vectors are extended TxRefs (version 1):
290+
291+
==== Bitcoin Extended TxRef ====
292+
The following list gives properly encoded Bitcoin Extended TxRef's and the values in hex. (block height, transaction index, TXO index)
293+
294+
* <tt>tx1:rpqq-qqqq-qqqq-q2ge-ahz</tt>: <tt>(0x0, 0x0, 0x0)</tt>
295+
* <tt>tx1:rpqq-qqql-llqq-qshz-qhw</tt>: <tt>(0x0, 0x7FFF, 0x0)</tt>
296+
* <tt>tx1:rp7l-lllq-qqqq-qpvh-wkq</tt>: <tt>(0xFFFFFF, 0x0, 0x0)</tt>
297+
* <tt>tx1:rp7l-llll-llqq-qmnv-nkv</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x0)</tt>
298+
299+
* <tt>tx1:rpqq-qqqq-qqpq-qg2s-2w6</tt>: <tt>(0x0, 0x0, 0x1)</tt>
300+
* <tt>tx1:rpqq-qqql-llpq-qj4t-hwk</tt>: <tt>(0x0, 0x7FFF, 0x1)</tt>
301+
* <tt>tx1:rp7l-lllq-qqpq-qrw7-e0c</tt>: <tt>(0xFFFFFF, 0x0, 0x1)</tt>
302+
* <tt>tx1:rp7l-llll-llpq-qe39-y05</tt>: <tt>(0xFFFFFF, 0x7FFF, 0x1)</tt>
303+
304+
* <tt>tx1:rpjk-0uqa-yzu4-x0w0-kuq</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt>
305+
* <tt>txtest1:xpjk-0uqa-yzu4-xgrl-pue</tt>: <tt>(0x71F69, 0x89D, 0x1ABC)</tt> (testnet, magic number = 0x6)
306+
275307
== Acknowledgements ==
276308
Special Thanks to Pieter Wuille and Greg Maxwell for Bech32, a wonderful user-facing data encoding.

0 commit comments

Comments
 (0)