summaryrefslogtreecommitdiff
path: root/bip-0136.mediawiki
blob: e8b107d9f2060b7b690b5287c9d8909b93042d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<pre>
  BIP: 136
  Layer: Applications
  Title: Bech32 Encoded Tx Position References
  Author: Велеслав <veleslav.bips@protonmail.com>
          Jonas Schnelli <dev@jonasschnelli.ch>
  Comments-Summary: No comments yet.
  Comments-URI: https://github.com/bitcoin/bips/wiki/Comments:BIP-0136
  Status: Draft
  Type: Informational
  Created: 2017-07-09
  License: BSD-2-Clause
</pre>

== Introduction ==

=== Abstract ===

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.

''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.''

=== Copyright ===

This BIP is licensed under the 2-clause BSD license.

=== Motivation ===
Since the first version of Bitcoin, TxID's (Transaction Identifiers) that are a core part of the consensus protocol, have been routinely used to identify individual transactions between users.

However, for many use-cases they have practical limitations:
* TxIDs are expensive for full nodes to lookup (requiring either a linear scan of the blockchain, or an expensive TxID index).
* TxIDs require third-party service for SPV wallets to lookup.
* TxIDs are very long HEX encoded values (64 characters long).

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.

=== Examples ===
These examples are for Bitcoin Transactions.
* Genesis Coinbase Transaction: <tt>tx1:rqqq-qqqq-qmhu-qk (need to update)</tt>
* Transaction #2205 of Block #466793: <tt>tx1:rjk0-u5ng-4jsf-mc (need to update)</tt>

== Specification ==

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.

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

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

* The block height hasn't been mined. Or,
* The index is more than the total number of transactions included within the specified block.

Therefore, implementers must be careful not to display TxRef's to users prematurely:

* Applications MUST NOT display TxRef's for transactions with less than 6 confirmations.
* Application MUST show a warning for TxRef's for transactions with less than 100 confirmations.
** This warning SHOULD state that in the case of a large reorganisation, the TxRefs Displayed may point to a different transaction, or to no transaction at all.

=== Encoding ===

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:

* Human-readable Part, or "HRP", that provides namespacing. We have chosen to distinguish between Main and Test Networks:
**For Any Mainnet Network: '''"tx"'''.
**For Any Testnet Network: '''"txtest"'''.
**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.
* Separator: '''"1"'''.
* Data Part.

To increase portability and readability additional separators SHOULD be added:

* A Colon<ref>'''Why add a colon here?''' This allows it to conform better with W3C URN/URL standards.</ref> '''":"'''  added after '1'.
* 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.

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.
</ref>
{| class="wikitable"
|+TxRef String Format for Bitcoin Mainnet and Bitcoin Testnet:
!
!Bit
!Character
!Characters
!Value
|-
|Human Readable Part
|
|1 – 2
|2
|Bitcoin Mainnet: "'''tx'''", Bitcoin Testnet: "'''txtest'''"
|-
|Separator
|
|3
|1
|"'''1'''"
|-
|Colon
|
|4
|1
|"''':'''"
|-
|Data
|0 – 19
|5 – 8
|4
|
|-
|Hyphen
|
|9
|1
|"'''-'''"
|-
|Data
|20 – 39
|10 – 13
|4
|
|-
|Hyphen
|
|14
|1
|"'''-'''"
|-
|Data
|40 – 59
|15 – 18
|4
|
|-
|Hyphen
|
|19
|1
|"'''-'''"
|-
|Data
|60 – 74
|20 – 22
|3
|
|}

=== Data Part ===
{| class="wikitable"
|+TxRef Binary Format for Bitcoin Mainnet and Bitcoin Testnet:
!
!'''Bit'''
!'''Bit(s)'''
!'''Type'''
!'''Values'''
!'''Notes'''
|-
|Magic
|0 – 4
|5
|Chain Namespacing Code
|'''0x3''' for Bitcoin Mainnet, or '''0x6''' for Bitcoin Testnet
|
|-
|Version
|5
|1
|For Future Use
|Must be '''0x0'''
|
|-
|Block Height
|6 – 29
|24
|The Block Height of the Tx
|Block 0 (genesis) to block 16777215
|Until Year ~2328
|-
|Transaction Index
|30 – 44
|15
|The index of the Tx inside the block
|Tx 0 (coinbase) to Tx position 32767
|Max Tx's in block is 16665
|-
|Checksum
|45 – 74
|30
|Bech32 Checksum
|
|
|}
==== Magic Notes: ====
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):

* For Bitcoin Mainnet the magic code is: '''0x3''', leading to a '''"r"''' character.
* For Bitcoin Testnet the magic code is: '''0x6''', leading to a '''"x"''' character.

Codes '''0x0''', '''0x1''', '''0x2''' are also reserved for future use within the Bitcoin project.

''Any other chain MUST NOT start their magic code with any value between 0x0 and 0x6 inclusive.''

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

=== Compatibly ===
There are no known compatibility issues.

== Rationale ==

<references />

== Reference implementations ==
C Reference Implementation: https://github.com/jonasschnelli/bitcoin_txref_code

Go Reference Implementation: https://github.com/kulpreet/txref

== Appendices ==

=== Test Vectors ===
There are two sets of Test Vectors included here:

* Bech32 Encoding Test Vectors. These are to test if a implementation accepts the encoding, with the correct human readable part, and separator.
* Bitcoin TxRef Test Vectors. These test the full specification, in particular correct values for block height and the transaction index.

==== Bech32 Encoding (for TxRef). ====
''Please Note: All test vectors are shown to help test if a string is compliant or not. All real-life applications (such as for Bitcoin) should comply with the Bitcoin Test Vectors listed Below.''

The following strings have a valid Human Readable Part and Bech32 Checksum.
* <tt>TX1A12UEL5L</tt>
* <tt>tx1an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs</tt>
* <tt>tx1abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw</tt>
* <tt>tx11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j</tt>

The following list gives invalid TxRef's and the reason for their invalidity.
* <tt>bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty</tt>: Invalid human-readable part
* <tt>tx1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5</tt>: Invalid checksum

==== Bitcoin TxRef <u>(out of date, need to be amended).</u> ====
The following list gives properly encoded Bitcoin TxRef's and the values in hex. (block height, transaction index)

* <tt>tx1:rqqq-qqqq-qmhu-qk</tt>: <tt>(0x0, 0x0)</tt>
* <tt>tx1:rqqq-qull-6v87-r7</tt>: <tt>(0x0, 0x1FFF)</tt>
* <tt>tx1:r7ll-lrqq-vq5e-gg</tt>: <tt>(0x1FFFFF, 0x0)</tt>
* <tt>tx1:r7ll-llll-khym-tq</tt>: <tt>(0x1FFFFF, 0x1FFF)</tt>

The following list give valid Bitcoin TxRef's and the values in hex. (block height, transaction index)
* <tt>tx1:rjk0-u5ng-4jsf-mc</tt>: <tt>(0x71F69, 0x89D)</tt>
* <tt>TX1RJK0U5NG4JSFMC</tt>:  <tt>(0x71F69, 0x89D)</tt>
* <tt>TX1R1JK0--U5bNG4JSb----FMC</tt>:  <tt>(0x71F69, 0x89D)</tt>
* <tt>tx1 rjk0 u5ng 4jsfmc</tt>: <tt>(0x71F69, 0x89D)</tt>
* <tt>tx1!rjk0\u5ng*4jsf^^mc</tt>: <tt>(0x71F69, 0x89D)</tt>

The following list gives invalid Bitcoin TxRef's and the reason for their invalidity.
* <tt>tx1:t7ll-llll-gey7-ez</tt>: Magic 0xB instead of 0x3.  <tt>(0x1FFFFF, 0x1FFF)</tt>
* <tt>tx1:rlll-llll-cgqu-n2</tt>: Version 1 instead of 0. <tt>(0x1FFFFF, 0x1FFF)</tt>
* <tt>tx1:rjk0-u5ng-gghq-fkg7</tt>: Valid Bech32, but 10x5bit packages instead of 8.
* <tt>tx1:rjk0-u5qd-s43z</tt>: Valid Bech32, but 6x5bit packages instead of 8.

=== Bitcoin TxRef Payload Value Choice: ===
Some calculations showing why we chose these particular bit-length of the block height and transaction index.

==== Block Height Value: ====
24-bit: between 0, and 0xFFFFFF (16,777,216 blocks).

*There are ~52,500 blocks every year, leading to ~319 years of blocks addressable.
*Therefore before year 2328 this specification should be extended. (We think that we have plenty of time).

==== Tx Position Value: ====
15-bit: between 0x0, and 0x7FFF. (32,768 transactions).

*The ''realistic'' smallest Tx is 83 Bytes: Max 12047 tx in a block.
**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 + 23B pubkey script + 4B lock_time = 83B
*The ''extreme'' smallest Tx is 60 Byte's: Max 16665 tx in a block.
**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

== Acknowledgements ==
Special Thanks to Pieter Wuille and Greg Maxwell for Bech32, a wonderful user-facing data encoding.