summaryrefslogtreecommitdiff
path: root/23/e76f1081b1073b9c23c4b82aa33fc6c2f0b208
blob: 247e8bd324b29c8bdc746b0f37ebb4d84d23f5c6 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
Return-Path: <tombriar11@protonmail.com>
Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137])
 by lists.linuxfoundation.org (Postfix) with ESMTP id 18859C0037
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue,  9 Jan 2024 15:32:00 +0000 (UTC)
Received: from localhost (localhost [127.0.0.1])
 by smtp4.osuosl.org (Postfix) with ESMTP id DA26241937
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue,  9 Jan 2024 15:31:59 +0000 (UTC)
DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DA26241937
Authentication-Results: smtp4.osuosl.org;
 dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com
 header.a=rsa-sha256 header.s=protonmail3 header.b=bHDUOL5e
X-Virus-Scanned: amavisd-new at osuosl.org
X-Spam-Flag: NO
X-Spam-Score: -2.549
X-Spam-Level: 
X-Spam-Status: No, score=-2.549 tagged_above=-999 required=5
 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
 DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
 autolearn=ham autolearn_force=no
Received: from smtp4.osuosl.org ([127.0.0.1])
 by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 62qASoPAdV1F
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue,  9 Jan 2024 15:31:58 +0000 (UTC)
Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com
 [188.165.51.139])
 by smtp4.osuosl.org (Postfix) with ESMTPS id 95F4741918
 for <bitcoin-dev@lists.linuxfoundation.org>;
 Tue,  9 Jan 2024 15:31:57 +0000 (UTC)
DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 95F4741918
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com;
 s=protonmail3; t=1704814309; x=1705073509;
 bh=kqz9JbHOFRGAt94kYxJdv7B7PVkX226hvlLGIpmLx8g=;
 h=Date:To:From:Subject:Message-ID:In-Reply-To:References:
 Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID:
 Message-ID:BIMI-Selector;
 b=bHDUOL5eTXg5ehAkrsJfygE/7IHoLkBDkizpVrEHMXCs7NQG6YRlzlOt1NX1Yg/1q
 o9zItTK4iO/LwpBLeZvEY7X7lEITbTjG3EbaA/6UG4bY78ZRnnBGC8QecrTLmlFQQq
 lvhp1Q0AQFCNvJUsKhIgkPjOWagliRif7Mkn1WKHChc1uFUaDFlGDVjpm98JwRyzRk
 flwn8RmLwbx/Cw8+nQr0PG2T+1UGg6WHYQs6Ym/aDINinCVs/WoAqp7BpntN5RfCMN
 pOAip7man8bv8KeKhwSHJIrEILdHEEFyWuULgFuFW3H44UGmPg63P9jDQbciuUq7u8
 nlCg+luhoOqOg==
Date: Tue, 09 Jan 2024 15:31:37 +0000
To: "bitcoin-dev@lists.linuxfoundation.org"
 <bitcoin-dev@lists.linuxfoundation.org>
From: Tom Briar <tombriar11@protonmail.com>
Message-ID: <IFgPQiCptuVM6I5AsCE6VFrPMsGzBMK3x78GHlupJj12-rBloASYdafdBzyjSKC0H0EWLG2NNBzu1wEyYyyl1VzMmjW3nO7M-9OJpMxoEMM=@protonmail.com>
In-Reply-To: <ZZgeA1KPUbLtQjoT@camus>
References: <WJoM7dyrk0o8ujOZOo462r66wS2Kl3L1ZZRodvaLK-HKEUc90yvwOqXbUUrGbV1lk6cOywTqLoCyHzk2Tm3TtBFyUL0NZ6D7v9NmTXypJPA=@protonmail.com>
 <KSmH1MBTPLuXMF4TWbWq6vaft_K_7IZS2YcoZ1iHwtHY06It1DjExVgSdrLBMQZA8mLGz8xdOzyXRHAZ2qCAugwG8gMtEGsGj-XNTPN0v0w=@protonmail.com>
 <ZPHtgiJQ4Yqrr941@camus> <ZPdswQ7uAJr35YbC@petertodd.org>
 <hd13VCUTiTaX_Z4oeZpzwjdVOcmkbcg-kgfThk9b1LUt2YUCEXrwVuEq8BiNWtfzeAafo6GdsrFzGg3pQI5kSjuRc4TtFGmRndvVukAwAiY=@protonmail.com>
 <xk6TD_XVlJodelVrD6HTzj-YZ6MaRJ8lU_ugEddOixoQfCmn59oQYKw-QZOwjL7b_LENm1Jza4NtBKAaXWqwHwcOOyvwlUbJuKw7f5lkm1s=@protonmail.com>
 <ZZgeA1KPUbLtQjoT@camus>
Feedback-ID: 43655394:user:proton
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Mailman-Approved-At: Thu, 11 Jan 2024 11:17:06 +0000
Subject: Re: [bitcoin-dev] Compressed Bitcoin Transactions
X-BeenThere: bitcoin-dev@lists.linuxfoundation.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Bitcoin Protocol Discussion <bitcoin-dev.lists.linuxfoundation.org>
List-Unsubscribe: <https://lists.linuxfoundation.org/mailman/options/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=unsubscribe>
List-Archive: <http://lists.linuxfoundation.org/pipermail/bitcoin-dev/>
List-Post: <mailto:bitcoin-dev@lists.linuxfoundation.org>
List-Help: <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=help>
List-Subscribe: <https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev>, 
 <mailto:bitcoin-dev-request@lists.linuxfoundation.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Jan 2024 15:32:00 -0000

Hi,

After reviewing all the feedback and writing a reference implementation, I =
have linked the updated schema and a Draft PR for a reference Implementatio=
n to Bitcoin Core.

Some of the major changes consist of:=20

Removing the grinding of the nLocktime in favor of a relative block height,=
 which all of the Compressed Inputs use.
And the use of a second kind of Variable Integer.


Compressed Transaction Schema:

compressed_transactions.md

Reference Impl/Draft PR:

https://github.com/bitcoin/bitcoin/pull/29134

Thanks-
Tom.

=3D=3D=3D begin compressed_transactions.md =3D=3D=3D

# Compressed Transaction Schema
By (Tom Briar) and (Andrew Poelstra)

## 1. Abstract

With this Transaction Compression Schema we use several methods to compress=
 transactions,
including dropping data and recovering it on decompression by grinding unti=
l we obtain
valid signatures.

The bulk of our size savings come from replacing the prevout of each input =
by a block
height and index. This requires the decompression to have access to the blo=
ckchain, and
also means that compression is ineffective for transactions that spend unco=
nfirmed or
insufficiently confirmed outputs.

Even without compression, Taproot keyspends are very small: as witness data=
 they
include only a single 64/65-byte signature and do not repeat the public key=
 or
any other metadata. By using pubkey recovery, we obtain Taproot-like compre=
ssion
for legacy and Segwit transactions.

The main applications for this schema are for steganography, satellite/radi=
o broadcast, and
other low bandwidth channels with a high CPU availability on decompression.=
 We
assume users have some ability to shape their transactions to improve their
compressibility, and therefore give special treatment to certain transactio=
n forms.

This schema is easily reversible except for compressing the Txid/Vout input=
 pairs(Method 4).
Compressing the input Txid/Vout is optional, and without it still gleans 50=
% of the
total compression. This allows for the additional use case of P2P communica=
tion.

## 2. Methods

The four main methods to achieve a lower transactions size are:

1. packing transaction metadata before the transaction and each of its inpu=
ts and
outputs to determine the structure of the following data.
2. replacing 32-bit numeric values with either variable-length integers (Va=
rInts) or compact-integers (CompactSizes).
3. using compressed signatures and public key recovery upon decompression.
4. replacing the 36-byte txid/vout pair with a blockheight and output index=
.

Method 4 will cause the compressed transaction to be undecompressable if a =
block
reorg occurs at or before the block it's included in. Therefore, we'll only=
 compress
the Txid if the transaction input is at least one hundred blocks old.


## 3 Schema

### 3.1 Primitives

| Name             | Width     | Description |
|------------------|-----------|-------------|
| CompactSize      | 1-5 Bytes | For 0-253, encode the value directly in on=
e byte. For 254-65535, encode 254 followed by 2 little-endian bytes. For 65=
536-(2^32-1), encode 255 followed by 4 little-endian bytes. |
| CompactSize flag | 2 Bits    | 1, 2 or 3 indicate literal values. 0 indic=
ates that the value will be encoded in a later CompactInt. |
| VarInt           | 1+ Bytes  | 7-bit little-endian encoding, with each 7-=
bit word encoded in a byte. The highest bit of each byte is 1 if more bytes=
 follow, and 0 for the last byte. |
| VLP-Bytestream   | 2+ Bytes  | A VarInt Length Prefixed Bytestream. Has a=
 VarInt prefixed to determine the length. |

### 3.2 General Schema

| Name                           | Width           | Description |
|--------------------------------|-----------------|-------------|
| Transaction Metadata           | 1 Byte    | Information on the structure=
 of the transaction. See Section 3.3. |
| Version                        | 0-5 Bytes | An optional CompactSize cont=
aining the transactions version. |
| Input Count                    | 0-5 Bytes | An optional CompactSize cont=
aining the transactions input count. |
| Output Count                   | 0-5 Bytes | An optional CompactSize cont=
aining the transactions output count. |
| LockTime                       | 0-5 Bytes | An optional CompactSize cont=
aining the transaction LockTime if its non zero. |
| Minimum Blockheight            | 1-5 Bytes | A VarInt containing the Mini=
mum Blockheight of which the transaction locktime and input blockheights ar=
e given as offsets. |
| Input Metadata+Output Metadata | 1+ Bytes  | A Encoding containing metada=
ta on all the inputs and then all the outputs of the transaction. For each =
input see Section 3.4, for each output see Section 3.5. |
| Input Data                     | 66+ Bytes | See Section 3.6 for each inp=
ut. |
| Output Data                    | 3+ Bytes  | See Section 3.7 for each out=
put. |

For the four CompactSize listed above we could use a more compact bit encod=
ing for these but they are already a fall back for the bit encoding of the =
Transaction Metadata.

### 3.3 Transaction Metadata

| Name         | Width  | Description |
|--------------|--------|-------------|
| Version      | 2 Bits | A CompactSize flag for the transaction version. |
| Input Count  | 2 Bits | A CompactSize flag for the transaction input coun=
t. |
| Output Count | 2 Bits | A CompactSize flag for the transaction output cou=
nt. |
| LockTime     | 1 Bit  | A Boolean to indicate if the transaction has a Lo=
ckTime. |

### 3.4 Input Metadata

| Name                 | Width  | Description |
|----------------------|--------|-------------|
| Compressed Signature | 1 Bit  | Signature compression flag. For P2TR: 1 f=
or keyspend, 0 for scriptspend; For P2SH: 0 for p2sh, 1 for p2sh-wpkh. |
| Standard Hash        | 1 Bit  | A flag to determine if this Input's Signa=
ture Hash Type is standard (0x00 for Taproot, 0x01 for Legacy/Segwit). |
| Standard Sequence    | 2 Bits | A CompactSize flag for the inputs sequenc=
e. Encode literal values as follows: 1 =3D 0x00000000, 2 =3D 0xFFFFFFFE, 3 =
=3D 0xFFFFFFFF. |

### 3.5.1 Output Metadata

| Name                | Width  | Description |
|---------------------|--------|-------------|
| Encoded Script Type | 3 Bits | Encoded Script Type. |

#### 3.5.2 Script Type encoding

| Script Type                | Value |
|----------------------------|-------|
| Uncompressed P2PK          | 0b000 |
| Compressed P2PK            | 0b001 |
| P2PKH                      | 0b010 |
| P2SH                       | 0b011 |
| P2WSH                      | 0b100 |
| P2WPKH                     | 0b101 |
| P2TR                       | 0b110 |
| Uncompressed Custom Script | 0b111 |

### 3.6 Input Data

| Name                    | Width     | Description |
|-------------------------|-----------|-------------|
| Sequence                | 0-5 Bytes | An Optional VarInt containing the s=
equence if it was non-standard. |
| Txid Blockheight        | 1-5 Bytes | A VarInt Either containing 0 if thi=
s an uncompressed input, or it contains the offset from Minimum Blockheight=
 for this Txid. |
| Txid/Signature Data     | 65+ Bytes | Txid/Signatures are determined to b=
e uncompressed either by the output script of the previous transaction, or =
if the Txid Blockheight is zero. For each Compressed Txid/Signature See Sec=
tion 3.6.1. For each Uncompressed Txid/Signature See Section 3.6.2. |

### 3.6.1 Compressed Txid/Signature Data

| Name              | Width     | Description |
|-------------------|-----------|-------------|
| Txid Block Index  | 1-5 Bytes | A VarInt containing the flattened index f=
rom the Txid Blockheight for the Vout. |
| Signature         | 64 Bytes  | Contains the 64 byte signature. |
| Hash Type         | 0-1 Bytes | An Optional Byte containing the Hash Type=
 if it was non-standard.|

### 3.6.2 Uncompressed Txid/Signature Data

| Name      | Width     | Description |
|-----------|-----------|-------------|
| Txid      | 32 Bytes  | Contains the 32 byte Txid. |
| Vout      | 1-5 Bytes | A CompactSize Containing the Vout of the Txid. |
| Signature | 2+ Bytes  | A VLP-Bytestream containing the signature. |

### 3.7 Output Data

| Name          | Width     | Description |
|---------------|-----------|-------------|
| Output Script | 2+ Bytes  | A VLP-Bytestream containing the output script=
. |
| Amount        | 1-9 Bytes | A VarInt containing the output amount. |

## 4 Ideal Transaction

The target transaction for the most optimal compression was chosen
based off the most common transactions that are likely to be used
for purposes that requires the best compression.

| Field           | Requirements                      | Possible Savings   =
               |
|-----------------|-----------------------------------|--------------------=
---------------|
| Version         | Less than four                    | 30 Bits            =
               |
| Input Count     | Less then four                    | 30 Bits            =
               |
| Output Count    | Less then four                    | 30 Bits            =
               |
| LockTime        | 0                                 | 30 Bits            =
               |
| Input Sequence  | 0x00, 0xFFFFFFFE, or 0xFFFFFFFF   | 62 Bits For Each In=
put            |
| Input Txid      | Compressed Outpoint               | 23-31 Bytes For Eac=
h Input        |
| Input Vout      | Compressed Outpoint               | (-1)-3 Bytes For Ea=
ch Input       |
| Input Signature | Non-custom Script Signing         | 40-72 Bytes For Eac=
h Legacy Input |
| Input Hash Type | 0x00 for Taproot, 0x01 for Legacy | 7 Bits For Each Inp=
ut             |
| Output Script   | Non-custom Scripts                | 2-5 Bytes For Each =
Output         |
| Output Amount   | No Restrictions                   | (-1)-7 Bytes For Ea=
ch Output      |

## 5 Test Vectors

| Transaction              | Before Compression | Possible Savings         =
| After Compression |
|--------------------------|--------------------|--------------------------=
|-------------------|
| 2-(input/output) Taproot | 312 Bytes          | 78-124 Bytes and 2 Bits  =
| 190-226 Bytes     |
| 2-(input/output) Legacy  | 394 Bytes          | 118-196 Bytes and 2 Bits =
| 176-244 Bytes     |

Taproot (Uncompressed)

020000000001028899af77861ede1ee384c333974722c96eabba8889506725b00735fc35ba4=
1680000000000000000008899af77861ede1ee384c333974722c96eabba8889506725b00735=
fc35ba41680000000000000000000288130000000000002251206b10142cffb29e9d83f63a7=
7a428be41f96bd9b6ccc9889e4ec74927058b41dda00f000000000000225120dd00ac641dc0=
f399e62a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd20140f3d9bcc844eab7055a1=
68a62f65b8625e3853fad8f834d5c82fdf23100b7b871cf48c2c956e7d76cdd367bbfefe496=
c426e64dcfeaef800ab9893142050714b6014081c15fe5ed6b8a0c0509e871dfbb7784ddb22=
dd33b47f3ad1a3b271d29acfe76b5152b53ed29a7f6ea27cb4f5882064da07e8430aacafab8=
9a334b32780fcb2700000000


Taproot (Compressed)

2ab0dd0177d801ad1cf3d9bcc844eab7055a168a62f65b8625e3853fad8f834d5c82fdf2310=
0b7b871cf48c2c956e7d76cdd367bbfefe496c426e64dcfeaef800ab9893142050714b601ad=
1c81c15fe5ed6b8a0c0509e871dfbb7784ddb22dd33b47f3ad1a3b271d29acfe76b5152b53e=
d29a7f6ea27cb4f5882064da07e8430aacafab89a334b32780fcb276b10142cffb29e9d83f6=
3a77a428be41f96bd9b6ccc9889e4ec74927058b41dda608dd00ac641dc0f399e62a6ed6300=
aba1ec5fa4b3aeedf1717901e0d49d980efd29e20


Legacy (Uncompressed)

02000000000102c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec18b926b8dc=
549000000000000000000c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec18b=
926b8dc5490000000000000000000288130000000000002251206b10142cffb29e9d83f63a7=
7a428be41f96bd9b6ccc9889e4ec74927058b41dda00f000000000000225120dd00ac641dc0=
f399e62a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd202473044022000d1c81efcf=
6d20d87253749bcef8bf1be7ba51ccdf7a3b328174ea874226c3c02202d810c20f92d49c821=
eaa6e3a9ec7d764e0e71006e572d6ea96b631bd921767c0121037833d05665f3b21c479583e=
e12c6c573d1f25977dedfae12c70c18ec9dd4618702473044022000d1c81efcf6d20d872537=
49bcef8bf1be7ba51ccdf7a3b328174ea874226c3c02202d810c20f92d49c821eaa6e3a9ec7=
d764e0e71006e572d6ea96b631bd921767c0121037833d05665f3b21c479583ee12c6c573d1=
f25977dedfae12c70c18ec9dd4618700000000


Legacy (Compressed)(Uncompressed Txid/Vout)

2a8efefefe7f44d800c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec18b926=
b8dc549006c0002473044022000d1c81efcf6d20d87253749bcef8bf1be7ba51ccdf7a3b328=
174ea874226c3c02202d810c20f92d49c821eaa6e3a9ec7d764e0e71006e572d6ea96b631bd=
921767c0121037833d05665f3b21c479583ee12c6c573d1f25977dedfae12c70c18ec9dd461=
8700c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec18b926b8dc549006c000=
2473044022000d1c81efcf6d20d87253749bcef8bf1be7ba51ccdf7a3b328174ea874226c3c=
02202d810c20f92d49c821eaa6e3a9ec7d764e0e71006e572d6ea96b631bd921767c0121037=
833d05665f3b21c479583ee12c6c573d1f25977dedfae12c70c18ec9dd461876b10142cffb2=
9e9d83f63a77a428be41f96bd9b6ccc9889e4ec74927058b41dda608dd00ac641dc0f399e62=
a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd29e20



=3D=3D=3D end compressed_transactions.md =3D=3D=3D

On Friday, January 5th, 2024 at 10:19 AM, Andrew Poelstra via bitcoin-dev <=
bitcoin-dev@lists.linuxfoundation.org> wrote:


> Thanks Tom.
>=20
> It looks like you posted a text-scrape of the rendered markdown, which
> is hard to read. For posterity here is the full text.
>=20
> Best
> Andrew
>=20
>=20
> =3D=3D=3D begin compressed_transactions.md =3D=3D=3D
>=20
> # Compressed Transaction Schema
> By (Tom Briar) and (Andrew Poelstra)
>=20
> ## 1. Abstract
>=20
> With this Transaction Compression Schema we use several methods to compre=
ss transactions,
> including dropping data and recovering it on decompression by grinding un=
til we obtain
> valid signatures.
>=20
> The bulk of our size savings come from replacing the prevout of each inpu=
t by a block
> height and index. This requires the decompression to have access to the b=
lockchain, and
> also means that compression is ineffective for transactions that spend un=
confirmed or
> insufficiently confirmed outputs.
>=20
> Even without compression, Taproot keyspends are very small: as witness da=
ta they
> include only a single 64/65-byte signature and do not repeat the public k=
ey or
> any other metadata. By using pubkey recovery, we obtain Taproot-like comp=
ression
> for legacy and Segwit transactions.
>=20
> The main applications for this schema are for steganography, satellite/ra=
dio broadcast, and
> other low bandwidth channels with a high CPU availability on decompressio=
n. We
> assume users have some ability to shape their transactions to improve the=
ir
> compressibility, and therefore give special treatment to certain transact=
ion forms.
>=20
> This schema is easily reversible except for compressing the Txid/Vout inp=
ut pairs(Method 4).
> Compressing the input Txid/Vout is optional, and without it still gleans =
50% of the
> total compression. This allows for the additional use case of P2P communi=
cation.
>=20
> ## 2. Methods
>=20
> The four main methods to achieve a lower transactions size are:
>=20
> 1. packing transaction metadata before the transaction and each of its in=
puts and
> outputs to determine the structure of the following data.
> 2. replacing 32-bit numeric values with either variable-length integers (=
VarInts) or compact-integers (CompactSizes).
> 3. using compressed signatures and public key recovery upon decompression=
.
> 4. replacing the 36-byte txid/vout pair with a blockheight and output ind=
ex.
>=20
> Method 4 will cause the compressed transaction to be undecompressable if =
a block
> reorg occurs at or before the block it's included in. Therefore, we'll on=
ly compress
> the Txid if the transaction input is at least one hundred blocks old.
>=20
>=20
> ## 3 Schema
>=20
> ### 3.1 Primitives
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> CompactSize
>=20
> 1-5 Bytes
>=20
> For 0-253, encode the value directly in one byte. For 254-65535, encode 2=
54 followed by 2 little-endian bytes. For 65536-(2^32-1), encode 255 follow=
ed by 4 little-endian bytes.
>=20
> CompactSize flag
>=20
> 2 Bits
>=20
> 1, 2 or 3 indicate literal values. 0 indicates that the value will be enc=
oded in a later CompactInt.
>=20
> VarInt
>=20
> 1+ Bytes
>=20
> 7-bit little-endian encoding, with each 7-bit word encoded in a byte. The=
 highest bit of each byte is 1 if more bytes follow, and 0 for the last byt=
e.
>=20
> VLP-Bytestream
>=20
> 2+ Bytes
>=20
> A VarInt Length Prefixed Bytestream. Has a VarInt prefixed to determine t=
he length.
>=20
> ### 3.2 General Schema
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> --------------------------------
>=20
> -----------------
>=20
> -------------
>=20
> Transaction Metadata
>=20
> 1 Byte
>=20
> Information on the structure of the transaction. See Section 3.3.
>=20
> Version
>=20
> 0-5 Bytes
>=20
> An optional CompactSize containing the transactions version.
>=20
> Input Count
>=20
> 0-5 Bytes
>=20
> An optional CompactSize containing the transactions input count.
>=20
> Output Count
>=20
> 0-5 Bytes
>=20
> An optional CompactSize containing the transactions output count.
>=20
> LockTime
>=20
> 0-5 Bytes
>=20
> An optional CompactSize containing the transaction LockTime if its non ze=
ro.
>=20
> Minimum Blockheight
>=20
> 1-5 Bytes
>=20
> A VarInt containing the Minimum Blockheight of which the transaction lock=
time and input blockheights are given as offsets.
>=20
> Input Metadata+Output Metadata
>=20
> 1+ Bytes
>=20
> A Encoding containing metadata on all the inputs and then all the outputs=
 of the transaction. For each input see Section 3.4, for each output see Se=
ction 3.5.
>=20
> Input Data
>=20
> 66+ Bytes
>=20
> See Section 3.6 for each input.
>=20
> Output Data
>=20
> 3+ Bytes
>=20
> See Section 3.7 for each output.
>=20
> For the four CompactSize listed above we could use a more compact bit enc=
oding for these but they are already a fall back for the bit encoding of th=
e Transaction Metadata.
>=20
> ### 3.3 Transaction Metadata
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> --------------
>=20
> --------
>=20
> -------------
>=20
> Version
>=20
> 2 Bits
>=20
> A CompactSize flag for the transaction version.
>=20
> Input Count
>=20
> 2 Bits
>=20
> A CompactSize flag for the transaction input count.
>=20
> Output Count
>=20
> 2 Bits
>=20
> A CompactSize flag for the transaction output count.
>=20
> LockTime
>=20
> 1 Bit
>=20
> A Boolean to indicate if the transaction has a LockTime.
>=20
> ### 3.4 Input Metadata
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> ----------------------
>=20
> --------
>=20
> -------------
>=20
> Compressed Signature
>=20
> 1 Bit
>=20
> Signature compression flag. For P2TR: 1 for keyspend, 0 for scriptspend; =
For P2SH: 0 for p2sh, 1 for p2sh-wpkh.
>=20
> Standard Hash
>=20
> 1 Bit
>=20
> A flag to determine if this Input's Signature Hash Type is standard (0x00=
 for Taproot, 0x01 for Legacy/Segwit).
>=20
> Standard Sequence
>=20
> 2 Bits
>=20
> A CompactSize flag for the inputs sequence. Encode literal values as foll=
ows: 1 =3D 0x00000000, 2 =3D 0xFFFFFFFE, 3 =3D 0xFFFFFFFF.
>=20
> ### 3.5.1 Output Metadata
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> ---------------------
>=20
> --------
>=20
> -------------
>=20
> Encoded Script Type
>=20
> 3 Bits
>=20
> Encoded Script Type.
>=20
> #### 3.5.2 Script Type encoding
>=20
> Script Type
>=20
> Value
>=20
> ----------------------------
>=20
> -------
>=20
> Uncompressed P2PK
>=20
> 0b000
>=20
> Compressed P2PK
>=20
> 0b001
>=20
> P2PKH
>=20
> 0b010
>=20
> P2SH
>=20
> 0b011
>=20
> P2WSH
>=20
> 0b100
>=20
> P2WPKH
>=20
> 0b101
>=20
> P2TR
>=20
> 0b110
>=20
> Uncompressed Custom Script
>=20
> 0b111
>=20
> ### 3.6 Input Data
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> -------------------------
>=20
> -----------
>=20
> -------------
>=20
> Sequence
>=20
> 0-5 Bytes
>=20
> An Optional VarInt containing the sequence if it was non-standard.
>=20
> Txid Blockheight
>=20
> 1-5 Bytes
>=20
> A VarInt Either containing 0 if this an uncompressed input, or it contain=
s the offset from Minimum Blockheight for this Txid.
>=20
> Txid/Signature Data
>=20
> 65+ Bytes
>=20
> Txid/Signatures are determined to be uncompressed either by the output sc=
ript of the previous transaction, or if the Txid Blockheight is zero. For e=
ach Compressed Txid/Signature See Section 3.6.1. For each Uncompressed Txid=
/Signature See Section 3.6.2.
>=20
> ### 3.6.1 Compressed Txid/Signature Data
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> -------------------
>=20
> -----------
>=20
> -------------
>=20
> Txid Block Index
>=20
> 1-5 Bytes
>=20
> A VarInt containing the flattened index from the Txid Blockheight for the=
 Vout.
>=20
> Signature
>=20
> 64 Bytes
>=20
> Contains the 64 byte signature.
>=20
> Hash Type
>=20
> 0-1 Bytes
>=20
> An Optional Byte containing the Hash Type if it was non-standard.
>=20
> ### 3.6.2 Uncompressed Txid/Signature Data
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> -----------
>=20
> -----------
>=20
> -------------
>=20
> Txid
>=20
> 32 Bytes
>=20
> Contains the 32 byte Txid.
>=20
> Vout
>=20
> 1-5 Bytes
>=20
> A CompactSize Containing the Vout of the Txid.
>=20
> Signature
>=20
> 2+ Bytes
>=20
> A VLP-Bytestream containing the signature.
>=20
> ### 3.7 Output Data
>=20
> Name
>=20
> Width
>=20
> Description
>=20
> ---------------
>=20
> -----------
>=20
> -------------
>=20
> Output Script
>=20
> 2+ Bytes
>=20
> A VLP-Bytestream containing the output script.
>=20
> Amount
>=20
> 1-9 Bytes
>=20
> A VarInt containing the output amount.
>=20
> ## 4 Ideal Transaction
>=20
> The target transaction for the most optimal compression was chosen
>=20
> based off the most common transactions that are likely to be used
>=20
> for purposes that requires the best compression.
>=20
> Field
>=20
> Requirements
>=20
> Possible Savings
>=20
> -----------------
>=20
> -----------------------------------
>=20
> -----------------------------------
>=20
> Version
>=20
> Less than four
>=20
> 30 Bits
>=20
> Input Count
>=20
> Less then four
>=20
> 30 Bits
>=20
> Output Count
>=20
> Less then four
>=20
> 30 Bits
>=20
> LockTime
>=20
> 0
>=20
> 30 Bits
>=20
> Input Sequence
>=20
> 0x00, 0xFFFFFFFE, or 0xFFFFFFFF
>=20
> 62 Bits For Each Input
>=20
> Input Txid
>=20
> Compressed Outpoint
>=20
> 23-31 Bytes For Each Input
>=20
> Input Vout
>=20
> Compressed Outpoint
>=20
> (-1)-3 Bytes For Each Input
>=20
> Input Signature
>=20
> Non-custom Script Signing
>=20
> 40-72 Bytes For Each Legacy Input
>=20
> Input Hash Type
>=20
> 0x00 for Taproot, 0x01 for Legacy
>=20
> 7 Bits For Each Input
>=20
> Output Script
>=20
> Non-custom Scripts
>=20
> 2-5 Bytes For Each Output
>=20
> Output Amount
>=20
> No Restrictions
>=20
> (-1)-7 Bytes For Each Output
>=20
> ## 5 Test Vectors
>=20
> Transaction
>=20
> Before Compression
>=20
> Possible Savings
>=20
> --------------------------
>=20
> --------------------
>=20
> --------------------------
>=20
> 2-(input/output) Taproot
>=20
> 312 Bytes
>=20
> 78-124 Bytes and 2 Bits
>=20
> 2-(input/output) Legacy
>=20
> 394 Bytes
>=20
> 118-196 Bytes and 2 Bits
>=20
> Taproot (Uncompressed)
>=20
> ```
>=20
> 020000000001028899af77861ede1ee384c333974722c96eabba8889506725b00735fc35b=
a41680000000000000000008899af77861ede1ee384c333974722c96eabba8889506725b007=
35fc35ba41680000000000000000000288130000000000002251206b10142cffb29e9d83f63=
a77a428be41f96bd9b6ccc9889e4ec74927058b41dda00f000000000000225120dd00ac641d=
c0f399e62a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd20140f3d9bcc844eab7055=
a168a62f65b8625e3853fad8f834d5c82fdf23100b7b871cf48c2c956e7d76cdd367bbfefe4=
96c426e64dcfeaef800ab9893142050714b6014081c15fe5ed6b8a0c0509e871dfbb7784ddb=
22dd33b47f3ad1a3b271d29acfe76b5152b53ed29a7f6ea27cb4f5882064da07e8430aacafa=
b89a334b32780fcb2700000000
>=20
> ```
>=20
> Taproot (Compressed)
>=20
> ```
>=20
> 2a81de3177d8019c2ef3d9bcc844eab7055a168a62f65b8625e3853fad8f834d5c82fdf23=
100b7b871cf48c2c956e7d76cdd367bbfefe496c426e64dcfeaef800ab9893142050714b601=
9c2e81c15fe5ed6b8a0c0509e871dfbb7784ddb22dd33b47f3ad1a3b271d29acfe76b5152b5=
3ed29a7f6ea27cb4f5882064da07e8430aacafab89a334b32780fcb276b10142cffb29e9d83=
f63a77a428be41f96bd9b6ccc9889e4ec74927058b41dd8827dd00ac641dc0f399e62a6ed63=
00aba1ec5fa4b3aeedf1717901e0d49d980efd2a01f
>=20
> ```
>=20
> Legacy (Uncompressed)
>=20
> ```
>=20
> 02000000000102c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec18b926b8=
dc549000000000000000000c583fe4f934a0ed87e4d082cd52967cc774b943fbb2e21378ec1=
8b926b8dc5490000000000000000000288130000000000002251206b10142cffb29e9d83f63=
a77a428be41f96bd9b6ccc9889e4ec74927058b41dda00f000000000000225120dd00ac641d=
c0f399e62a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd202473044022000d1c81ef=
cf6d20d87253749bcef8bf1be7ba51ccdf7a3b328174ea874226c3c02202d810c20f92d49c8=
21eaa6e3a9ec7d764e0e71006e572d6ea96b631bd921767c0121037833d05665f3b21c47958=
3ee12c6c573d1f25977dedfae12c70c18ec9dd4618702473044022000d1c81efcf6d20d8725=
3749bcef8bf1be7ba51ccdf7a3b328174ea874226c3c02202d810c20f92d49c821eaa6e3a9e=
c7d764e0e71006e572d6ea96b631bd921767c0121037833d05665f3b21c479583ee12c6c573=
d1f25977dedfae12c70c18ec9dd4618700000000
>=20
> ```
>=20
> Legacy (Compressed)
>=20
> ```
>=20
> 2ad1e53044d801ae276c0002473044022000d1c81efcf6d20d87253749bcef8bf1be7ba51=
ccdf7a3b328174ea874226c3c02202d810c20f92d49c821eaa6e3a9ec7d764e0e71006e572d=
6ea96b631bd921767c0121037833d05665f3b21c479583ee12c6c573d1f25977dedfae12c70=
c18ec9dd461870001ae276c0002473044022000d1c81efcf6d20d87253749bcef8bf1be7ba5=
1ccdf7a3b328174ea874226c3c02202d810c20f92d49c821eaa6e3a9ec7d764e0e71006e572=
d6ea96b631bd921767c0121037833d05665f3b21c479583ee12c6c573d1f25977dedfae12c7=
0c18ec9dd46187006b10142cffb29e9d83f63a77a428be41f96bd9b6ccc9889e4ec74927058=
b41dd8827dd00ac641dc0f399e62a6ed6300aba1ec5fa4b3aeedf1717901e0d49d980efd2a0=
1f
>=20
> ```
>=20
> --
>=20
> Andrew Poelstra
>=20
> Director of Research, Blockstream
>=20
> Email: apoelstra at wpsoftware.net
>=20
> Web: https://www.wpsoftware.net/andrew
>=20
> The sun is always shining in space
>=20
> -Justin Lewis-Webster
>=20
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists.linuxfoundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev