@typesol/cli 0.44.0 → 0.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/dist/compiler/emit/alias.d.ts +16 -2
- package/dist/compiler/emit/alias.js +62 -4
- package/dist/compiler/emit/calls.js +15 -7
- package/dist/compiler/emit/cpi-core.d.ts +6 -0
- package/dist/compiler/emit/cpi-core.js +18 -5
- package/dist/compiler/emit/create.js +19 -11
- package/dist/compiler/emit/function.js +5 -5
- package/dist/compiler/emit/metaplex.js +17 -4
- package/dist/compiler/emit/token.js +64 -39
- package/docs/architecture.md +1 -1
- package/docs/audit.md +45 -6
- package/docs/errors.md +1 -1
- package/docs/language.md +6 -4
- package/docs/security-model.md +46 -11
- package/llms-full.txt +53 -16
- package/package.json +1 -1
- package/runtime/typesol_rt.h +8 -5
|
@@ -24,15 +24,23 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
24
24
|
if (a.length !== fixed && a.length !== fixed + 1)
|
|
25
25
|
this.fail(node, `${method} takes ${fixed} arguments plus optional signerSeeds`);
|
|
26
26
|
};
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The amount, then the signer seeds: JS reads the amount first, so it is copied before a seed list that runs code
|
|
29
|
+
* (`["vault", next(st), bump]`) when it reads storage that code may change.
|
|
30
|
+
*/
|
|
31
|
+
const amountThenSeeds = (n, seedsNode, auth, at) => {
|
|
32
|
+
const v = this.expect(this.expr(n, U64), U64, n);
|
|
33
|
+
const mark = this.lines.length;
|
|
34
|
+
const s = this.signerSeeds(seedsNode, auth, at);
|
|
35
|
+
return [seedsNode && this.runsCode(seedsNode, true) ? this.settle(v, mark).c : v.c, s];
|
|
36
|
+
};
|
|
28
37
|
switch (method) {
|
|
29
38
|
case "transfer": {
|
|
30
39
|
arity(4);
|
|
31
40
|
const from = want(a[0], "token", true, "the source");
|
|
32
41
|
const to = want(a[1], "token", true, "the destination");
|
|
33
42
|
const auth = this.cpiAccount(a[2], "the authority");
|
|
34
|
-
const amt =
|
|
35
|
-
const s = this.signerSeeds(a[4], auth, a[2]);
|
|
43
|
+
const [amt, s] = amountThenSeeds(a[3], a[4], auth, a[2]);
|
|
36
44
|
this.line(`TS_TRY(ts_token_transfer(params, ${p}, ${from.c}, ${to.c}, ${auth.c}, ${amt}, ${s.name}, ${s.count}));`);
|
|
37
45
|
return undefined;
|
|
38
46
|
}
|
|
@@ -42,8 +50,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
42
50
|
const mint = want(a[1], "mint", false, "the mint");
|
|
43
51
|
const to = want(a[2], "token", true, "the destination");
|
|
44
52
|
const auth = this.cpiAccount(a[3], "the authority");
|
|
45
|
-
const amt =
|
|
46
|
-
const s = this.signerSeeds(a[5], auth, a[3]);
|
|
53
|
+
const [amt, s] = amountThenSeeds(a[4], a[5], auth, a[3]);
|
|
47
54
|
this.line(`TS_TRY(ts_token_transfer_checked(params, ${p}, ${from.c}, ${mint.c}, ${to.c}, ${auth.c}, ${amt}, ${s.name}, ${s.count}));`);
|
|
48
55
|
return undefined;
|
|
49
56
|
}
|
|
@@ -56,8 +63,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
56
63
|
this.fail(a[0], "the mint must be a Mut<Mint>, or a Mut<Signer> / Mut<AccountInfo> mint this instruction created");
|
|
57
64
|
const to = want(a[1], "token", true, "the destination");
|
|
58
65
|
const auth = this.cpiAccount(a[2], "the mint authority");
|
|
59
|
-
const amt =
|
|
60
|
-
const s = this.signerSeeds(a[4], auth, a[2]);
|
|
66
|
+
const [amt, s] = amountThenSeeds(a[3], a[4], auth, a[2]);
|
|
61
67
|
this.line(`TS_TRY(ts_token_mint_to(params, ${p}, ${mint.c}, ${to.c}, ${auth.c}, ${amt}, ${s.name}, ${s.count}));`);
|
|
62
68
|
return undefined;
|
|
63
69
|
}
|
|
@@ -66,8 +72,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
66
72
|
const from = want(a[0], "token", true, "the burned account");
|
|
67
73
|
const mint = want(a[1], "mint", true, "the mint");
|
|
68
74
|
const auth = this.cpiAccount(a[2], "the authority");
|
|
69
|
-
const amt =
|
|
70
|
-
const s = this.signerSeeds(a[4], auth, a[2]);
|
|
75
|
+
const [amt, s] = amountThenSeeds(a[3], a[4], auth, a[2]);
|
|
71
76
|
this.line(`TS_TRY(ts_token_burn(params, ${p}, ${from.c}, ${mint.c}, ${auth.c}, ${amt}, ${s.name}, ${s.count}));`);
|
|
72
77
|
return undefined;
|
|
73
78
|
}
|
|
@@ -82,7 +87,11 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
82
87
|
this.fail(a[0], "the mint must be writable (Mut<...>)");
|
|
83
88
|
const ua = this.cpiAccount(a[1], "the update authority");
|
|
84
89
|
const ma = this.cpiAccount(a[2], "the mint authority");
|
|
85
|
-
|
|
90
|
+
// Read at the call: a view of account text is copied first when a later argument runs code that may rewrite it.
|
|
91
|
+
const [nm, sym, uri] = [3, 4, 5].map((i) => {
|
|
92
|
+
const v = this.expect(this.expr(a[i], STRING), STRING, a[i]);
|
|
93
|
+
return (a.slice(i + 1).some((n) => this.runsCode(n, true)) ? this.ownedString(v) : v).c;
|
|
94
|
+
});
|
|
86
95
|
const s = this.signerSeeds(a[6], ma, a[2]);
|
|
87
96
|
this.line(`TS_TRY(ts_t22_init_metadata(params, ${p}, ${mint.c}, ${ua.c}, ${ma.c}, ${nm}, ${sym}, ${uri}, ${s.name}, ${s.count}));`);
|
|
88
97
|
return undefined;
|
|
@@ -110,7 +119,15 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
110
119
|
this.fail(n, `${what} must be writable (Mut<...>)`);
|
|
111
120
|
return acct;
|
|
112
121
|
};
|
|
113
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Signer seeds given as a function are lowered after the fields when an argument runs code (JS evaluates the
|
|
124
|
+
* fields first: `approve(src, d, owner, next(st), ["vault", st.count, bump])` signs for the count next() left), and
|
|
125
|
+
* before them otherwise, which keeps those programs' code as it was.
|
|
126
|
+
*/
|
|
127
|
+
const seedsFirst = (seeds, fields) => typeof seeds === "function" && !(fields.length && a.some((n) => this.runsCode(n, true))) ? seeds() : seeds;
|
|
128
|
+
const seedsNow = (seeds) => (typeof seeds === "function" ? seeds() : seeds);
|
|
129
|
+
const simple = (tag, fields, metas, seeds0) => {
|
|
130
|
+
const seeds = seedsFirst(seeds0, fields);
|
|
114
131
|
const { buf, len, put, finish } = this.byteBuffer("tok", 128, "TS_ERR_INSTRUCTION_DATA", "token instruction");
|
|
115
132
|
const t = this.tmp("tag");
|
|
116
133
|
this.line(`uint8_t ${t} = ${tag};`);
|
|
@@ -118,7 +135,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
118
135
|
for (const f of fields)
|
|
119
136
|
f(put);
|
|
120
137
|
finish(node);
|
|
121
|
-
this.cpi(p, metas.map(([acc, w, sg]) => [acc.c, w, sg]), buf, len, seeds);
|
|
138
|
+
this.cpi(p, metas.map(([acc, w, sg]) => [acc.c, w, sg]), buf, len, seedsNow(seeds));
|
|
122
139
|
};
|
|
123
140
|
const value = (n, t) => (put) => this.serialize(this.expect(this.expr(n, t), t, n), n, put);
|
|
124
141
|
const optKey = { kind: "option", inner: PUBKEY };
|
|
@@ -151,7 +168,8 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
151
168
|
};
|
|
152
169
|
const none = { name: "NULL", count: 0 };
|
|
153
170
|
// The Token Group interface (spl-token-group-interface), which Token-2022 implements: 8-byte discriminators.
|
|
154
|
-
const grouped = (disc, fields, metas,
|
|
171
|
+
const grouped = (disc, fields, metas, seeds0) => {
|
|
172
|
+
const seeds = seedsFirst(seeds0, fields);
|
|
155
173
|
const { buf, len, put, finish } = this.byteBuffer("grp", 96, "TS_ERR_INSTRUCTION_DATA", "token group instruction");
|
|
156
174
|
const d = this.tmp("disc");
|
|
157
175
|
this.line(`static const uint8_t ${d}[8] = {${disc.join(", ")}};`);
|
|
@@ -159,7 +177,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
159
177
|
for (const f of fields)
|
|
160
178
|
f(put);
|
|
161
179
|
finish(node);
|
|
162
|
-
this.cpi(p, metas.map(([acc, w, sg]) => [acc.c, w, sg]), buf, len, seeds);
|
|
180
|
+
this.cpi(p, metas.map(([acc, w, sg]) => [acc.c, w, sg]), buf, len, seedsNow(seeds));
|
|
163
181
|
};
|
|
164
182
|
switch (method) {
|
|
165
183
|
case "initializeTokenGroup": {
|
|
@@ -173,7 +191,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
173
191
|
[group, true, false],
|
|
174
192
|
[mint, false, false],
|
|
175
193
|
[auth, false, true],
|
|
176
|
-
], this.signerSeeds(a[5], auth, a[2]));
|
|
194
|
+
], () => this.signerSeeds(a[5], auth, a[2]));
|
|
177
195
|
return undefined;
|
|
178
196
|
}
|
|
179
197
|
case "initializeGroupMember": {
|
|
@@ -203,7 +221,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
203
221
|
grouped([108, 37, 171, 143, 248, 30, 18, 110], [value(a[2], U64)], [
|
|
204
222
|
[group, true, false],
|
|
205
223
|
[auth, false, true],
|
|
206
|
-
], this.signerSeeds(a[3], auth, a[1]));
|
|
224
|
+
], () => this.signerSeeds(a[3], auth, a[1]));
|
|
207
225
|
return undefined;
|
|
208
226
|
}
|
|
209
227
|
case "updateGroupAuthority": {
|
|
@@ -215,7 +233,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
215
233
|
grouped([161, 105, 88, 1, 237, 221, 216, 203], [nonZeroKey(a[2])], [
|
|
216
234
|
[group, true, false],
|
|
217
235
|
[auth, false, true],
|
|
218
|
-
], this.signerSeeds(a[3], auth, a[1]));
|
|
236
|
+
], () => this.signerSeeds(a[3], auth, a[1]));
|
|
219
237
|
return undefined;
|
|
220
238
|
}
|
|
221
239
|
case "initializeTransferFeeConfig": {
|
|
@@ -294,7 +312,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
294
312
|
simple(28, [byte(1), (put) => put(`&${st}`, "1", 1)], [
|
|
295
313
|
[mint, true, false],
|
|
296
314
|
[auth, false, true],
|
|
297
|
-
], this.signerSeeds(a[3], auth, a[1]));
|
|
315
|
+
], () => this.signerSeeds(a[3], auth, a[1]));
|
|
298
316
|
return undefined;
|
|
299
317
|
}
|
|
300
318
|
case "enableRequiredMemoTransfers":
|
|
@@ -307,7 +325,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
307
325
|
simple(30, [byte(method === "enableRequiredMemoTransfers" ? 0 : 1)], [
|
|
308
326
|
[acct, true, false],
|
|
309
327
|
[owner, false, true],
|
|
310
|
-
], this.signerSeeds(a[2], owner, a[1]));
|
|
328
|
+
], () => this.signerSeeds(a[2], owner, a[1]));
|
|
311
329
|
return undefined;
|
|
312
330
|
}
|
|
313
331
|
case "updateTransferHook": {
|
|
@@ -319,7 +337,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
319
337
|
simple(36, [byte(1), nonZeroKey(a[2])], [
|
|
320
338
|
[mint, true, false],
|
|
321
339
|
[auth, false, true],
|
|
322
|
-
], this.signerSeeds(a[3], auth, a[1]));
|
|
340
|
+
], () => this.signerSeeds(a[3], auth, a[1]));
|
|
323
341
|
return undefined;
|
|
324
342
|
}
|
|
325
343
|
case "updateInterestRate": {
|
|
@@ -331,7 +349,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
331
349
|
simple(33, [byte(1), value(a[2], I16)], [
|
|
332
350
|
[mint, true, false],
|
|
333
351
|
[auth, false, true],
|
|
334
|
-
], this.signerSeeds(a[3], auth, a[1]));
|
|
352
|
+
], () => this.signerSeeds(a[3], auth, a[1]));
|
|
335
353
|
return undefined;
|
|
336
354
|
}
|
|
337
355
|
case "transferCheckedWithFee": {
|
|
@@ -353,7 +371,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
353
371
|
[mint, false, false],
|
|
354
372
|
[to, true, false],
|
|
355
373
|
[auth, false, true],
|
|
356
|
-
], this.signerSeeds(a[6], auth, a[3]));
|
|
374
|
+
], () => this.signerSeeds(a[6], auth, a[3]));
|
|
357
375
|
return undefined;
|
|
358
376
|
}
|
|
359
377
|
case "harvestWithheldTokensToMint": {
|
|
@@ -383,7 +401,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
383
401
|
[mint, true, false],
|
|
384
402
|
[dest, true, false],
|
|
385
403
|
[auth, false, true],
|
|
386
|
-
], this.signerSeeds(a[3], auth, a[2]));
|
|
404
|
+
], () => this.signerSeeds(a[3], auth, a[2]));
|
|
387
405
|
return undefined;
|
|
388
406
|
}
|
|
389
407
|
case "setTransferFee": {
|
|
@@ -400,7 +418,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
400
418
|
simple(26, [byte(5), bps, value(a[3], U64)], [
|
|
401
419
|
[mint, true, false],
|
|
402
420
|
[auth, false, true],
|
|
403
|
-
], this.signerSeeds(a[4], auth, a[1]));
|
|
421
|
+
], () => this.signerSeeds(a[4], auth, a[1]));
|
|
404
422
|
return undefined;
|
|
405
423
|
}
|
|
406
424
|
case "updateMetadataField":
|
|
@@ -445,7 +463,9 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
445
463
|
this.serialize(this.expect(this.expr(a[3], STRING), STRING, a[3]), a[3], put);
|
|
446
464
|
}
|
|
447
465
|
else if (method === "removeMetadataKey") {
|
|
448
|
-
|
|
466
|
+
// Written after `idempotent` is read: a view of account text is copied first when that runs code.
|
|
467
|
+
const key0 = this.expect(this.expr(a[2], STRING), STRING, a[2]);
|
|
468
|
+
const key = this.runsCode(a[3], true) ? this.ownedString(key0) : key0;
|
|
449
469
|
const idem = this.expect(this.expr(a[3], BOOL), BOOL, a[3]);
|
|
450
470
|
const t = this.tmp("idem");
|
|
451
471
|
this.line(`uint8_t ${t} = (${idem.c}) ? 1 : 0;`);
|
|
@@ -475,7 +495,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
475
495
|
const src = want(a[0], "token", true, "the source");
|
|
476
496
|
const delegate = this.cpiAccount(a[1], "the delegate");
|
|
477
497
|
const owner = this.cpiAccount(a[2], "the owner");
|
|
478
|
-
const s = this.signerSeeds(a[4], owner, a[2]);
|
|
498
|
+
const s = () => this.signerSeeds(a[4], owner, a[2]);
|
|
479
499
|
const amt = value(a[3], U64);
|
|
480
500
|
simple(4, [amt], [
|
|
481
501
|
[src, true, false],
|
|
@@ -491,7 +511,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
491
511
|
const mint = want(a[1], "mint", false, "the mint");
|
|
492
512
|
const delegate = this.cpiAccount(a[2], "the delegate");
|
|
493
513
|
const owner = this.cpiAccount(a[3], "the owner");
|
|
494
|
-
const s = this.signerSeeds(a[5], owner, a[3]);
|
|
514
|
+
const s = () => this.signerSeeds(a[5], owner, a[3]);
|
|
495
515
|
simple(13, [value(a[4], U64), decimals(mint)], [
|
|
496
516
|
[src, true, false],
|
|
497
517
|
[mint, false, false],
|
|
@@ -505,7 +525,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
505
525
|
const mint = want(a[0], "mint", true, "the mint");
|
|
506
526
|
const to = want(a[1], "token", true, "the destination");
|
|
507
527
|
const auth = this.cpiAccount(a[2], "the mint authority");
|
|
508
|
-
const s = this.signerSeeds(a[4], auth, a[2]);
|
|
528
|
+
const s = () => this.signerSeeds(a[4], auth, a[2]);
|
|
509
529
|
simple(14, [value(a[3], U64), decimals(mint)], [
|
|
510
530
|
[mint, true, false],
|
|
511
531
|
[to, true, false],
|
|
@@ -518,7 +538,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
518
538
|
const from = want(a[0], "token", true, "the burned account");
|
|
519
539
|
const mint = want(a[1], "mint", true, "the mint");
|
|
520
540
|
const auth = this.cpiAccount(a[2], "the authority");
|
|
521
|
-
const s = this.signerSeeds(a[4], auth, a[2]);
|
|
541
|
+
const s = () => this.signerSeeds(a[4], auth, a[2]);
|
|
522
542
|
simple(15, [value(a[3], U64), decimals(mint)], [
|
|
523
543
|
[from, true, false],
|
|
524
544
|
[mint, true, false],
|
|
@@ -533,7 +553,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
533
553
|
simple(5, [], [
|
|
534
554
|
[src, true, false],
|
|
535
555
|
[owner, false, true],
|
|
536
|
-
], this.signerSeeds(a[2], owner, a[1]));
|
|
556
|
+
], () => this.signerSeeds(a[2], owner, a[1]));
|
|
537
557
|
return undefined;
|
|
538
558
|
}
|
|
539
559
|
case "setAuthority": {
|
|
@@ -541,7 +561,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
541
561
|
const target = anyAcct(a[0], "the mint or token account", true);
|
|
542
562
|
const current = this.cpiAccount(a[1], "the current authority");
|
|
543
563
|
this.model.options.set("pubkey", PUBKEY);
|
|
544
|
-
const s = this.signerSeeds(a[4], current, a[1]);
|
|
564
|
+
const s = () => this.signerSeeds(a[4], current, a[1]);
|
|
545
565
|
simple(6, [value(a[2], U8), value(a[3], optKey)], [
|
|
546
566
|
[target, true, false],
|
|
547
567
|
[current, false, true],
|
|
@@ -558,7 +578,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
558
578
|
[acct, true, false],
|
|
559
579
|
[mint, false, false],
|
|
560
580
|
[auth, false, true],
|
|
561
|
-
], this.signerSeeds(a[3], auth, a[2]));
|
|
581
|
+
], () => this.signerSeeds(a[3], auth, a[2]));
|
|
562
582
|
return undefined;
|
|
563
583
|
}
|
|
564
584
|
case "syncNative": {
|
|
@@ -668,7 +688,10 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
668
688
|
this.fail(n, `pass ${what} as an account, or named(account, address) to name its address with the slot's account`);
|
|
669
689
|
return acct(i, what);
|
|
670
690
|
};
|
|
671
|
-
|
|
691
|
+
// Seeds given as a function: lowered after the fields when an argument runs code, as JS evaluates them (see tokenOp).
|
|
692
|
+
const runs = (n) => this.runsCode(n, true);
|
|
693
|
+
const send = (tag, fields, metas, seeds0) => {
|
|
694
|
+
let seeds = typeof seeds0 === "function" && !(fields.length && a.some(runs)) ? seeds0() : seeds0;
|
|
672
695
|
const { buf, len, put, finish } = this.byteBuffer("stk", 116, "TS_ERR_INSTRUCTION_DATA", "stake instruction");
|
|
673
696
|
const t = this.tmp("tag");
|
|
674
697
|
this.line(`uint32_t ${t} = ${tag};`);
|
|
@@ -676,6 +699,8 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
676
699
|
for (const f of fields)
|
|
677
700
|
f(put);
|
|
678
701
|
finish(node);
|
|
702
|
+
if (typeof seeds === "function")
|
|
703
|
+
seeds = seeds();
|
|
679
704
|
if (metas.some(([x]) => x.named)) {
|
|
680
705
|
// Addresses named with the slot's account: the account infos are the CPI's accounts, as passed (ts_cpi_named).
|
|
681
706
|
const m = this.tmp("metas");
|
|
@@ -743,7 +768,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
743
768
|
[sysvar(1, "the Clock sysvar"), false, false],
|
|
744
769
|
[auth, false, true],
|
|
745
770
|
...(opt.custodian ? [custodian(opt.custodian, opt.seeds)] : []),
|
|
746
|
-
], this.signerSeeds(opt.seeds, auth, a[2]));
|
|
771
|
+
], () => this.signerSeeds(opt.seeds, auth, a[2]));
|
|
747
772
|
return undefined;
|
|
748
773
|
}
|
|
749
774
|
case "delegate": {
|
|
@@ -756,7 +781,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
756
781
|
[sysvar(3, "the StakeHistory sysvar"), false, false],
|
|
757
782
|
[sysvar(4, "the stake config account"), false, false],
|
|
758
783
|
[staker, false, true],
|
|
759
|
-
], this.signerSeeds(a[6], staker, a[5]));
|
|
784
|
+
], () => this.signerSeeds(a[6], staker, a[5]));
|
|
760
785
|
return undefined;
|
|
761
786
|
}
|
|
762
787
|
case "split": {
|
|
@@ -766,7 +791,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
766
791
|
[acct(0, "the stake account", true), true, false],
|
|
767
792
|
[acct(1, "the split stake account", true), true, false],
|
|
768
793
|
[auth, false, true],
|
|
769
|
-
], this.signerSeeds(a[4], auth, a[2]));
|
|
794
|
+
], () => this.signerSeeds(a[4], auth, a[2]));
|
|
770
795
|
return undefined;
|
|
771
796
|
}
|
|
772
797
|
case "deactivate": {
|
|
@@ -776,7 +801,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
776
801
|
[acct(0, "the stake account", true), true, false],
|
|
777
802
|
[sysvar(1, "the Clock sysvar"), false, false],
|
|
778
803
|
[staker, false, true],
|
|
779
|
-
], this.signerSeeds(a[3], staker, a[2]));
|
|
804
|
+
], () => this.signerSeeds(a[3], staker, a[2]));
|
|
780
805
|
return undefined;
|
|
781
806
|
}
|
|
782
807
|
case "withdraw": {
|
|
@@ -794,7 +819,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
794
819
|
[sysvar(3, "the StakeHistory sysvar"), false, false],
|
|
795
820
|
[withdrawer, false, true],
|
|
796
821
|
...(opt.custodian ? [custodian(opt.custodian, opt.seeds)] : []),
|
|
797
|
-
], this.signerSeeds(opt.seeds, withdrawer, a[4]));
|
|
822
|
+
], () => this.signerSeeds(opt.seeds, withdrawer, a[4]));
|
|
798
823
|
return undefined;
|
|
799
824
|
}
|
|
800
825
|
case "merge": {
|
|
@@ -806,7 +831,7 @@ export class TokenEmitter extends CreateEmitter {
|
|
|
806
831
|
[sysvar(2, "the Clock sysvar"), false, false],
|
|
807
832
|
[sysvar(3, "the StakeHistory sysvar"), false, false],
|
|
808
833
|
[staker, false, true],
|
|
809
|
-
], this.signerSeeds(a[5], staker, a[4]));
|
|
834
|
+
], () => this.signerSeeds(a[5], staker, a[4]));
|
|
810
835
|
return undefined;
|
|
811
836
|
}
|
|
812
837
|
case "getMinimumDelegation": {
|
package/docs/architecture.md
CHANGED
|
@@ -103,7 +103,7 @@ representation in between. We reviewed this on 2026-10-30 and kept it that way f
|
|
|
103
103
|
named in the source, see `alias.ts`), a second backend (SBF without clang), and optimizations clang cannot see
|
|
104
104
|
because they depend on account semantics (dropping a repeated check, packing a `@layout borsh` account only where
|
|
105
105
|
it changed).
|
|
106
|
-
- **What it would cost now:** rewriting most of the compiler's
|
|
106
|
+
- **What it would cost now:** rewriting most of the compiler's 20,000 lines, and losing the property every release
|
|
107
107
|
relies on: programs that do not use a change compile to the same binaries. Audit scope and differential results
|
|
108
108
|
would start over.
|
|
109
109
|
- **What we have instead:** the layers above, each owning one concern; `Ref` / `Value` as the typed place and value
|
package/docs/audit.md
CHANGED
|
@@ -7,16 +7,16 @@ with TypeSOL are out of scope; their authors audit them.
|
|
|
7
7
|
|
|
8
8
|
## Scope
|
|
9
9
|
|
|
10
|
-
In order of priority. Line counts at 0.
|
|
10
|
+
In order of priority. Line counts at 0.44.0 (November 2026).
|
|
11
11
|
|
|
12
12
|
| Priority | Component | Files | Lines | Why |
|
|
13
13
|
| --- | --- | --- | ---: | --- |
|
|
14
|
-
| 1 | C runtime | `runtime/typesol_rt.h` | 2,
|
|
15
|
-
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` |
|
|
16
|
-
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 3,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,
|
|
14
|
+
| 1 | C runtime | `runtime/typesol_rt.h` | 2,998 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
|
|
15
|
+
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 876 | Which checks each account parameter gets, and their order |
|
|
16
|
+
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 3,799 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
|
|
17
|
+
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,694 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
|
|
18
18
|
| 1 | Raw views and the red-black tree | `src/compiler/emit/views.ts`, `rbtree.ts` | 655 | Accounts read without a discriminator at run-time offsets (`loadRaw`, `loadRawAt`, `rawArrayAt`, `BigVec`), their bounds, and the red-black tree's node indexes (`rbTreeAt`) |
|
|
19
|
-
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,
|
|
19
|
+
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,465 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
|
|
20
20
|
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,088 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
|
|
21
21
|
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,486 | What the language accepts; constraints and account types as parsed from the source |
|
|
22
22
|
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,460 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
|
|
@@ -54,6 +54,45 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
|
|
|
54
54
|
Internal reviews, by the maintainers: none of them is an independent audit. Their findings and fixes are in the
|
|
55
55
|
CHANGELOG.
|
|
56
56
|
|
|
57
|
+
### 0.44.0 (2026-11-11)
|
|
58
|
+
|
|
59
|
+
A second internal review, of 0.44.0 as published, over the areas the review of 0.43.0 left out: the token,
|
|
60
|
+
Token-2022 and Metaplex CPI wrappers' emitters, the oracle readers, the Stake wrappers and signature introspection,
|
|
61
|
+
SBPF v1 and v2 builds, optional accounts, `Dup<…>`, and the heap and stack limits. It probed each with targeted
|
|
62
|
+
programs run in LiteSVM against the real token programs, and read the runtime header and the C generated for them.
|
|
63
|
+
|
|
64
|
+
Defects found, fixed in 0.44.1 (its CHANGELOG section, with a test for each):
|
|
65
|
+
|
|
66
|
+
- **A None authority in `mint.create`'s `transferFee` was 33 bytes.** Token-2022 reads a None COption as one byte,
|
|
67
|
+
so the 32 zero bytes after it became the next fields: a mint with a null config authority got no withdraw
|
|
68
|
+
authority and a fee of 0. The standalone `initializeTransferFeeConfig` was right.
|
|
69
|
+
- **A reference held across a resize through another slot.** The reference rule compared names only: with a
|
|
70
|
+
`Dup<…>` pair, a read-only and a writable account of one type, or a loaded struct naming one account, a reference
|
|
71
|
+
made through one slot outlived a push, pop or clear through the other and reached another record. Such programs are
|
|
72
|
+
now refused, as with one name.
|
|
73
|
+
- **Wrapper arguments out of source order.** Twelve token wrappers and the Stake wrappers read their signer seeds
|
|
74
|
+
before an earlier argument's code ran (a PDA other than the one the source names); amounts of `transfer` and the
|
|
75
|
+
like, and account text given to the metadata wrappers, were read after a later argument's code ran.
|
|
76
|
+
- **A 355-byte mint.** Extensions adding up to a Multisig's length made `mint.create` fail every time (Token-2022
|
|
77
|
+
sizes such a mint 357).
|
|
78
|
+
- **`updateExtraAccountMetas` growth.** The 10 KiB limit was counted from the current length, so after a
|
|
79
|
+
`resizeAccount` it could write past the runtime's room into the next account's record.
|
|
80
|
+
- **Heap Vec aliasing in the runtime.** `ts_hvec_reserve` wrote through a type the C aliasing rules let the optimizer
|
|
81
|
+
treat as unrelated to the generated code's (latent; no miscompile seen).
|
|
82
|
+
- **Oracle documentation.** What `pythPrice` and `switchboardValue` do not check was not said plainly; the readers are
|
|
83
|
+
unchanged (docs/security-model.md).
|
|
84
|
+
|
|
85
|
+
Examined and found sound: the other token and Token-2022 wrappers' optional keys (the standalone initializers'
|
|
86
|
+
COptions and Borsh Options, the OptionalNonZero keys of the pointer, hook, group and interest extensions); Token-2022
|
|
87
|
+
mints and accounts with extensions not taken for one another; several large token-metadata buffers in one
|
|
88
|
+
instruction; the Ed25519 signature readers against hostile offsets (into another instruction, a zero count, the same
|
|
89
|
+
bytes under another program id, a fake Instructions sysvar); optional accounts left out or passed unsigned; `Dup<…>`
|
|
90
|
+
pairs without references across a resize; the heap frame and stack limits; and checked arithmetic at every integer
|
|
91
|
+
width, built for SBPF v0, v1 and v2 from the same source, with the same results.
|
|
92
|
+
|
|
93
|
+
Not reviewed: the Metaplex wrappers for unusual argument shapes beyond reading them, the large ports (Marginfi,
|
|
94
|
+
Phoenix, Raydium, the Stake Pool) built for SBPF v1 and v2, and Windows.
|
|
95
|
+
|
|
57
96
|
### 0.43.0 (2026-11-11)
|
|
58
97
|
|
|
59
98
|
An internal review of 0.43.0 as published. It probed the compiler's semantics with targeted programs (helpers,
|
package/docs/errors.md
CHANGED
|
@@ -34,7 +34,7 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
|
|
|
34
34
|
| 3010 | account must sign (AccountNotSigner; also a new keypair account a `create(payer, null, …)` makes) |
|
|
35
35
|
| 3011 | a `SystemAccount` owned by another program (AccountNotSystemOwned) |
|
|
36
36
|
| 3012 | account not initialized: empty system account where a program account, a token account or a mint was expected (AccountNotInitialized; not for zero-copy accounts, which Anchor's AccountLoader reports as 3007) |
|
|
37
|
-
| 3016 | account would grow more than 10 KiB in one instruction, or grow without a payer (AccountReallocExceedsLimit) |
|
|
37
|
+
| 3016 | account would grow more than 10 KiB in one instruction (counted from its length when the instruction started), or grow without a payer (AccountReallocExceedsLimit) |
|
|
38
38
|
| 4101 | an `Init` / `create` whose payer is the account being created (TryingToInitPayerAsProgramAccount) |
|
|
39
39
|
| 4102 | cast overflow (InvalidNumericConversion) |
|
|
40
40
|
| 5100 / 5101 | arithmetic overflow (including shifts) / division by zero |
|
package/docs/language.md
CHANGED
|
@@ -26,7 +26,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
26
26
|
| Events | `emit<Deposited>({ owner: owner.key, amount })` — Anchor-format `Program data:` logs, listed under `events` in the IDL; event structs may hold `string`, `Option`, `FixedVec<T, N>` (its fixed layout, as in account data), `Vec<T>` (Borsh: from a Vec argument or a list in account data) and `Option<Vec<T>>`; a nested struct given as a literal is Borsh too |
|
|
27
27
|
| Enums | `export enum Status { Pending, Approved }` — unit variants stored as the Borsh u8 index; `Status.Approved`, `===` |
|
|
28
28
|
| Options | `best: Option<u64>` (or `u64 \| null`) — `null`, `=== null`, TypeScript narrowing; `===` between options or with a value follows JS (null equals null, empty never equals a value); empty use aborts (5108); `acct?.field` on an optional account and `x.home?.field` on an `Option<struct>` give an Option (empty when the account was left out / the option is empty), `a ?? b` takes b only when a is empty (b runs only then; the result is an Option when b can be null), `x!` is the value or aborts with 5108; `${opt}` prints the value or `null`. Borsh `option` in arguments/events, fixed `{ is_some, value }` in account data |
|
|
29
|
-
| Vecs | `entries: Vec<Entry>` in account data, any number of them, declared anywhere: they are stored after the fixed-size fields in the order declared (so every other field keeps its offset; the IDL lists that order), and a push, pop or clear moves the Vecs after it (a reference into one of those cannot be used across it). In a `@layout borsh` struct a Vec is the last field (Anchor's order) — `get`, `set`, `push(v, payer)`, `pop()`, `clear()`, `.length`; the account is resized (realloc) and rent topped up by `payer`; `Vec<u64>` arguments are read-only views; `Vec<string>` arguments (Anchor's `Vec<String>`) are views of the instruction data, each checked as UTF-8 on entry (102), and go back out as Borsh through `invoke`; `pop()` of a Vec of structs works as a statement |
|
|
29
|
+
| Vecs | `entries: Vec<Entry>` in account data, any number of them, declared anywhere: they are stored after the fixed-size fields in the order declared (so every other field keeps its offset; the IDL lists that order), and a push, pop or clear moves the Vecs after it (a reference into one of those cannot be used across it, also when it was made through another parameter that may be the same account: a `Dup<…>` pair, a read-only and a writable account of one type, a struct loaded with `loadAccount` / `loadAccountMut`). In a `@layout borsh` struct a Vec is the last field (Anchor's order) — `get`, `set`, `push(v, payer)`, `pop()`, `clear()`, `.length`; the account is resized (realloc) and rent topped up by `payer`; `Vec<u64>` arguments are read-only views; `Vec<string>` arguments (Anchor's `Vec<String>`) are views of the instruction data, each checked as UTF-8 on entry (102), and go back out as Borsh through `invoke`; `pop()` of a Vec of structs works as a statement |
|
|
30
30
|
| Anchor's account bytes | `/** @layout borsh */` on an account struct stores it as Anchor does (Borsh: a `FixedString<N>` is a String, a `FixedVec<T, N>` or `Vec<T>` a Vec, an `Option` one byte when empty, and the fields after them move), so a TypeSOL program can take over accounts an Anchor program wrote and the IDL lists Anchor's own types. The instruction unpacks it into the usual fixed layout when it starts (bad bytes fail with 3003) and packs it back when it returns (3004 when the account is too small for the new value), so everything else works on it unchanged. A `Vec<T>` field (any position; integers, booleans, Pubkeys, unit enums or fixed-size structs) is Anchor's own: held on the heap while the instruction runs, growing as Rust's Vec does, bounded only by the account when it is written back (3004); its elements move when it grows, so a reference into one cannot outlive a `push` or an assignment. `Init` of such a struct takes its space, `create(payer, seeds, space)`. Programs invoked from the body (CPIs) see the account's bytes as they were when the instruction started. Costs more compute than the fixed layout (the whole account is read and written each time; see the benchmarks); nested structs and list elements must be fixed-size (FixedString elements allowed). The same struct is Borsh as a whole instruction argument (checked like Borsh deserialization, UTF-8 included), as return data and as an event; as those (not as account data) it may also hold `string` fields and data enums carrying strings, Anchor's `String` and enums in argument structs (account data takes data enums without strings); not inside list or enum arguments or `loadAccount`, and a struct holding a `Vec<T>` is account data or a whole argument, not return data or an event |
|
|
31
31
|
| A native program's Borsh accounts | `const pool = loadBorsh<StakePool>(acct)` / `storeBorsh(acct, pool)`: Borsh from byte 0 with no discriminator and no owner check, read into a local struct and written back, as Rust's `try_from_slice_unchecked` and `serialize` do (trailing bytes ignored when reading, left as they were when writing; invalid bytes or an account too small fail with `ProgramError.BorshIoError`). Any struct of integers, booleans, Pubkeys, enums, FixedArrays, FixedStrings, FixedVecs, Options, data enums with fixed-size payloads and nested structs of those; see [Porting a native program](#porting-a-native-program) |
|
|
32
32
|
| Zero-copy types as Anchor's IDL describes them | `/** @repr c */` (`@repr c packed`, `@repr c align 8`, `@repr rust` on an enum) and `/** @serialization bytemuck */` on a struct or enum put the IDL's `repr` and `serialization` there, as Anchor's `#[account(zero_copy)]` / `#[repr(C)]` types have them. TypeSOL stores fields back to back, so an unpacked `@repr c` struct must have its fields where C puts them: a field off its alignment, or a size that is not a multiple of the struct's, is a compile error naming the padding to add (Anchor zero-copy types spell their padding out as `_pad` fields, so a port matches). A 16-byte integer's alignment differs between targets: hold it as below or mark the struct packed |
|
|
@@ -51,7 +51,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
51
51
|
| Strings at runtime | `"hello, " + name`, `` `#${n}` ``, `` `owner ${acct.owner}` `` (a Pubkey or Hash as base58; an `Option` of an integer, boolean, Pubkey or Hash as its value, or `null` when empty, as JS prints it: after `x !== null` that is the value) — built on the 32 KiB heap (5110 when full): a template is joined in one allocation, text known at compile time (literals, string and Pubkey constants) is folded in, and `s += …` grows the newest heap string in place |
|
|
52
52
|
| `switch` | on integers (128-bit ones too), enums and data-enum `.kind`, with JS `break` / fallthrough; case labels are literals, constants or enum members |
|
|
53
53
|
| Hashing & signatures | `sha256(...)`, `keccak256(...)` → `Hash` (a PDA seed too: its 32 bytes, as Marginfi seeds an order with the hash of its bank keys); `findProgramAddress(seeds, program)` → the canonical PDA of any program (Rust `Pubkey::find_program_address(..).0`, e.g. a Bubblegum asset id) and `findProgramAddressBump(seeds, program)` its bump, or both from one search with `const [address, bump] = findProgramAddressWithBump(seeds, program)` (Rust's `let (address, bump) = …`; each separate search costs about 450 CU per bump tried); `programId()` → this program's address; `a.compare(b)` orders Pubkeys and Hashes as Rust orders their 32 bytes (-1 / 0 / 1); `merkleVerify(leaf, proof: Vec<Hash>, root)` (sorted-pair keccak, OpenZeppelin convention; inner nodes and leaves are hashed alike, so hash leaves as OpenZeppelin does, `keccak256(keccak256(data))`, and never take the leaf itself from the arguments: an inner node would pass as a leaf); `verifyEd25519(instructionsSysvar, signer, message)` checks an Ed25519 precompile instruction in the same transaction; `stackHeight()` is 1 when the transaction calls the program directly, more under a CPI (`require(stackHeight() === 1n, …)` refuses CPI callers); `verifySecp256k1(keccak256(...message) | ethMessageHash(message), recoveryId, r, s, ethAddress)` (the hash must be computed in the program; a passed-in hash could be forged) |
|
|
54
|
-
| Oracles | `pythPrice(update: PythPriceUpdate, feedId, maxAgeSeconds, exponent?)` (fully verified, feed-matched, fresh; with `exponent`, a feed at another scale is refused); raw `update.price / conf / exponent / publishTime` are unchecked (any feed, partially verified or stale: check `feedId`, `fullyVerified` and the age yourself, or use `pythPrice`); `switchboardValue(feed: SwitchboardFeed, expectedFeed, maxStaleSlots, decimals, minSamples?)` (the feed must be the expected one: anyone can create feeds; `minSamples`, default 1, the fewest oracle samples accepted) (mainnet program unless `SwitchboardFeed<"devnet">`) |
|
|
54
|
+
| Oracles | `pythPrice(update: PythPriceUpdate, feedId, maxAgeSeconds, exponent?)` (fully verified, feed-matched, fresh; with `exponent`, a feed at another scale is refused); raw `update.price / conf / exponent / publishTime` are unchecked (any feed, partially verified or stale: check `feedId`, `fullyVerified` and the age yourself, or use `pythPrice`); `switchboardValue(feed: SwitchboardFeed, expectedFeed, maxStaleSlots, decimals, minSamples?)` (the feed must be the expected one: anyone can create feeds; `minSamples`, default 1, the fewest oracle samples accepted; staleness counts slots from the feed's `result.slot`; the 18-decimal result is scaled to `decimals` rounding toward zero) (mainnet program unless `SwitchboardFeed<"devnet">`). Neither reader checks the price's sign or zero, the confidence (Pyth's `conf`, Switchboard's spread of samples), or a publish time or result slot in the future (it counts as fresh): check what your program relies on |
|
|
55
55
|
| Randomness | A chain has no secret randomness of its own: slot hashes and timestamps are known to, or chosen by, the block producer. `SwitchboardRandomness` (Switchboard On-Demand's RandomnessAccountData; owner, discriminator and size checked) gives verifiable randomness by commit and reveal: commit while `r.seedSlot === currentSlot() - 1n` and store `r.key` and `r.seedSlot`; settle in a later transaction after checking both, with `r.value()` (32 bytes) or `r.valueU64()`, which fail (5111) unless the value was revealed in this slot. See test/fixtures/coinflip.ts |
|
|
56
56
|
| Multiple files | `import { Side, min } from "./math"` — structs, enums, constants and helpers can live in other files; only the entry file's exported functions are instructions; names are program-wide, so imports from TypeSOL files cannot be renamed; error codes number imported files first |
|
|
57
57
|
| Loops | `for (let i = 0n; i < n; i++)` (or two counters, `for (let i = 0n, j = n; i < j; i++, j--)`: several declarations, and comma-separated updates run in order after each pass, `continue` included), `while`, `do … while`, `for (const x of list)` over a `Vec` or `FixedArray` (each `x` is what `list.get(i)` gives: a value, or a reference into account data for structs; the length is read again every step, as in JS), `break`, `continue` — bounded by the compute budget. Remaining accounts are iterated by index |
|
|
@@ -97,7 +97,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
97
97
|
| `Migrate<From, To>` | Anchor 1.0's `Migration`: an existing `From` account (owner, discriminator, size) rewritten as `To` by `acct.migrate(payer, value)`, a top-level statement the instruction must reach. `acct.from` (read-only) before it, `acct.to` after; the value is built in full before the rewrite, so it may read `acct.from`. Resized to `To` (the payer tops up rent when it grows, at most 10 KiB; shrinking keeps the lamports; growing needs `SystemProgram`). Fixed-layout structs without growable Vecs; no constraints yet; the account cannot be passed to a helper (use `acct.to` fields in the instruction). An account already migrated fails with 3002. Keep the old struct under a new name with its discriminator: `/** @discriminator account:Counter */ interface CounterV1 { … }` |
|
|
98
98
|
| `Zeroed<T>` | accounts (up to 10 MiB) the client allocated with System `CreateAccount`, Anchor's `zero`: discriminator still zero (2013, checked first as under Anchor), owned by this program, big enough, rent-exempt — then initialized. A `@layout borsh` struct starts empty and is written as Borsh when the instruction returns |
|
|
99
99
|
| `Signed<A>` | the account must sign the transaction (Anchor's `signer` constraint, 2002), e.g. `Signed<Zeroed<Multisig>>` for an account the client creates with a fresh keypair; the IDL marks it a signer |
|
|
100
|
-
| `Init<Mint>`, `InitIfNeeded<Mint>` | Anchor `init` / `init_if_needed` with `mint::decimals` / `mint::authority` / `mint::freeze_authority`: `const bump = mint.create(payer, ["mint", payer.key], 6n, authority, freezeAuthority \| null)` creates the mint at that PDA of this program, or with `null` seeds as a new keypair account that signs (3010 if it did not), under the instruction's token program (its only token program parameter, or one passed as the last argument of `create` / `createIfNeeded`; plus `SystemProgram`). Token-2022 extensions (Anchor's `extensions::…`) go after the freeze authority: `mint.create(payer, null, 6n, authority, null, { metadataPointer: { authority, metadataAddress: mint.key }, transferHook: { authority, programId }, closeAuthority, permanentDelegate, nonTransferable: true, defaultAccountState: true, interestBearing: { rateAuthority, rate }, transferFee: { configAuthority, withdrawAuthority, basisPoints, maximumFee }, groupPointer, groupMemberPointer })` sizes the mint for them and initializes each before InitializeMint2. With `createIfNeeded` an existing mint must carry groupPointer / groupMemberPointer / metadataPointer / closeAuthority / permanentDelegate / transferHook with those keys (Anchor's 2024–2039); extensions not listed are not looked at, so an existing mint may carry others (a permanent delegate, say). `createIfNeeded(…)` returns whether it created it; an existing one must be that PDA and have those decimals and authorities (2018 / 2016 / 2017) |
|
|
100
|
+
| `Init<Mint>`, `InitIfNeeded<Mint>` | Anchor `init` / `init_if_needed` with `mint::decimals` / `mint::authority` / `mint::freeze_authority`: `const bump = mint.create(payer, ["mint", payer.key], 6n, authority, freezeAuthority \| null)` creates the mint at that PDA of this program, or with `null` seeds as a new keypair account that signs (3010 if it did not), under the instruction's token program (its only token program parameter, or one passed as the last argument of `create` / `createIfNeeded`; plus `SystemProgram`). Token-2022 extensions (Anchor's `extensions::…`) go after the freeze authority: `mint.create(payer, null, 6n, authority, null, { metadataPointer: { authority, metadataAddress: mint.key }, transferHook: { authority, programId }, closeAuthority, permanentDelegate, nonTransferable: true, defaultAccountState: true, interestBearing: { rateAuthority, rate }, transferFee: { configAuthority, withdrawAuthority, basisPoints, maximumFee }, groupPointer, groupMemberPointer })` sizes the mint for them (as Token-2022 does: extensions adding up to a Multisig's 355 bytes give a 357-byte mint) and initializes each before InitializeMint2; a `null` authority is sent as Token-2022's empty COption. With `createIfNeeded` an existing mint must carry groupPointer / groupMemberPointer / metadataPointer / closeAuthority / permanentDelegate / transferHook with those keys (Anchor's 2024–2039); extensions not listed are not looked at, so an existing mint may carry others (a permanent delegate, say). `createIfNeeded(…)` returns whether it created it; an existing one must be that PDA and have those decimals and authorities (2018 / 2016 / 2017) |
|
|
101
101
|
| `Init<TokenAccount>`, `InitIfNeeded<TokenAccount>` (no `Ata<…>`) | Anchor `init` / `init_if_needed` with `token::mint` / `token::authority`: `vault.create(payer, ["vault", mint.key], mint, authority)` (the authority may be `vault.key` itself) creates a token account at that PDA (or a keypair account with `null`), sized for the mint's extensions under Token-2022. `createIfNeeded` checks an existing one has that mint and owner (2014 / 2015), not its delegate or close authority (as Anchor) |
|
|
102
102
|
| `TokenAccount` / `Mut<TokenAccount>` | owned by SPL Token or Token-2022 (extensions allowed, multisig accounts refused), initialized (an account never created: 3012, as Anchor; a `Mint` likewise); `mint`, `owner`, `amount`, `delegate`, `delegatedAmount`, `isFrozen`, `isNative`, `closeAuthority`, `tokenProgram` |
|
|
103
103
|
| `Mint` / `Mut<Mint>` | owned by SPL Token or Token-2022, initialized; `decimals`, `supply`, `mintAuthority`, `freezeAuthority`, `tokenProgram` |
|
|
@@ -120,7 +120,9 @@ Two writable parameters can never be the same account: aliasing is refused with
|
|
|
120
120
|
account written through `.lamports` or `loadAccountMut` is another account of the instruction). `Dup<Mut<T>>`
|
|
121
121
|
(Anchor's `dup`) lifts that for one parameter when both accounts are read and written in place (not created, closed
|
|
122
122
|
or `@layout borsh`; a close destination may be one, the rent reaching it through either): a write through either is
|
|
123
|
-
seen through the other, so read what you need before writing. A
|
|
123
|
+
seen through the other, so read what you need before writing. A reference into one of them (`const e = a.entries.get(i)`)
|
|
124
|
+
cannot be used after a push, pop or clear through the other moved that data, as with one name (compile error); copy
|
|
125
|
+
the fields first. A remaining account
|
|
124
126
|
can be loaded with `loadAccountMut` once per instruction: loading the same one again (`rest.get(i)` and `rest.get(j)`
|
|
125
127
|
with `i == j`) is refused with 2040 too, since the two views would alias. So is a second `loadAccountMut` of one
|
|
126
128
|
`AccountInfo` parameter; two `Dup<…>` parameters that are one account may each be loaded (one array holding both ticks
|
package/docs/security-model.md
CHANGED
|
@@ -59,16 +59,23 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
59
59
|
replacing or resizing what a live reference points into is a compile error, as is writing a Vec element with a
|
|
60
60
|
right side that may resize the Vec. A helper given a writable struct account may replace anything in it, however
|
|
61
61
|
the account is named at the call (a parameter, an account group's field, a struct loaded with `loadAccountMut`): a
|
|
62
|
-
reference into it read after the call is a compile error.
|
|
62
|
+
reference into it read after the call is a compile error. Data that moves (a Vec of the account resized, so the
|
|
63
|
+
Vecs after it shift, or a helper given the account) moves under every name of the account: a reference made
|
|
64
|
+
through another parameter that may be the same account (a `Dup<…>` pair, a read-only and a writable account of one
|
|
65
|
+
type, a struct loaded with `loadAccount` / `loadAccountMut`) is held to the same rule. A helper that can write gets its Pubkey, Option and
|
|
63
66
|
string arguments as they were at the call (a copy unless nothing it is given reaches them), and a closed account
|
|
64
67
|
is not used after `close()` (compile error).
|
|
65
68
|
10. **Remaining accounts.** Writing one (`.lamports`, `loadAccountMut`) checks it is writable (3006) and not another
|
|
66
69
|
account of the instruction (2040); `loadAccountMut` loads a given account once per instruction (2040);
|
|
67
70
|
`loadAccount<T>` checks owner, discriminator and size, and validates the data as instruction arguments are.
|
|
68
|
-
11. **Growth.** An account grows by at most 10 KiB per instruction (3016),
|
|
69
|
-
zero and the new rent is paid; shrinking keeps
|
|
71
|
+
11. **Growth.** An account grows by at most 10 KiB per instruction (3016), counted from its length when the
|
|
72
|
+
instruction started, the payer is a `Mut<Signer>`, new bytes are zero and the new rent is paid; shrinking keeps
|
|
73
|
+
the lamports in the account.
|
|
70
74
|
12. **CPIs.** A program signs only for its own PDAs (the runtime enforces it; the seeds are those written in the
|
|
71
|
-
source, with the values they had where the list was written, also for a named list or one given to a helper
|
|
75
|
+
source, with the values they had where the list was written, also for a named list or one given to a helper; a
|
|
76
|
+
wrapper's arguments are evaluated left to right, as JS evaluates them, the seeds after the arguments before
|
|
77
|
+
them). Token-2022 and SPL Token instruction data is laid out as the program reads it (a `COption` key that is
|
|
78
|
+
None is one byte). `invoke` marks an account writable or signer only when the parameter is `Mut` / `Signer` or the program
|
|
72
79
|
signs for it; remaining accounts keep the flags they were passed with, or are checked for the role requested.
|
|
73
80
|
`invokeInstruction` is the exception by design: its program, account flags and data come from values (stored in
|
|
74
81
|
account data or passed in), so the compiler cannot check them; the runtime does, refusing any account the
|
|
@@ -91,15 +98,23 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
91
98
|
- **`requirePda(account, seeds, bump)`.** Any valid bump passes (Anchor's `bump = expr`). Use a stored bump, never one
|
|
92
99
|
from the arguments.
|
|
93
100
|
- **`Dup<…>`.** A parameter marked `Dup` may be the same account as another writable one. Reads see every write
|
|
94
|
-
(both are the same bytes), so a value read before a write through the other slot is stale: read, then write.
|
|
101
|
+
(both are the same bytes), so a value read before a write through the other slot is stale: read, then write. (A
|
|
102
|
+
reference held across a resize through the other slot is a compile error, guarantee 9.)
|
|
95
103
|
- **`NATIVE_ACCOUNT_WRITES`.** A program that declares it gives up the up-front writability check and the
|
|
96
104
|
one-view-per-account refusal for `loadRawMut`, `storeBorsh` and BigVec writes, as a native program has neither: the
|
|
97
105
|
runtime still refuses a changed read-only account, but two loads of one account alias each other. Make the
|
|
98
106
|
original's address and type checks before loading.
|
|
99
107
|
- **Instruction introspection.** The Instructions sysvar holds what the transaction's author put there. Require things
|
|
100
108
|
of the transaction with it (that a repay instruction follows), never treat it as proof of who did what.
|
|
101
|
-
- **Oracles.** `pythPrice` checks
|
|
102
|
-
fields are unchecked. `switchboardValue`
|
|
109
|
+
- **Oracles.** `pythPrice` checks the owner and account type, full verification, the feed id, the age and (when
|
|
110
|
+
passed) the exponent; the raw `update.*` fields are unchecked. `switchboardValue` checks the owner, the account
|
|
111
|
+
type, the expected feed, the sample count (`minSamples`, default 1) and staleness, measured in slots from the
|
|
112
|
+
feed's `result.slot`. Neither checks, and both leave to the author:
|
|
113
|
+
- the price's sign and zero: a negative or zero price is returned as it is;
|
|
114
|
+
- the confidence: Pyth's `conf` and Switchboard's spread of samples are not compared with anything;
|
|
115
|
+
- a publish time (Pyth) or result slot (Switchboard) in the future: it counts as fresh;
|
|
116
|
+
- rounding: `switchboardValue` scales the 18-decimal result to `decimals` rounding toward zero, and a price scaled
|
|
117
|
+
by its exponent in the program rounds as that code does.
|
|
103
118
|
- **`merkleVerify`.** Leaves and inner nodes hash alike: build leaves as `keccak256(keccak256(data))` in the program.
|
|
104
119
|
- **Existing accounts in `createIfNeeded`.** An existing token account's delegate and close authority, and a mint's
|
|
105
120
|
extensions the call does not name, are not checked (as in Anchor).
|
|
@@ -112,6 +127,25 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
112
127
|
- Arithmetic overflow returns an error code (5100) in every build; Anchor aborts the program, and only when
|
|
113
128
|
overflow checks are enabled.
|
|
114
129
|
|
|
130
|
+
## Review of 0.44.0 (2026-11-11)
|
|
131
|
+
|
|
132
|
+
A second internal review, of 0.44.0, found guarantees 9 and 12 and the token wrappers' instruction data broken in the
|
|
133
|
+
cases listed in [audit.md](audit.md#0440-2026-11-11); they are fixed in 0.44.1. Of the 76 programs of the 0.44.0
|
|
134
|
+
sources, 74 build to the same binary with 0.44.1 and 2 to another (mint-close-authority and allow-block-list-token);
|
|
135
|
+
none is refused. A program was exposed only if it uses the construct a defect names:
|
|
136
|
+
|
|
137
|
+
- `mint.create` / `createIfNeeded` with `transferFee` whose config or withdraw authority is `null` or a run-time None
|
|
138
|
+
(the mint got another fee and no withdraw authority: check the mint), or extensions adding up to 355 bytes (the
|
|
139
|
+
call always failed);
|
|
140
|
+
- a `Dup<…>` pair, a read-only and a writable account of one struct type, or a struct loaded with `loadAccount` /
|
|
141
|
+
`loadAccountMut`, with a reference made through one held across a push, pop or clear (or a helper given the
|
|
142
|
+
account) through the other, when the transaction passes one account for both;
|
|
143
|
+
- a token or Stake wrapper call with signer seeds and an argument that runs code (a helper call, an assignment) whose
|
|
144
|
+
effects the seeds, the amount or a metadata string read;
|
|
145
|
+
- `updateExtraAccountMetas` after the account was already grown in the same instruction.
|
|
146
|
+
|
|
147
|
+
A program that uses none of them was not exposed to these defects; rebuilding it with 0.44.1 gives the same binary.
|
|
148
|
+
|
|
115
149
|
## Review of 0.43.0 (2026-11-11)
|
|
116
150
|
|
|
117
151
|
An internal review of 0.43.0 found that some of the guarantees above did not hold in every case; the defects are
|
|
@@ -140,7 +174,8 @@ exposed to them.
|
|
|
140
174
|
|
|
141
175
|
## Status
|
|
142
176
|
|
|
143
|
-
The compiler and runtime have had internal security reviews, the latest of 0.
|
|
144
|
-
0.44.
|
|
145
|
-
|
|
146
|
-
|
|
177
|
+
The compiler and runtime have had internal security reviews, the latest of 0.44.0 (above); its findings are fixed in
|
|
178
|
+
0.44.1. It was an internal review, not an independent audit; it covered the token, Token-2022, Metaplex and Stake
|
|
179
|
+
wrappers, the oracles and SBPF v1/v2 builds of the examples that the review of 0.43.0 left out, but not the Metaplex
|
|
180
|
+
wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows. There has been no
|
|
181
|
+
external audit: see [audit.md](audit.md).
|