-
Notifications
You must be signed in to change notification settings - Fork 355
/
avm-transaction-serialization.md
2056 lines (1778 loc) · 86.7 KB
/
avm-transaction-serialization.md
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
# AVM Transaction Format
This file is meant to be the single source of truth for how we serialize transactions in the Avalanche Virtual Machine \(AVM\). This document uses the [primitive serialization](serialization-primitives.md) format for packing and [secp256k1](cryptographic-primitives.md#secp256k1-addresses) for cryptographic user identification.
## Codec ID
Some data is prepended with a codec ID \(unt16\) that denotes how the data should be deserialized. Right now, the only valid codec ID is 0 \(`0x00 0x00`\).
## Transferable Output
Transferable outputs wrap an output with an asset ID.
### What Transferable Output Contains
A transferable output contains an `AssetID` and an [`Output`](avm-transaction-serialization.md#outputs).
* **`AssetID`** is a 32-byte array that defines which asset this output references.
* **`Output`** is an output, as defined [below](avm-transaction-serialization.md#outputs). For example, this can be a [SECP256K1 transfer output](avm-transaction-serialization.md#secp256k1-transfer-output).
### Gantt Transferable Output Specification
```text
+----------+----------+-------------------------+
| asset_id : [32]byte | 32 bytes |
+----------+----------+-------------------------+
| output : Output | size(output) bytes |
+----------+----------+-------------------------+
| 32 + size(output) bytes |
+-------------------------+
```
### Proto Transferable Output Specification
```text
message TransferableOutput {
bytes asset_id = 1; // 32 bytes
Output output = 2; // size(output)
}
```
### Transferable Output Example
Let’s make a transferable output:
* `AssetID`: `0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f`
* `Output`: `"Example SECP256K1 Transfer Output from below"`
```text
[
AssetID <- 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Output <- 0x000000070000000000003039000000000000d431000000010000000251025c61fbcfc078f69334f834be6dd26d55a955c3344128e060128ede3523a24a461c8943ab0859,
]
=
[
// assetID:
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
// output:
0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x39, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xd4, 0x31, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x02, 0x51, 0x02, 0x5c, 0x61,
0xfb, 0xcf, 0xc0, 0x78, 0xf6, 0x93, 0x34, 0xf8,
0x34, 0xbe, 0x6d, 0xd2, 0x6d, 0x55, 0xa9, 0x55,
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## Transferable Input
Transferable inputs describe a specific UTXO with a provided transfer input.
### What Transferable Input Contains
A transferable input contains a `TxID`, `UTXOIndex` `AssetID` and an `Input`.
* **`TxID`** is a 32-byte array that defines which transaction this input is consuming an output from. Transaction IDs are calculated by taking sha256 of the bytes of the signed transaction.
* **`UTXOIndex`** is an int that defines which utxo this input is consuming in the specified transaction.
* **`AssetID`** is a 32-byte array that defines which asset this input references.
* **`Input`** is an input, as defined below. This can currently only be a [SECP256K1 transfer input](avm-transaction-serialization.md#secp256k1-transfer-input)
### Gantt Transferable Input Specification
```text
+------------+----------+------------------------+
| tx_id : [32]byte | 32 bytes |
+------------+----------+------------------------+
| utxo_index : int | 04 bytes |
+------------+----------+------------------------+
| asset_id : [32]byte | 32 bytes |
+------------+----------+------------------------+
| input : Input | size(input) bytes |
+------------+----------+------------------------+
| 68 + size(input) bytes |
+------------------------+
```
### Proto Transferable Input Specification
```text
message TransferableInput {
bytes tx_id = 1; // 32 bytes
uint32 utxo_index = 2; // 04 bytes
bytes asset_id = 3; // 32 bytes
Input input = 4; // size(input)
}
```
### Transferable Input Example
Let’s make a transferable input:
* `TxID`: `0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000`
* `UTXOIndex`: `5`
* `AssetID`: `0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f`
* `Input`: `"Example SECP256K1 Transfer Input from below"`
```text
[
TxID <- 0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000
UTXOIndex <- 0x00000005
AssetID <- 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
Input <- 0x0000000500000000075bcd15000000020000000700000003
]
=
[
// txID:
0xf1, 0xe1, 0xd1, 0xc1, 0xb1, 0xa1, 0x91, 0x81,
0x71, 0x61, 0x51, 0x41, 0x31, 0x21, 0x11, 0x01,
0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0x90, 0x80,
0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
// utxoIndex:
0x00, 0x00, 0x00, 0x05,
// assetID:
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
// input:
0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
0x07, 0x5b, 0xcd, 0x15, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07
]
```
## Transferable Op
Transferable operations describe a set of UTXOs with a provided transfer operation. Only one Asset ID is able to be referenced per operation.
### What Transferable Op Contains
A transferable operation contains an `AssetID`, `UTXOIDs`, and a `TransferOp`.
* **`AssetID`** is a 32-byte array that defines which asset this operation changes.
* **`UTXOIDs`** is an array of TxID-OutputIndex tuples. This array must be sorted in lexicographical order.
* **`TransferOp`** is a [transferable operation object](avm-transaction-serialization.md#operations).
### Gantt Transferable Op Specification
```text
+-------------+------------+------------------------------+
| asset_id : [32]byte | 32 bytes |
+-------------+------------+------------------------------+
| utxo_ids : []UTXOID | 4 + 36 * len(utxo_ids) bytes |
+-------------+------------+------------------------------+
| transfer_op : TransferOp | size(transfer_op) bytes |
+-------------+------------+------------------------------+
| 36 + 36 * len(utxo_ids) |
| + size(transfer_op) bytes |
+------------------------------+
```
### Proto Transferable Op Specification
```text
message UTXOID {
bytes tx_id = 1; // 32 bytes
uint32 utxo_index = 2; // 04 bytes
}
message TransferableOp {
bytes asset_id = 1; // 32 bytes
repeated UTXOID utxo_ids = 2; // 4 + 36 * len(utxo_ids) bytes
TransferOp transfer_op = 3; // size(transfer_op)
}
```
### Transferable Op Example
Let’s make a transferable operation:
* `AssetID`: `0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f`
* `UTXOIDs`:
* `UTXOID`:
* `TxID`: `0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000`
* `UTXOIndex`: `5`
* `Op`: `"Example Transfer Op from below"`
```text
[
AssetID <- 0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
UTXOIDs <- [
{
TxID:0xf1e1d1c1b1a191817161514131211101f0e0d0c0b0a090807060504030201000
UTXOIndex:5
}
]
Op <- 0x0000000d0000000200000003000000070000303900000003431100000000010000000251025c61fbcfc078f69334f834be6dd26d55a955c3344128e060128ede3523a24a461c8943ab0859
]
=
[
// assetID:
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
// number of utxoIDs:
0x00, 0x00, 0x00, 0x01,
// txID:
0xf1, 0xe1, 0xd1, 0xc1, 0xb1, 0xa1, 0x91, 0x81,
0x71, 0x61, 0x51, 0x41, 0x31, 0x21, 0x11, 0x01,
0xf0, 0xe0, 0xd0, 0xc0, 0xb0, 0xa0, 0x90, 0x80,
0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0x00,
// utxoIndex:
0x00, 0x00, 0x00, 0x05,
// op:
0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x02,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x07,
0x00, 0x00, 0x30, 0x39, 0x00, 0x00, 0x00, 0x03,
0x43, 0x11, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x02, 0x51, 0x02, 0x5c, 0x61, 0xfb,
0xcf, 0xc0, 0x78, 0xf6, 0x93, 0x34, 0xf8, 0x34,
0xbe, 0x6d, 0xd2, 0x6d, 0x55, 0xa9, 0x55, 0xc3,
0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e, 0xde,
0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89, 0x43,
0xab, 0x08, 0x59,
]
```
## Outputs
Outputs have four possible types: [`SECP256K1TransferOutput`](avm-transaction-serialization.md#secp256k1-transfer-output), [`SECP256K1MintOutput`](avm-transaction-serialization.md#secp256k1-mint-output), [`NFTTransferOutput`](avm-transaction-serialization.md#nft-transfer-output) and [`NFTMintOutput`](avm-transaction-serialization.md#nft-mint-output).
## SECP256K1 Transfer Output
A [secp256k1](cryptographic-primitives.md#secp-256-k1-addresses) transfer output allows for sending a quantity of an asset to a collection of addresses after a specified unix time.
### **What SECP256K1 Transfer Output Contains**
A secp256k1 transfer output contains a `TypeID`, `Amount`, `Locktime`, `Threshold`, and `Addresses`.
* **`TypeID`** is the ID for this output type. It is `0x00000007`.
* **`Amount`** is a long that specifies the quantity of the asset that this output owns. Must be positive.
* **`Locktime`** is a long that contains the unix timestamp that this output can be spent after. The unix timestamp is specific to the second.
* **`Threshold`** is an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length of **`Addresses`**. If **`Addresses`** is empty, must be 0.
* **`Addresses`** is a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
### **Gantt SECP256K1 Transfer Output Specification**
```text
+-----------+------------+--------------------------------+
| type_id : int | 4 bytes |
+-----------+------------+--------------------------------+
| amount : long | 8 bytes |
+-----------+------------+--------------------------------+
| locktime : long | 8 bytes |
+-----------+------------+--------------------------------+
| threshold : int | 4 bytes |
+-----------+------------+--------------------------------+
| addresses : [][20]byte | 4 + 20 * len(addresses) bytes |
+-----------+------------+--------------------------------+
| 28 + 20 * len(addresses) bytes |
+--------------------------------+
```
### **Proto SECP256K1 Transfer Output Specification**
```text
message SECP256K1TransferOutput {
uint32 typeID = 1; // 04 bytes
uint64 amount = 2; // 08 bytes
uint64 locktime = 3; // 08 bytes
uint32 threshold = 4; // 04 bytes
repeated bytes addresses = 5; // 04 bytes + 20 bytes * len(addresses)
}
```
### **SECP256K1 Transfer Output Example**
Let’s make a secp256k1 transfer output with:
* **`TypeID`**: `7`
* **`Amount`**: `12345`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0x51025c61fbcfc078f69334f834be6dd26d55a955`
* `0xc3344128e060128ede3523a24a461c8943ab0859`
```text
[
TypeID <- 0x00000007
Amount <- 0x0000000000003039
Locktime <- 0x000000000000d431
Threshold <- 0x00000001
Addresses <- [
0x51025c61fbcfc078f69334f834be6dd26d55a955,
0xc3344128e060128ede3523a24a461c8943ab0859,
]
]
=
[
// typeID:
0x00, 0x00, 0x00, 0x07,
// amount:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x39,
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x02,
// addrs[0]:
0x51, 0x02, 0x5c, 0x61, 0xfb, 0xcf, 0xc0, 0x78,
0xf6, 0x93, 0x34, 0xf8, 0x34, 0xbe, 0x6d, 0xd2,
0x6d, 0x55, 0xa9, 0x55,
// addrs[1]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## SECP256K1 Mint Output
A [secp256k1](cryptographic-primitives.md#secp-256-k1-addresses) mint output is an output that is owned by a collection of addresses.
### **What SECP256K1 Mint Output Contains**
A secp256k1 Mint output contains a `TypeID`, `Locktime`, `Threshold`, and `Addresses`.
* **`TypeID`** is the ID for this output type. It is `0x00000006`.
* **`Locktime`** is a long that contains the unix timestamp that this output can be spent after. The unix timestamp is specific to the second.
* **`Threshold`** is an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length of **`Addresses`**. If **`Addresses`** is empty, must be 0.
* **`Addresses`** is a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
### **Gantt SECP256K1 Mint Output Specification**
```text
+-----------+------------+--------------------------------+
| type_id : int | 4 bytes |
+-----------+------------+--------------------------------+
| locktime : long | 8 bytes |
+-----------+------------+--------------------------------+
| threshold : int | 4 bytes |
+-----------+------------+--------------------------------+
| addresses : [][20]byte | 4 + 20 * len(addresses) bytes |
+-----------+------------+--------------------------------+
| 20 + 20 * len(addresses) bytes |
+--------------------------------+
```
### **Proto SECP256K1 Mint Output Specification**
```text
message SECP256K1MintOutput {
uint32 typeID = 1; // 04 bytes
uint64 locktime = 2; // 08 bytes
uint32 threshold = 3; // 04 bytes
repeated bytes addresses = 4; // 04 bytes + 20 bytes * len(addresses)
}
```
### **SECP256K1 Mint Output Example**
Let’s make a SECP256K1 mint output with:
* **`TypeID`**: `6`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0x51025c61fbcfc078f69334f834be6dd26d55a955`
* `0xc3344128e060128ede3523a24a461c8943ab0859`
```text
[
TypeID <- 0x00000006
Locktime <- 0x000000000000d431
Threshold <- 0x00000001
Addresses <- [
0x51025c61fbcfc078f69334f834be6dd26d55a955,
0xc3344128e060128ede3523a24a461c8943ab0859,
]
]
=
[
// typeID:
0x00, 0x00, 0x00, 0x06,
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x02,
// addrs[0]:
0x51, 0x02, 0x5c, 0x61, 0xfb, 0xcf, 0xc0, 0x78,
0xf6, 0x93, 0x34, 0xf8, 0x34, 0xbe, 0x6d, 0xd2,
0x6d, 0x55, 0xa9, 0x55,
// addrs[1]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## NFT Transfer Output
An NFT transfer output is an NFT that is owned by a collection of addresses.
### **What NFT Transfer Output Contains**
An NFT transfer output contains a `TypeID`, `GroupID`, `Payload`, `Locktime`, `Threshold`, and `Addresses`.
* **`TypeID`** is the ID for this output type. It is `0x0000000b`.
* **`GroupID`** is an int that specifies the group this NFT was issued with.
* **`Payload`** is an arbitrary string of bytes no long longer than 1024 bytes.
* **`Locktime`** is a long that contains the unix timestamp that this output can be spent after. The unix timestamp is specific to the second.
* **`Threshold`** is an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length of **`Addresses`**. If **`Addresses`** is empty, must be 0.
* **`Addresses`** is a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
### **Gantt NFT Transfer Output Specification**
```text
+-----------+------------+-------------------------------+
| type_id : int | 4 bytes |
+-----------+------------+-------------------------------+
| group_id : int | 4 bytes |
+-----------+------------+-------------------------------+
| payload : []byte | 4 + len(payload) bytes |
+-----------+------------+-------------------------------+
| locktime : long | 8 bytes |
+-----------+------------+-------------------------------+
| threshold : int | 4 bytes |
+-----------+------------+-------------------------------+
| addresses : [][20]byte | 4 + 20 * len(addresses) bytes |
+-----------+------------+-------------------------------+
| 28 + len(payload) |
| + 20 * len(addresses) bytes |
+-------------------------------+
```
### **Proto NFT Transfer Output Specification**
```text
message NFTTransferOutput {
uint32 typeID = 1; // 04 bytes
uint32 group_id = 2; // 04 bytes
bytes payload = 3; // 04 bytes + len(payload)
uint64 locktime = 4 // 08 bytes
uint32 threshold = 5; // 04 bytes
repeated bytes addresses = 6; // 04 bytes + 20 bytes * len(addresses)
}
```
### **NFT Transfer Output Example**
Let’s make an NFT transfer output with:
* **`TypeID`**: `11`
* **`GroupID`**: `12345`
* **`Payload`**: `0x431100`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0x51025c61fbcfc078f69334f834be6dd26d55a955`
* `0xc3344128e060128ede3523a24a461c8943ab0859`
```text
[
TypeID <- 0x0000000b
GroupID <- 0x00003039
Payload <- 0x431100
Locktime <- 0x000000000000d431
Threshold <- 0x00000001
Addresses <- [
0x51025c61fbcfc078f69334f834be6dd26d55a955,
0xc3344128e060128ede3523a24a461c8943ab0859,
]
]
=
[
// TypeID:
0x00, 0x00, 0x00, 0x0b,
// groupID:
0x00, 0x00, 0x30, 0x39,
// length of payload:
0x00, 0x00, 0x00, 0x03,
// payload:
0x43, 0x11, 0x00,
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x02,
// addrs[0]:
0x51, 0x02, 0x5c, 0x61, 0xfb, 0xcf, 0xc0, 0x78,
0xf6, 0x93, 0x34, 0xf8, 0x34, 0xbe, 0x6d, 0xd2,
0x6d, 0x55, 0xa9, 0x55,
// addrs[1]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## NFT Mint Output
An NFT mint output is an NFT that is owned by a collection of addresses.
### **What NFT Mint Output Contains**
An NFT Mint output contains a `TypeID`, `GroupID`, `Locktime`, `Threshold`, and `Addresses`.
* **`TypeID`** is the ID for this output type. It is `0x0000000a`.
* **`GroupID`** is an int that specifies the group this NFT is issued to.
* **`Locktime`** is a long that contains the unix timestamp that this output can be spent after. The unix timestamp is specific to the second.
* **`Threshold`** is an int that names the number of unique signatures required to spend the output. Must be less than or equal to the length of **`Addresses`**. If **`Addresses`** is empty, must be 0.
* **`Addresses`** is a list of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
### **Gantt NFT Mint Output Specification**
```text
+-----------+------------+--------------------------------+
| type_id : int | 4 bytes |
+-----------+------------+--------------------------------+
| group_id : int | 4 bytes |
+-----------+------------+--------------------------------+
| locktime : long | 8 bytes |
+-----------+------------+--------------------------------+
| threshold : int | 4 bytes |
+-----------+------------+--------------------------------+
| addresses : [][20]byte | 4 + 20 * len(addresses) bytes |
+-----------+------------+--------------------------------+
| 24 + 20 * len(addresses) bytes |
+--------------------------------+
```
### **Proto NFT Mint Output Specification**
```text
message NFTMintOutput {
uint32 typeID = 1; // 04 bytes
uint32 group_id = 2; // 04 bytes
uint64 locktime = 3; // 08 bytes
uint32 threshold = 4; // 04 bytes
repeated bytes addresses = 5; // 04 bytes + 20 bytes * len(addresses)
}
```
### **NFT Mint Output Example**
Let’s make an NFT mint output with:
* **`TypeID`**: `10`
* **`GroupID`**: `12345`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0x51025c61fbcfc078f69334f834be6dd26d55a955`
* `0xc3344128e060128ede3523a24a461c8943ab0859`
```text
[
TypeID <- 0x0000000a
GroupID <- 0x00003039
Locktime <- 0x000000000000d431
Threshold <- 0x00000001
Addresses <- [
0x51025c61fbcfc078f69334f834be6dd26d55a955,
0xc3344128e060128ede3523a24a461c8943ab0859,
]
]
=
[
// TypeID
0x00, 0x00, 0x00, 0x0a,
// groupID:
0x00, 0x00, 0x30, 0x39,
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x02,
// addrs[0]:
0x51, 0x02, 0x5c, 0x61, 0xfb, 0xcf, 0xc0, 0x78,
0xf6, 0x93, 0x34, 0xf8, 0x34, 0xbe, 0x6d, 0xd2,
0x6d, 0x55, 0xa9, 0x55,
// addrs[1]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## Inputs
Inputs have one possible type: `SECP256K1TransferInput`.
## SECP256K1 Transfer Input
A [secp256k1](cryptographic-primitives.md#secp-256-k1-addresses) transfer input allows for spending an unspent secp256k1 transfer output.
### **What SECP256K1 Transfer Input Contains**
A secp256k1 transfer input contains an `Amount` and `AddressIndices`.
* **`TypeID`** is the ID for this input type. It is `0x00000005`.
* **`Amount`** is a long that specifies the quantity that this input should be consuming from the UTXO. Must be positive. Must be equal to the amount specified in the UTXO.
* **`AddressIndices`** is a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.
### **Gantt SECP256K1 Transfer Input Specification**
```text
+-------------------------+-------------------------------------+
| type_id : int | 4 bytes |
+-----------------+-------+-------------------------------------+
| amount : long | 8 bytes |
+-----------------+-------+-------------------------------------+
| address_indices : []int | 4 + 4 * len(address_indices) bytes |
+-----------------+-------+-------------------------------------+
| 16 + 4 * len(address_indices) bytes |
+-------------------------------------+
```
### **Proto SECP256K1 Transfer Input Specification**
```text
message SECP256K1TransferInput {
uint32 typeID = 1; // 04 bytes
uint64 amount = 2; // 08 bytes
repeated uint32 address_indices = 3; // 04 bytes + 04 bytes * len(address_indices)
}
```
### **SECP256K1 Transfer Input Example**
Let’s make a payment input with:
* **`TypeId`**: `5`
* **`Amount`**: `123456789`
* **`AddressIndices`**: \[`3`,`7`\]
```text
[
TypeID <- 0x00000005
Amount <- 123456789 = 0x00000000075bcd15,
AddressIndices <- [0x00000003, 0x00000007]
]
=
[
// type id:
0x00, 0x00, 0x00, 0x05,
// amount:
0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15,
// length:
0x00, 0x00, 0x00, 0x02,
// sig[0]
0x00, 0x00, 0x00, 0x03,
// sig[1]
0x00, 0x00, 0x00, 0x07,
]
```
## Operations
Operations have three possible types: `SECP256K1MintOperation`, `NFTMintOp`, and `NFTTransferOp`.
## **SECP256K1 Mint Operation**
A [secp256k1](cryptographic-primitives.md#secp-256-k1-addresses) mint operation consumes a SECP256K1 mint output, creates a new mint output and sends a transfer output to a new set of owners.
### **What SECP256K1 Mint Operation Contains**
A secp256k1 Mint operation contains a `TypeID`, `AddressIndices`, `MintOutput`, and `TransferOutput`.
* **`TypeID`** is the ID for this output type. It is `0x00000008`.
* **`AddressIndices`** is a list of unique ints that define the private keys that are being used to spend the [UTXO](avm-transaction-serialization.md#utxo). Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.
* **`MintOutput`** is a [SECP256K1 Mint output](avm-transaction-serialization.md#secp256k1-mint-output).
* **`TransferOutput`** is a [SECP256K1 Transfer output](avm-transaction-serialization.md#secp256k1-transfer-output).
### **Gantt SECP256K1 Mint Operation Specification**
```text
+----------------------------------+------------------------------------+
| type_id : int | 4 bytes |
+----------------------------------+------------------------------------+
| address_indices : []int | 4 + 4 * len(address_indices) bytes |
+----------------------------------+------------------------------------+
| mint_output : MintOutput | size(mint_output) bytes |
+----------------------------------+------------------------------------+
| transfer_output : TransferOutput | size(transfer_output) bytes |
+----------------------------------+------------------------------------+
| 8 + 4 * len(address_indices) |
| + size(mint_output) |
| + size(transfer_output) bytes |
+------------------------------------+
```
### **Proto SECP256K1 Mint Operation Specification**
```text
message SECP256K1MintOperation {
uint32 typeID = 1; // 4 bytes
repeated uint32 address_indices = 2; // 04 bytes + 04 bytes * len(address_indices)
MintOutput mint_output = 3; // size(mint_output
TransferOutput transfer_output = 4; // size(transfer_output)
}
```
### **SECP256K1 Mint Operation Example**
Let’s make a [secp256k1](cryptographic-primitives.md#secp-256-k1-addresses) mint operation with:
* **`TypeId`**: `8`
* **`AddressIndices`**:
* `0x00000003`
* `0x00000007`
* **`MintOutput`**: `"Example SECP256K1 Mint Output from above"`
* **`TransferOutput`**: `"Example SECP256K1 Transfer Output from above"`
```text
[
TypeID <- 0x00000008
AddressIndices <- [0x00000003, 0x00000007]
MintOutput <- 0x00000006000000000000d431000000010000000251025c61fbcfc078f69334f834be6dd26d55a955c3344128e060128ede3523a24a461c89
TransferOutput <- 0x000000070000000000003039000000000000d431000000010000000251025c61fbcfc078f69334f834be6dd26d55a955c3344128e060128ede3523a24a461c8943ab0859
]
=
[
// typeID
0x00, 0x00, 0x00, 0x08,
// number of address_indices:
0x00, 0x00, 0x00, 0x02,
// address_indices[0]:
0x00, 0x00, 0x00, 0x03,
// address_indices[1]:
0x00, 0x00, 0x00, 0x07,
// mint output
0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xd4, 0x31, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x02, 0x51, 0x02, 0x5c, 0x61,
0xfb, 0xcf, 0xc0, 0x78, 0xf6, 0x93, 0x34, 0xf8,
0x34, 0xbe, 0x6d, 0xd2, 0x6d, 0x55, 0xa9, 0x55,
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
// transfer output
0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x39, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xd4, 0x31, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x02, 0x51, 0x02, 0x5c, 0x61,
0xfb, 0xcf, 0xc0, 0x78, 0xf6, 0x93, 0x34, 0xf8,
0x34, 0xbe, 0x6d, 0xd2, 0x6d, 0x55, 0xa9, 0x55,
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## NFT Mint Op
An NFT mint operation consumes an NFT mint output and sends an unspent output to a new set of owners.
### **What NFT Mint Op Contains**
An NFT mint operation contains a `TypeID`, `AddressIndices`, `GroupID`, `Payload`, and `Output` of addresses.
* **`TypeID`** is the ID for this operation type. It is `0x0000000c`.
* **`AddressIndices`** is a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.
* **`GroupID`** is an int that specifies the group this NFT is issued to.
* **`Payload`** is an arbitrary string of bytes no longer than 1024 bytes.
* **`Output`** is not a `TransferableOutput`, but rather is a locktime, threshold, and an array of unique addresses that correspond to the private keys that can be used to spend this output. Addresses must be sorted lexicographically.
### **Gantt NFT Mint Op Specification**
```text
+------------------------------+------------------------------------+
| type_id : int | 4 bytes |
+-----------------+------------+------------------------------------+
| address_indices : []int | 4 + 4 * len(address_indices) bytes |
+-----------------+------------+------------------------------------+
| group_id : int | 4 bytes |
+-----------------+------------+------------------------------------+
| payload : []byte | 4 + len(payload) bytes |
+-----------------+------------+------------------------------------+
| outputs : []Output | 4 + size(outputs) bytes |
+-----------------+------------+------------------------------------+
| 20 + |
| 4 * len(address_indices) + |
| len(payload) + |
| size(outputs) bytes |
+------------------------------------+
```
### **Proto NFT Mint Op Specification**
```text
message NFTMintOp {
uint32 typeID = 1; // 04 bytes
repeated uint32 address_indices = 2; // 04 bytes + 04 bytes * len(address_indices)
uint32 group_id = 3; // 04 bytes
bytes payload = 4; // 04 bytes + len(payload)
repeated bytes outputs = 5; // 04 bytes + size(outputs)
}
```
### **NFT Mint Op Example**
Let’s make an NFT mint operation with:
* **`TypeId`**: `12`
* **`AddressIndices`**:
* `0x00000003`
* `0x00000007`
* **`GroupID`**: `12345`
* **`Payload`**: `0x431100`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0xc3344128e060128ede3523a24a461c8943ab0859`
```text
[
TypeID <- 0x0000000c
AddressIndices <- [
0x00000003,
0x00000007,
]
GroupID <- 0x00003039
Payload <- 0x431100
Locktime <- 0x000000000000d431
Threshold <- 0x00000001
Addresses <- [
0xc3344128e060128ede3523a24a461c8943ab0859
]
]
=
[
// Type ID
0x00, 0x00, 0x00, 0x0c,
// number of address indices:
0x00, 0x00, 0x00, 0x02,
// address index 0:
0x00, 0x00, 0x00, 0x03,
// address index 1:
0x00, 0x00, 0x00, 0x07,
// groupID:
0x00, 0x00, 0x30, 0x39,
// length of payload:
0x00, 0x00, 0x00, 0x03,
// payload:
0x43, 0x11, 0x00,
// number of outputs:
0x00, 0x00, 0x00, 0x01,
// outputs[0]
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x01,
// addrs[0]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## NFT Transfer Op
An NFT transfer operation sends an unspent NFT transfer output to a new set of owners.
### **What NFT Transfer Op Contains**
An NFT transfer operation contains a `TypeID`, `AddressIndices` and an untyped `NFTTransferOutput`.
* **`TypeID`** is the ID for this output type. It is `0x0000000d`.
* **`AddressIndices`** is a list of unique ints that define the private keys that are being used to spend the UTXO. Each UTXO has an array of addresses that can spend the UTXO. Each int represents the index in this address array that will sign this transaction. The array must be sorted low to high.
* **`NFTTransferOutput`** is the output of this operation and must be an [NFT Transfer Output](avm-transaction-serialization.md#nft-transfer-output). This output doesn’t have the **`TypeId`**, because the type is known by the context of being in this operation.
### **Gantt NFT Transfer Op Specification**
```text
+------------------------------+------------------------------------+
| type_id : int | 4 bytes |
+-----------------+------------+------------------------------------+
| address_indices : []int | 4 + 4 * len(address_indices) bytes |
+-----------------+------------+------------------------------------+
| group_id : int | 4 bytes |
+-----------------+------------+------------------------------------+
| payload : []byte | 4 + len(payload) bytes |
+-----------------+------------+------------------------------------+
| locktime : long | 8 bytes |
+-----------+------------+------------------------------------------+
| threshold : int | 4 bytes |
+-----------------+------------+------------------------------------+
| addresses : [][20]byte | 4 + 20 * len(addresses) bytes |
+-----------------+------------+------------------------------------+
| 36 + len(payload) |
| + 4 * len(address_indices) |
| + 20 * len(addresses) bytes |
+------------------------------------+
```
### **Proto NFT Transfer Op Specification**
```text
message NFTTransferOp {
uint32 typeID = 1; // 04 bytes
repeated uint32 address_indices = 2; // 04 bytes + 04 bytes * len(address_indices)
uint32 group_id = 3; // 04 bytes
bytes payload = 4; // 04 bytes + len(payload)
uint64 locktime = 5; // 08 bytes
uint32 threshold = 6; // 04 bytes
repeated bytes addresses = 7; // 04 bytes + 20 bytes * len(addresses)
}
```
### **NFT Transfer Op Example**
Let’s make an NFT transfer operation with:
* **`TypeID`**: `13`
* **`AddressIndices`**:
* `0x00000007`
* `0x00000003`
* **`GroupID`**: `12345`
* **`Payload`**: `0x431100`
* **`Locktime`**: `54321`
* **`Threshold`**: `1`
* **`Addresses`**:
* `0xc3344128e060128ede3523a24a461c8943ab0859`
* `0x51025c61fbcfc078f69334f834be6dd26d55a955`
```text
[
TypeID <- 0x0000000d
AddressIndices <- [
0x00000007,
0x00000003,
]
GroupID <- 0x00003039
Payload <- 0x431100
Locktime <- 0x000000000000d431
Threshold <- 00000001
Addresses <- [
0x51025c61fbcfc078f69334f834be6dd26d55a955,
0xc3344128e060128ede3523a24a461c8943ab0859,
]
]
=
[
// Type ID
0x00, 0x00, 0x00, 0x0d,
// number of address indices:
0x00, 0x00, 0x00, 0x02,
// address index 0:
0x00, 0x00, 0x00, 0x07,
// address index 1:
0x00, 0x00, 0x00, 0x03,
// groupID:
0x00, 0x00, 0x30, 0x39,
// length of payload:
0x00, 0x00, 0x00, 0x03,
// payload:
0x43, 0x11, 0x00,
// locktime:
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x31,
// threshold:
0x00, 0x00, 0x00, 0x01,
// number of addresses:
0x00, 0x00, 0x00, 0x02,
// addrs[0]:
0x51, 0x02, 0x5c, 0x61, 0xfb, 0xcf, 0xc0, 0x78,
0xf6, 0x93, 0x34, 0xf8, 0x34, 0xbe, 0x6d, 0xd2,
0x6d, 0x55, 0xa9, 0x55,
// addrs[1]:
0xc3, 0x34, 0x41, 0x28, 0xe0, 0x60, 0x12, 0x8e,
0xde, 0x35, 0x23, 0xa2, 0x4a, 0x46, 0x1c, 0x89,
0x43, 0xab, 0x08, 0x59,
]
```
## Initial State