@typesol/cli 0.38.0 → 0.39.0
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 +327 -2
- package/README.md +29 -15
- package/SECURITY.md +1 -1
- package/dist/compiler/analyze.d.ts +6 -11
- package/dist/compiler/analyze.js +323 -31
- package/dist/compiler/emit/alias.js +3 -2
- package/dist/compiler/emit/base.d.ts +5 -0
- package/dist/compiler/emit/base.js +2 -0
- package/dist/compiler/emit/borsh.js +63 -2
- package/dist/compiler/emit/calls.d.ts +9 -1
- package/dist/compiler/emit/calls.js +147 -18
- package/dist/compiler/emit/cpi-core.js +17 -5
- package/dist/compiler/emit/cpi.js +81 -27
- package/dist/compiler/emit/create.d.ts +7 -0
- package/dist/compiler/emit/create.js +27 -0
- package/dist/compiler/emit/expressions.js +7 -4
- package/dist/compiler/emit/function.d.ts +7 -0
- package/dist/compiler/emit/function.js +164 -29
- package/dist/compiler/emit/program.js +15 -2
- package/dist/compiler/emit/shared.d.ts +5 -5
- package/dist/compiler/emit/shared.js +5 -0
- package/dist/compiler/emit/statements.d.ts +8 -0
- package/dist/compiler/emit/statements.js +93 -6
- package/dist/compiler/emit/storage.d.ts +10 -1
- package/dist/compiler/emit/storage.js +50 -11
- package/dist/compiler/idl.d.ts +1 -1
- package/dist/compiler/idl.js +42 -11
- package/dist/compiler/model.d.ts +47 -10
- package/dist/compiler/model.js +14 -4
- package/dist/testing.js +8 -0
- package/dist/tools/clientgen.js +10 -1
- package/dist/tools/portgen.d.ts +6 -0
- package/dist/tools/portgen.js +68 -17
- package/docs/architecture.md +5 -4
- package/docs/audit.md +31 -19
- package/docs/case-study-escrow.md +5 -5
- package/docs/case-study-jito-mev.md +9 -5
- package/docs/case-study-marginfi.md +797 -0
- package/docs/case-study-multisig.md +3 -3
- package/docs/case-study-raydium-clmm.md +44 -33
- package/docs/case-study-raydium-cp-swap.md +3 -3
- package/docs/cli.md +5 -5
- package/docs/client.md +1 -1
- package/docs/errors.md +13 -5
- package/docs/language.md +38 -25
- package/docs/migrate-from-anchor.md +4 -1
- package/docs/runtime.md +1 -1
- package/docs/security-model.md +2 -1
- package/docs/testing.md +33 -1
- package/lib/typesol.d.ts +46 -9
- package/package.json +9 -7
- package/runtime/typesol_rt.h +111 -17
package/dist/tools/clientgen.js
CHANGED
|
@@ -81,7 +81,8 @@ export const TYPESOL_ERRORS = {
|
|
|
81
81
|
const INTS = { u8: 8, u16: 16, u32: 32, u64: 64, u128: 128, i8: 8, i16: 16, i32: 32, i64: 64, i128: 128 };
|
|
82
82
|
const FLOATS = { f32: 32, f64: 64 };
|
|
83
83
|
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
84
|
-
|
|
84
|
+
/** A seed path: `arg`, `arg.field…`, or `opt.unwrap_or(N)` (Anchor's text for an Option argument with a default). */
|
|
85
|
+
const PATH = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*(\.unwrap_or\(-?\d+\))?$/;
|
|
85
86
|
const BASE58 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
86
87
|
const JS_RESERVED = new Set(("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in " +
|
|
87
88
|
"instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package " +
|
|
@@ -1112,6 +1113,14 @@ function generate(idl, opts) {
|
|
|
1112
1113
|
if (s.kind === "const")
|
|
1113
1114
|
return bytes(s.value);
|
|
1114
1115
|
if (s.kind === "arg") {
|
|
1116
|
+
// `opt.unwrap_or(7)`: an Option argument, or 7 when it is None.
|
|
1117
|
+
const fallback = /^(.*)\.unwrap_or\((-?\d+)\)$/.exec(s.path);
|
|
1118
|
+
if (fallback) {
|
|
1119
|
+
const t = argType.get(fallback[1]);
|
|
1120
|
+
if (t === undefined || typeof t !== "object" || t.option === undefined || !(typeof t.option === "string" && t.option in INTS))
|
|
1121
|
+
return { why: `the seed ${s.path} is not an Option integer argument with a default` };
|
|
1122
|
+
return `${codec(t.option)}.encode(${refs.arg(camel(fallback[1]))} ?? ${fallback[2]})`;
|
|
1123
|
+
}
|
|
1115
1124
|
// `params.id`: a field (of a field…) of a struct argument.
|
|
1116
1125
|
const [head, ...rest] = s.path.split(".");
|
|
1117
1126
|
let t = argType.get(head);
|
package/dist/tools/portgen.d.ts
CHANGED
package/dist/tools/portgen.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* data enum, a COption) it says so in a note and a comment.
|
|
10
10
|
*/
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
|
-
import { cNameProblem } from "../compiler/analyze.js";
|
|
12
|
+
import { ACCOUNT_MEMBERS, cNameProblem, fieldIdlName } from "../compiler/analyze.js";
|
|
13
13
|
const RESERVED = new Set("break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield let static implements interface package private protected public await".split(" "));
|
|
14
14
|
const camel = (s) => s.replace(/[_-]+([a-zA-Z0-9])/g, (_, c) => c.toUpperCase()).replace(/^[A-Z]/, (c) => c.toLowerCase());
|
|
15
15
|
const pascal = (s) => camel(s).replace(/^[a-z]/, (c) => c.toUpperCase());
|
|
@@ -130,6 +130,9 @@ export function generatePort(idl) {
|
|
|
130
130
|
}
|
|
131
131
|
if (t === "bytes")
|
|
132
132
|
return tsType({ vec: "u8" }, where, at, last);
|
|
133
|
+
// An f64 is held as its bits (no float arithmetic): f64FromBits / f64Bits.
|
|
134
|
+
if (t === "f64")
|
|
135
|
+
return use("f64");
|
|
133
136
|
notes.push(`${at}: IDL type "${t}" has no TypeSOL equivalent; left as u64`);
|
|
134
137
|
return `${use("u64")} /* TODO: ${t} */`;
|
|
135
138
|
}
|
|
@@ -145,7 +148,8 @@ export function generatePort(idl) {
|
|
|
145
148
|
notes.push(`${at}: a COption (4-byte tag in Anchor); TypeSOL's Option has a 1-byte tag, so this layout differs.`);
|
|
146
149
|
if (t.option || t.coption) {
|
|
147
150
|
const inner = tsType((t.option ?? t.coption), where === "variant" ? "variant" : where, at);
|
|
148
|
-
|
|
151
|
+
// A struct argument holding Options is Borsh on the wire (as Anchor sends it); account data and variants are fixed.
|
|
152
|
+
if (fixed(where) && where !== "struct")
|
|
149
153
|
notes.push(`${at}: an Option in ${describe(where)} is fixed-size in TypeSOL (1 + size of T), Borsh (1, or 1 + size) in Anchor: the layout differs.`);
|
|
150
154
|
return `${use("Option")}<${inner}>`;
|
|
151
155
|
}
|
|
@@ -182,13 +186,26 @@ export function generatePort(idl) {
|
|
|
182
186
|
return `${use("u64")} /* TODO */`;
|
|
183
187
|
};
|
|
184
188
|
/** A String, Vec or Option at a struct's top level: Borsh-sized in Anchor. */
|
|
189
|
+
const nestedOption = (t, seen = new Set()) => {
|
|
190
|
+
if (typeof t === "string")
|
|
191
|
+
return false;
|
|
192
|
+
if (t.option || t.coption)
|
|
193
|
+
return true;
|
|
194
|
+
if (t.array)
|
|
195
|
+
return nestedOption(t.array[0], seen);
|
|
196
|
+
const name = t.defined ? (typeof t.defined === "string" ? t.defined : t.defined.name) : undefined;
|
|
197
|
+
if (!name || seen.has(name))
|
|
198
|
+
return false;
|
|
199
|
+
const def = (idl.types ?? []).find((d) => d.name === name);
|
|
200
|
+
return !!def && def.type.kind === "struct" && (def.type.fields ?? []).some((f) => nestedOption(f.type, new Set([...seen, name])));
|
|
201
|
+
};
|
|
185
202
|
const borshOnly = (t) => t === "string" || t === "bytes" || (typeof t === "object" && (!!t.vec || !!t.option));
|
|
186
203
|
/** A field's type in a `@layout borsh` struct, or undefined when that layout cannot hold it. Notes the capacities. */
|
|
187
204
|
const borshField = (t, at) => {
|
|
188
205
|
const quiet = at === "";
|
|
189
206
|
const fixedOk = (u) => {
|
|
190
207
|
if (typeof u === "string")
|
|
191
|
-
return INTS.has(u) || u === "bool" || u === "pubkey" || u === "publicKey";
|
|
208
|
+
return INTS.has(u) || u === "bool" || u === "pubkey" || u === "publicKey" || u === "f64";
|
|
192
209
|
if (u.array)
|
|
193
210
|
return Number.isInteger(Number(u.array[1])) && fixedOk(u.array[0]);
|
|
194
211
|
if (u.defined) {
|
|
@@ -226,17 +243,37 @@ export function generatePort(idl) {
|
|
|
226
243
|
notes.push(`${at}: set the Vec's capacity to Anchor's #[max_len] (Borsh bytes are kept: @layout borsh)`);
|
|
227
244
|
return `${use("FixedVec")}<${elem}, 8> /* TODO: #[max_len] */`;
|
|
228
245
|
}
|
|
246
|
+
// A struct with Options inside (Marginfi's event header): Borsh at every depth, its own fields fixed or Options.
|
|
247
|
+
const nestedOk = (u) => {
|
|
248
|
+
if (typeof u !== "object" || !u.defined)
|
|
249
|
+
return false;
|
|
250
|
+
const d = defs.get(definedName(u.defined));
|
|
251
|
+
if (!d || d.type.kind !== "struct")
|
|
252
|
+
return false;
|
|
253
|
+
return (d.type.fields ?? []).every((f) => fixedOk(f.type) || nestedOk(f.type) || (typeof f.type === "object" && !!f.type.option && (fixedOk(f.type.option) || nestedOk(f.type.option))));
|
|
254
|
+
};
|
|
229
255
|
if (typeof t === "object" && t.option) {
|
|
230
|
-
if (!fixedOk(t.option))
|
|
256
|
+
if (!fixedOk(t.option) && !nestedOk(t.option))
|
|
231
257
|
return undefined;
|
|
232
|
-
return quiet ? "x" : `${use("Option")}<${tsType(t.option, "
|
|
258
|
+
return quiet ? "x" : `${use("Option")}<${tsType(t.option, "event", at)}>`;
|
|
233
259
|
}
|
|
260
|
+
if (nestedOk(t))
|
|
261
|
+
return quiet ? "x" : tsType(t, "event", at);
|
|
234
262
|
if (!fixedOk(t))
|
|
235
263
|
return undefined;
|
|
236
264
|
return quiet ? "x" : tsType(t, "account", at);
|
|
237
265
|
};
|
|
238
266
|
const esc = (s) => s.replace(/\*\//g, "* /");
|
|
239
|
-
const docs = (lines, pad = ""
|
|
267
|
+
const docs = (lines, pad = "", tags = []) => tags.length
|
|
268
|
+
? `${pad}/**\n${lines?.length ? `${pad} * ${esc(lines.join(" "))}\n` : ""}${tags.map((t) => `${pad} * ${t}\n`).join("")}${pad} */\n`
|
|
269
|
+
: lines?.length
|
|
270
|
+
? `${pad}/** ${esc(lines.join(" "))} */\n`
|
|
271
|
+
: "";
|
|
272
|
+
// What an Anchor IDL says of a zero-copy type (repr, serialization), kept as tags so the port's IDL says it too.
|
|
273
|
+
const metaTags = (def) => [
|
|
274
|
+
...(def.serialization ? [`@serialization ${def.serialization}`] : []),
|
|
275
|
+
...(def.repr ? [`@repr ${def.repr.kind}${def.repr.packed ? " packed" : ""}${def.repr.align ? ` align ${def.repr.align}` : ""}`] : []),
|
|
276
|
+
];
|
|
240
277
|
const out = [];
|
|
241
278
|
// Constants: integer literals and strings; expressions are left to port by hand.
|
|
242
279
|
for (const c of idl.constants ?? []) {
|
|
@@ -266,26 +303,34 @@ export function generatePort(idl) {
|
|
|
266
303
|
// An account struct, or one passed / returned whole, with a String, Vec or Option of its own: `@layout borsh`
|
|
267
304
|
// keeps Anchor's bytes.
|
|
268
305
|
const borshable = accountNames.has(def.name) || (whole.has(def.name) && !nested.has(def.name) && !eventNames.has(def.name));
|
|
269
|
-
const borsh = borshable && !isTuple(fields) && fields.some((f) => borshOnly(f.type)) && fields.every((f) => borshField(f.type, "") !== undefined)
|
|
306
|
+
const borsh = (borshable && !isTuple(fields) && fields.some((f) => borshOnly(f.type)) && fields.every((f) => borshField(f.type, "") !== undefined)) ||
|
|
307
|
+
// An event holding a struct with Options (Marginfi's header { signer: Option<Pubkey> }): Borsh at every depth.
|
|
308
|
+
(eventNames.has(def.name) && !isTuple(fields) && fields.some((f) => nestedOption(f.type)));
|
|
270
309
|
const tag = accountNames.has(def.name) ? " (account)" : eventNames.has(def.name) ? ` (event: emit<${typeName(def.name)}>({ … }))` : "";
|
|
271
310
|
const doc = def.docs?.length ? esc(def.docs.join(" ")) : `${def.name}${tag}`;
|
|
272
|
-
|
|
311
|
+
const typeTags = [...(borsh ? ["@layout borsh"] : []), ...metaTags(def)];
|
|
312
|
+
out.push(typeTags.length ? `/**\n * ${doc}\n${typeTags.map((t) => ` * ${t}\n`).join("")} */` : `/** ${doc} */`);
|
|
273
313
|
out.push(`export interface ${typeName(def.name)} {`);
|
|
274
314
|
const seen = new Set();
|
|
275
315
|
fields.forEach((f, i) => {
|
|
276
316
|
let n = ident(f.name, true);
|
|
317
|
+
// An account member's name (key, lamports) is held as key_, which the IDL still calls key.
|
|
318
|
+
if (ACCOUNT_MEMBERS.has(n))
|
|
319
|
+
n = `${n}_`;
|
|
277
320
|
while (seen.has(n))
|
|
278
321
|
n = `${n}2`;
|
|
279
322
|
seen.add(n);
|
|
280
323
|
const ty = borsh ? borshField(f.type, `${def.name}.${f.name}`) : tsType(f.type, where, `${def.name}.${f.name}`, i === fields.length - 1);
|
|
281
|
-
|
|
324
|
+
// The IDL's own name where TypeSOL's would differ (_pad0, integration_acc_1).
|
|
325
|
+
const tags = fieldIdlName(n) === f.name ? [] : [`@idlName ${f.name}`];
|
|
326
|
+
out.push(`${docs(f.docs, " ", tags)} ${n}: ${ty};`);
|
|
282
327
|
});
|
|
283
328
|
out.push("}", "");
|
|
284
329
|
}
|
|
285
330
|
else {
|
|
286
331
|
const variants = def.type.variants ?? [];
|
|
287
332
|
if (variants.every((v) => !v.fields?.length)) {
|
|
288
|
-
out.push(`${docs(def.docs)}export enum ${typeName(def.name)} {`, ...variants.map((v) => ` ${ident(v.name, true).replace(/^[a-z]/, (c) => c.toUpperCase())},`), "}", "");
|
|
333
|
+
out.push(`${docs(def.docs, "", metaTags(def))}export enum ${typeName(def.name)} {`, ...variants.map((v) => ` ${ident(v.name, true).replace(/^[a-z]/, (c) => c.toUpperCase())},`), "}", "");
|
|
289
334
|
}
|
|
290
335
|
else {
|
|
291
336
|
// Strings in variants are fine in arguments and events (Borsh); account data needs fixed-size variants.
|
|
@@ -296,17 +341,17 @@ export function generatePort(idl) {
|
|
|
296
341
|
: `f${i}: ${tsType(f, vw, `${def.name}.${v.name}`)}`);
|
|
297
342
|
return `{ kind: "${pascal(v.name)}"${fs.map((x) => `; ${x}`).join("")} }`;
|
|
298
343
|
});
|
|
299
|
-
out.push(`${docs(def.docs)}export type ${typeName(def.name)} =\n | ${parts.join("\n | ")};`, "");
|
|
344
|
+
out.push(`${docs(def.docs, "", metaTags(def))}export type ${typeName(def.name)} =\n | ${parts.join("\n | ")};`, "");
|
|
300
345
|
}
|
|
301
346
|
}
|
|
302
347
|
}
|
|
303
|
-
// Errors: TypeSOL numbers them 6000
|
|
304
|
-
// codes of the program's own errors do not move.
|
|
305
|
-
const errors = idl.errors ?? [];
|
|
348
|
+
// Errors: TypeSOL numbers them from 6000 in order; `/** @code N */` keeps an IDL code that skips ahead. NotPorted,
|
|
349
|
+
// last, marks the instructions still to write, so the codes of the program's own errors do not move.
|
|
350
|
+
const errors = [...(idl.errors ?? [])].sort((a, b) => a.code - b.code);
|
|
306
351
|
const program = typeName(pascal(idl.metadata?.name ?? "program"));
|
|
307
352
|
const errorEnum = `${program}Error`;
|
|
308
|
-
if (
|
|
309
|
-
notes.push(`errors:
|
|
353
|
+
if (errors.some((e, i) => e.code < 6000 || (i > 0 && e.code === errors[i - 1].code)))
|
|
354
|
+
notes.push(`errors: codes below 6000 or repeated in the IDL (${errors.map((e) => e.code).join(", ")}) cannot be kept, so clients see other codes`);
|
|
310
355
|
const memberNames = new Set();
|
|
311
356
|
const member = (name) => {
|
|
312
357
|
// RequireFailedN is TypeSOL's own name for require("message") errors; it is reserved in source.
|
|
@@ -316,7 +361,13 @@ export function generatePort(idl) {
|
|
|
316
361
|
memberNames.add(n);
|
|
317
362
|
return n;
|
|
318
363
|
};
|
|
319
|
-
|
|
364
|
+
let nextCode = 6000;
|
|
365
|
+
const errorLines = errors.flatMap((e) => {
|
|
366
|
+
const skip = e.code > nextCode ? [` /** @code ${e.code} */`] : [];
|
|
367
|
+
nextCode = Math.max(nextCode, e.code) + 1;
|
|
368
|
+
// An error without a message has none in TypeSOL's IDL either.
|
|
369
|
+
return [...skip, ` ${member(e.name)} = ${JSON.stringify(e.msg ?? "")},`];
|
|
370
|
+
});
|
|
320
371
|
const notPorted = member("NotPorted");
|
|
321
372
|
out.push(`export enum ${errorEnum} {`, ...errorLines, ` ${notPorted} = "This instruction is not ported yet",`, "}", "");
|
|
322
373
|
// Accounts of an instruction, nested groups flattened.
|
package/docs/architecture.md
CHANGED
|
@@ -31,9 +31,10 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
|
|
|
31
31
|
| `lib/` | `typesol.d.ts`, the language surface programs typecheck against |
|
|
32
32
|
| `ts-plugin/` | The editor plugin (`typesol/ts-plugin`) |
|
|
33
33
|
| `examples/` | Example programs; the `typesol init` templates are copies of three of them |
|
|
34
|
-
| `test/` | The test suite, by subject: `language/`, `security/`, `examples/`, `integrations/` (token, Metaplex, oracle and other CPIs), `client/`, `cli/`, `
|
|
35
|
-
| `
|
|
36
|
-
| `
|
|
34
|
+
| `test/` | The compiler's test suite (`pnpm test:core`), by subject: `language/`, `security/`, `examples/`, `integrations/` (token, Metaplex, oracle and other CPIs), `client/`, `cli/`, `verification/` (differential and fuzz tests). Shared: `harness.ts` and the `*-helpers.ts`, `fixtures/` (programs the tests compile), `golden/` (pinned generated C and clients), `programs/` (third-party program binaries, see its SOURCES.md), `anchor-twins/` (below) |
|
|
35
|
+
| `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Raydium CP-Swap and CLMM, Jito's MEV programs, Marginfi, coral-xyz/multisig, each checked against the binary on mainnet), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
|
|
36
|
+
| `test/anchor-twins/` | Anchor twins of the counter, vault and escrow examples, for the differential tests (`pnpm build:twins`) and the zero-copy client test; the benchmarks themselves are in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) |
|
|
37
|
+
| `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes) |
|
|
37
38
|
| `docs/` | User and contributor documentation (also published on typesol.com) |
|
|
38
39
|
| `assets/` | The CLI's logo and the README images (`readme/`, generated) |
|
|
39
40
|
|
|
@@ -101,7 +102,7 @@ representation in between. We reviewed this on 2026-10-30 and kept it that way f
|
|
|
101
102
|
named in the source, see `alias.ts`), a second backend (SBF without clang), and optimizations clang cannot see
|
|
102
103
|
because they depend on account semantics (dropping a repeated check, packing a `@layout borsh` account only where
|
|
103
104
|
it changed).
|
|
104
|
-
- **What it would cost now:** rewriting most of the compiler's
|
|
105
|
+
- **What it would cost now:** rewriting most of the compiler's 14,000 lines, and losing the property every release
|
|
105
106
|
relies on: programs that do not use a change compile to the same binaries. Audit scope and differential results
|
|
106
107
|
would start over.
|
|
107
108
|
- **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,21 +7,21 @@ 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.38.0 plus main (November 2026).
|
|
11
11
|
|
|
12
12
|
| Priority | Component | Files | Lines | Why |
|
|
13
13
|
| --- | --- | --- | ---: | --- |
|
|
14
|
-
| 1 | C runtime | `runtime/typesol_rt.h` |
|
|
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` | 2,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 3,
|
|
18
|
-
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,
|
|
19
|
-
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,
|
|
20
|
-
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,
|
|
21
|
-
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,
|
|
14
|
+
| 1 | C runtime | `runtime/typesol_rt.h` | 2,407 | 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` | 733 | 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` | 2,577 | 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` | 3,730 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
|
|
18
|
+
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,454 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
|
|
19
|
+
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,656 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
|
|
20
|
+
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,715 | What the language accepts; constraints and account types as parsed from the source |
|
|
21
|
+
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,293 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
|
|
22
22
|
| 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
|
|
23
23
|
|
|
24
|
-
The language surface is `lib/typesol.d.ts` (
|
|
24
|
+
The language surface is `lib/typesol.d.ts` (2,057 lines): every type and built-in a program can use, with its
|
|
25
25
|
documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
|
|
26
26
|
the code, [docs/runtime.md](runtime.md) the runtime's conventions.
|
|
27
27
|
|
|
@@ -48,7 +48,12 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
|
|
|
48
48
|
|
|
49
49
|
## Earlier reviews
|
|
50
50
|
|
|
51
|
-
Internal reviews, by the maintainers, in October 2026. Their findings and fixes are in the CHANGELOG
|
|
51
|
+
Internal reviews, by the maintainers, in October 2026. Their findings and fixes are in the CHANGELOG. The releases
|
|
52
|
+
after 0.25.0 (0.26.0 to 0.38.0, and main since) have had no review of this kind yet; they add, among others, `u256`,
|
|
53
|
+
big-endian seeds and accounts loaded in the body (0.37.0), stored bumps in nested fields and error members without
|
|
54
|
+
messages (0.38.0), and on main `@code`, `@repr` / `@serialization`, `@bytes` / `@idlName`, `f64`, Options inside
|
|
55
|
+
Options in arguments and events, and loop-scoped `loadAccountMut` with `Dup<T>`. An external review should include
|
|
56
|
+
them.
|
|
52
57
|
|
|
53
58
|
- **0.25.0** (runtime and emitted checks): two Medium issues fixed, a remaining account loaded mutably twice through
|
|
54
59
|
the same slot, and a Vec element written after its right side resized the Vec; plus a token program ambiguity,
|
|
@@ -60,22 +65,29 @@ Internal reviews, by the maintainers, in October 2026. Their findings and fixes
|
|
|
60
65
|
|
|
61
66
|
## Evidence
|
|
62
67
|
|
|
63
|
-
- **Tests**:
|
|
68
|
+
- **Tests**: by subject under `test/` (`docs/architecture.md`); the count of each run is in CI's log (727 on main on
|
|
69
|
+
2026-11-01). `test/security/` holds the attacks.
|
|
64
70
|
- **Differential tests**: the same transactions to TypeSOL and to Anchor twins (`test/anchor-twins`), comparing
|
|
65
71
|
outcomes, account contents and balances after every step.
|
|
66
|
-
- **Model-based fuzzing** (`test/verification/`): arithmetic against BigInt at every width
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
- **Model-based fuzzing** (`test/verification/`): arithmetic against BigInt at every width, `u256` against BigInt,
|
|
73
|
+
Marginfi's I80F48 against vectors the `fixed` crate wrote; honest and hostile action sequences against state models
|
|
74
|
+
with value conservation; account layout with two growable Vecs and aliasing through remaining accounts. Each run
|
|
75
|
+
prints its seed (`FUZZ_SEED`), `pnpm fuzz` runs them wide.
|
|
76
|
+
- **Random transactions against mainnet binaries**: Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`),
|
|
77
|
+
Marginfi's administration and interest (`showcase/test/fuzz-marginfi.test.ts`) and Raydium CLMM (the `fuzz:`
|
|
78
|
+
case of its differential test) take random sequences of honest and hostile
|
|
79
|
+
transactions, in the original and the port alike, with the same outcome, account bytes and events required after
|
|
80
|
+
every step. A new seed on every run, CI's included.
|
|
69
81
|
- **Ported programs**: all 46 programs of solana-developers/program-examples, run through their original tests' flows
|
|
70
|
-
and failure paths ([
|
|
71
|
-
- **Four-way comparison**: [typesol/benchmarks](https://github.com/typesol/benchmarks) runs 17 of those programs in
|
|
82
|
+
and failure paths ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)).
|
|
83
|
+
- **Four-way comparison**: [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) runs 17 of those programs in
|
|
72
84
|
TypeSOL, Anchor, native Rust and Pinocchio, requires the same outcome, and records how each refuses the hostile calls
|
|
73
85
|
and with which error.
|
|
74
86
|
|
|
75
87
|
## Running it
|
|
76
88
|
|
|
77
89
|
```sh
|
|
78
|
-
git clone https://github.com/typesol/typesol && cd typesol
|
|
90
|
+
git clone https://github.com/typesol-lang/typesol && cd typesol
|
|
79
91
|
pnpm install && pnpm build
|
|
80
92
|
pnpm fetch:programs # Metaplex binaries for the token-metadata, Core and Bubblegum tests
|
|
81
93
|
pnpm build:twins # the Anchor twins (Rust + Anchor 1.0.2)
|
|
@@ -88,5 +100,5 @@ way to review what a construct compiles to; `test/golden/counter.c` is a pinned
|
|
|
88
100
|
|
|
89
101
|
## Contact
|
|
90
102
|
|
|
91
|
-
Coordinate through a private advisory on https://github.com/typesol/typesol/security, or report findings the same way
|
|
103
|
+
Coordinate through a private advisory on https://github.com/typesol-lang/typesol/security, or report findings the same way
|
|
92
104
|
(SECURITY.md).
|
|
@@ -4,7 +4,7 @@ This page follows one complete Anchor program into TypeSOL: the token escrow fro
|
|
|
4
4
|
[solana-developers/program-examples](https://github.com/solana-developers/program-examples/tree/de090195e4de698e150572c4f886c333323a64a5/tokens/escrow/anchor)
|
|
5
5
|
(`tokens/escrow`, commit `de09019`). It shows the original and the port side by side, what changed, how the two were
|
|
6
6
|
checked against each other, where they still differ, and what the port costs to run. The port is
|
|
7
|
-
[`
|
|
7
|
+
[`showcase/program-examples/tokens/escrow.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/tokens/escrow.ts); [Migrate from Anchor](migrate-from-anchor.md) is the
|
|
8
8
|
general reference.
|
|
9
9
|
|
|
10
10
|
## The program
|
|
@@ -160,17 +160,17 @@ tokenProgram.closeAccount(vault, maker, offer, ["offer", maker.key, offer.id, of
|
|
|
160
160
|
| `ErrorCode::CustomError` (unused upstream) | `enum ErrorCode`, the same code 6000 |
|
|
161
161
|
|
|
162
162
|
Nothing in the program needed a construct TypeSOL lacks, and every account constraint has its TypeSOL form; the port
|
|
163
|
-
is marked PORTED in [the ports table](https://github.com/typesol/typesol/blob/main/
|
|
163
|
+
is marked PORTED in [the ports table](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md).
|
|
164
164
|
|
|
165
165
|
## Same inputs, same results
|
|
166
166
|
|
|
167
167
|
Two independent checks run the original and the port against each other.
|
|
168
168
|
|
|
169
|
-
- **The port's own test** ([`test/porting/ports-tokens.test.ts`](https://github.com/typesol/typesol/blob/main/test/porting/ports-tokens.test.ts)) runs the upstream flow with SPL
|
|
169
|
+
- **The port's own test** ([`showcase/test/porting/ports-tokens.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/porting/ports-tokens.test.ts)) runs the upstream flow with SPL
|
|
170
170
|
Token mints and again with Token-2022 mints: make, take (creating the taker's and the maker's missing token accounts),
|
|
171
171
|
make again, a refund attempt by someone other than the maker, and the refund. It checks balances, the decoded offer
|
|
172
172
|
and that offer and vault are closed.
|
|
173
|
-
- **The four-way comparison** in [typesol/benchmarks](https://github.com/typesol/benchmarks) builds the upstream Anchor,
|
|
173
|
+
- **The four-way comparison** in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) builds the upstream Anchor,
|
|
174
174
|
native and Pinocchio versions unmodified and sends all four the same 21 offers (ten taken, ten refunded, one left
|
|
175
175
|
open). The decoded open offer, every token balance, the vault's authority and which accounts were closed must be
|
|
176
176
|
identical before any number is reported. They are.
|
|
@@ -191,7 +191,7 @@ token account. A client that matches on this code needs to accept either.
|
|
|
191
191
|
## Cost
|
|
192
192
|
|
|
193
193
|
Mean compute units per instruction in LiteSVM (21 make_offer, 10 take_offer and 10 refund_offer calls), and the
|
|
194
|
-
program size, from typesol/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
|
|
194
|
+
program size, from typesol-lang/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
|
|
195
195
|
|
|
196
196
|
| | TypeSOL | Anchor | Native Rust | Pinocchio |
|
|
197
197
|
| --- | ---: | ---: | ---: | ---: |
|
|
@@ -6,9 +6,9 @@ Anchor 0.31.1, Apache-2.0). Each one is checked against the binary that runs on
|
|
|
6
6
|
|
|
7
7
|
| Program | Mainnet id | Port |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| Tip payment | `T1pyyaTNZsKv2WcRAB8oVnk93mLJw2XzjtVYqCsaHqt` | [`tip_payment.ts`](https://github.com/typesol/typesol/blob/main/
|
|
10
|
-
| Tip distribution | `4R3gSG8BpU4t19KYj8CfnbtRpnT8gtk4dvTHxVRwc2r7` | [`tip_distribution.ts`](https://github.com/typesol/typesol/blob/main/
|
|
11
|
-
| Priority fee distribution | `Priority6weCZ5HwDn29NxLFpb7TDp2iLZ6XKc5e8d3` | [`priority_fee_distribution.ts`](https://github.com/typesol/typesol/blob/main/
|
|
9
|
+
| Tip payment | `T1pyyaTNZsKv2WcRAB8oVnk93mLJw2XzjtVYqCsaHqt` | [`tip_payment.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/tip_payment.ts) |
|
|
10
|
+
| Tip distribution | `4R3gSG8BpU4t19KYj8CfnbtRpnT8gtk4dvTHxVRwc2r7` | [`tip_distribution.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/tip_distribution.ts) |
|
|
11
|
+
| Priority fee distribution | `Priority6weCZ5HwDn29NxLFpb7TDp2iLZ6XKc5e8d3` | [`priority_fee_distribution.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/priority_fee_distribution.ts) |
|
|
12
12
|
|
|
13
13
|
Searchers pay tips into eight fixed tip payment accounts. When the leader changes, the tip payment program pays them
|
|
14
14
|
out to the current tip receiver and the block builder's commission to the block builder. The tip receiver is
|
|
@@ -74,9 +74,9 @@ The rest uses what TypeSOL already had:
|
|
|
74
74
|
|
|
75
75
|
## How it was checked
|
|
76
76
|
|
|
77
|
-
[`test/
|
|
77
|
+
[`showcase/test/jito-mev.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/jito-mev.test.ts) loads
|
|
78
78
|
the binaries dumped from mainnet on 2026-10-31 (sha256 in
|
|
79
|
-
[`test/programs/SOURCES.md`](https://github.com/typesol/typesol/blob/main/test/programs/SOURCES.md)). A dump is padded
|
|
79
|
+
[`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)). A dump is padded
|
|
80
80
|
with zeros to its program account's size, 10 MB for tip distribution, so the files are cut where the ELF ends. Each
|
|
81
81
|
original runs in one LiteSVM and its port in another, under the same program id and with the same clock.
|
|
82
82
|
|
|
@@ -117,6 +117,10 @@ There are 150 transactions:
|
|
|
117
117
|
- a go-live epoch in the future, then the current one;
|
|
118
118
|
- a transfer into last epoch's account.
|
|
119
119
|
|
|
120
|
+
Besides these, `showcase/test/fuzz-jito.test.ts` sends random sequences of the same transactions, honest and
|
|
121
|
+
hostile, to the originals and the ports, with a new seed on every run (CI's included). It requires the same outcome,
|
|
122
|
+
bytes, events and log lines after every step; `FUZZ_SEED=<seed>` reproduces a run, `FUZZ_STEPS=<n>` lengthens it.
|
|
123
|
+
|
|
120
124
|
## Cost
|
|
121
125
|
|
|
122
126
|
Compute units per transaction, mainnet original against the port, from one run of that test:
|