@typesol/cli 0.44.0 → 0.45.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/NOTICE +14 -1
  3. package/README.md +52 -10
  4. package/SECURITY.md +1 -1
  5. package/dist/cli.js +194 -48
  6. package/dist/compiler/emit/alias.d.ts +16 -2
  7. package/dist/compiler/emit/alias.js +62 -4
  8. package/dist/compiler/emit/calls.js +15 -7
  9. package/dist/compiler/emit/cpi-core.d.ts +6 -0
  10. package/dist/compiler/emit/cpi-core.js +18 -5
  11. package/dist/compiler/emit/create.js +19 -11
  12. package/dist/compiler/emit/function.js +5 -5
  13. package/dist/compiler/emit/metaplex.js +17 -4
  14. package/dist/compiler/emit/token.js +64 -39
  15. package/dist/compiler/index.d.ts +51 -1
  16. package/dist/compiler/index.js +17 -2
  17. package/dist/compiler/toolchain.d.ts +23 -0
  18. package/dist/compiler/toolchain.js +128 -8
  19. package/dist/tools/docker.d.ts +183 -0
  20. package/dist/tools/docker.js +442 -0
  21. package/dist/tools/doctor.d.ts +3 -0
  22. package/dist/tools/doctor.js +12 -0
  23. package/dist/workspace.d.ts +2 -1
  24. package/dist/workspace.js +33 -6
  25. package/docker/Dockerfile +163 -0
  26. package/docker/deps/0.43.0.lock.json +1206 -0
  27. package/docker/deps/0.44.0.lock.json +1206 -0
  28. package/docker/deps/0.44.1.lock.json +1206 -0
  29. package/docker/deps/0.45.0.lock.json +1206 -0
  30. package/docs/architecture.md +13 -5
  31. package/docs/audit.md +54 -7
  32. package/docs/cli.md +31 -4
  33. package/docs/errors.md +1 -1
  34. package/docs/language.md +6 -4
  35. package/docs/mainnet.md +86 -6
  36. package/docs/security-model.md +47 -12
  37. package/docs/stability.md +62 -3
  38. package/docs/testing.md +49 -2
  39. package/docs/troubleshooting.md +46 -0
  40. package/llms-full.txt +283 -34
  41. package/package.json +3 -1
  42. package/releases/0.43.0.json +669 -0
  43. package/releases/0.44.0.json +672 -0
  44. package/releases/0.44.1.json +672 -0
  45. package/runtime/LICENSE-compiler-builtins.txt +275 -0
  46. package/runtime/typesol_builtins.c +484 -0
  47. package/runtime/typesol_rt.h +8 -5
@@ -27,14 +27,16 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
27
27
  | Path | Contents |
28
28
  | --- | --- |
29
29
  | `src/` | The compiler (`src/compiler/`); the CLI, projects, init templates and `typesol/testing` at the top; generators and chain tooling in `src/tools/` (client, CPI and port generators, IDL publishing, on-chain reads, profiling, the LiteSVM RPC). Source map below |
30
- | `runtime/` | `typesol_rt.h`, the C runtime every program includes ([runtime.md](runtime.md)) |
30
+ | `runtime/` | `typesol_rt.h`, the C runtime every program includes ([runtime.md](runtime.md)), and `typesol_builtins.c`, the compiler builtins every program links |
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 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) |
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, and what 14 programs build to in the build container: SBPF v0, and v1 and v2 for four of them), `programs/` (third-party program binaries, see its SOURCES.md), `anchor-twins/` (below) |
35
35
  | `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, 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
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
+ | `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; the cross-host check against `test/golden/binaries.json`) |
38
+ | `docker/` | The Dockerfile of the `--docker` build container |
39
+ | `releases/` | Each release's npm tarball record (`scripts/release-check.ts`); shipped, so `--docker` can check the tarball it installs |
38
40
  | `docs/` | User and contributor documentation (also published on typesol.com) |
39
41
  | `assets/` | The CLI's logo and the README images (`readme/`, generated) |
40
42
 
@@ -48,11 +50,12 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
48
50
  | `src/compiler/model.ts` | The data model shared by every stage (`ProgramModel`, `Instruction`, `ParamKind`, `FieldType`, `ValueType`) and small type utilities. |
49
51
  | `src/compiler/emit/` | Code generation (see below). |
50
52
  | `src/compiler/idl.ts` | Turns the model into an Anchor IDL: accounts with `pda`, `relations`, `address` and `optional`, plus types, events, errors and docs. |
51
- | `src/compiler/toolchain.ts` | Finds the Agave SDK and runs clang and lld with the SDK's flags, plus per-function sections, `--gc-sections` and `--strip-all` so unused code and symbol tables stay out of the binary. |
53
+ | `src/compiler/toolchain.ts` | Finds the Agave SDK and runs clang and lld with the SDK's flags, plus per-function sections, `--gc-sections` and `--strip-all` so unused code and symbol tables stay out of the binary. Links the program with the runtime's builtins and platform-tools' libc, nothing from its Rust libraries, and refuses a binary that would leave the loader a symbol that is not a syscall. |
52
54
  | `src/compiler/diagnostics.ts` | `Reporter` and `CompileError`: diagnostics with file, line and column. |
53
55
  | `src/compiler/anchor-errors.ts` | Anchor's own error codes (`AnchorError.X`), shared by `require` and the generated clients. |
54
56
  | `src/compiler/index.ts` | The compiler's API (`generate`, `build`, `verifyBinary`, the build manifest). |
55
57
  | `runtime/typesol_rt.h` | The C runtime: error codes, word-wise memory helpers, the entry point's input parser (`ts_deserialize`), account checks, checked math, Borsh helpers, CPIs (System, Token, Token-2022, ATA, Metaplex), oracles and the heap allocator. Header-only and `static inline`, so unused code is dropped. |
58
+ | `runtime/typesol_builtins.c` | The compiler builtins clang calls for 128-bit multiplication, division and shifts and signed 64-bit division, compiled with each program and linked in place of platform-tools' compiler-builtins library (whose build differs between its host packages); a program links the ones it calls. Division in C, multiplication and shifts as the instructions compiler-builtins has for each SBPF version. |
56
59
  | `src/workspace.ts` | `typesol.json` projects, program keypairs, `typesol init` templates and deploy arguments. |
57
60
  | `src/tools/cpigen.ts` | `typesol cpi`: reads an Anchor IDL and writes typed TypeSOL CPI helpers. |
58
61
  | `src/tools/clientgen.ts` | The TypeScript client (`<name>.client.ts`, [client.md](client.md)): reads an IDL, validates it (it may come from anywhere), and writes one `@solana/kit` file. Not part of the compiler core: `workspace.ts` and the CLI write it after `build()`, and `typesol client` writes it for any IDL. |
@@ -65,6 +68,8 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
65
68
  | `src/testing.ts` | `typesol/testing`: LiteSVM test helpers for projects (accounts by name from the IDL, plain values). |
66
69
  | `src/tools/onchain.ts` | `typesol verify --address`: a deployed program's ELF, authority and deploy slot under loader v2, v3 or v4. |
67
70
  | `src/tools/profile.ts` | Turns `--profile` logs into compute units per source line. |
71
+ | `src/tools/docker.ts` | `build --docker` / `verify --docker`: the TypeSOL version and its release record (the package's, a file, or fetched from the repository), the image from `docker/Dockerfile` (built when missing), the locked-down container run, the container's identity in the manifest. |
72
+ | `docker/Dockerfile` | The pinned build environment (linux/amd64, platform-tools v1.52, a recorded TypeSOL tarball); shipped in the package with `releases/`. |
68
73
  | `src/cli.ts` | Command parsing. Every command has strict options, `--help`, and exit codes 0 (success), 1 (failure), 2 (usage error) and 3 (verify mismatch). |
69
74
 
70
75
  ## The emitter
@@ -103,7 +108,7 @@ representation in between. We reviewed this on 2026-10-30 and kept it that way f
103
108
  named in the source, see `alias.ts`), a second backend (SBF without clang), and optimizations clang cannot see
104
109
  because they depend on account semantics (dropping a repeated check, packing a `@layout borsh` account only where
105
110
  it changed).
106
- - **What it would cost now:** rewriting most of the compiler's 19,000 lines, and losing the property every release
111
+ - **What it would cost now:** rewriting most of the compiler's 20,000 lines, and losing the property every release
107
112
  relies on: programs that do not use a change compile to the same binaries. Audit scope and differential results
108
113
  would start over.
109
114
  - **What we have instead:** the layers above, each owning one concern; `Ref` / `Value` as the typed place and value
@@ -182,6 +187,9 @@ These invariants are easy to break. Each one has tests.
182
187
 
183
188
  `test/golden/counter.c` pins the output for the counter example. Run
184
189
  `UPDATE_GOLDEN=1 pnpm test test/language/diagnostics.test.ts`, review the diff, and commit it with the change.
190
+ `test/golden/binaries.json` pins what 14 programs build to in the `--docker` container (SBPF v0, and counter,
191
+ escrow, Phoenix and Marginfi for v1 and v2 too); when they change,
192
+ regenerate it as [testing.md](testing.md#across-hosts) says (CI's cross-host check fails with `STALE` until then).
185
193
 
186
194
  For refactors that should not change behaviour, compare binaries: build every example and fixture before and after
187
195
  the change. The sha256 values in the `*.build.json` manifests must not change.
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.43.0 (November 2026).
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,995 | 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` | 879 | 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,742 | 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,633 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
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,454 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
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) |
@@ -29,7 +29,15 @@ the code, [docs/runtime.md](runtime.md) the runtime's conventions.
29
29
  Out of scope: the Solana runtime, platform-tools (clang, lld), the TypeScript compiler, and programs written with
30
30
  TypeSOL. The platform-tools are part of what a binary trusts all the same: the tests cover the toolchain the release
31
31
  declares (`TESTED_TOOLCHAIN` in `src/compiler/toolchain.ts`: Agave 3.1.10, platform-tools v1.52), builds with another
32
- one warn, and the review of 0.43.0 traced one defect to how that backend passes struct arguments.
32
+ one warn, and the review of 0.43.0 traced one defect to how that backend passes struct arguments. The platform-tools
33
+ host package mattered too, up to 0.44.1: its compiler-builtins library, which each of the macOS, Linux arm64 and
34
+ Linux x86_64 packages lays out differently, made a program with 128-bit or signed division link to different bytes on
35
+ each. From 0.45.0 on the builtins are TypeSOL's own C, compiled with the program, and the programs measured build to
36
+ the same bytes on the three hosts (the 76 of the sources for SBPF v0, 14 for v1 and v2;
37
+ [stability.md](stability.md#what-builds-the-same-bytes-where)). The reference environment for binaries is the
38
+ `--docker` build container (`docker/Dockerfile`, linux/amd64; base images by digest, release files by sha256, the
39
+ TypeSOL tarball by its release record and its npm dependencies by a lock whose every integrity `npm ci` checks), which
40
+ `typesol verify --docker` rebuilds in.
33
41
 
34
42
  ## What to check
35
43
 
@@ -54,6 +62,45 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
54
62
  Internal reviews, by the maintainers: none of them is an independent audit. Their findings and fixes are in the
55
63
  CHANGELOG.
56
64
 
65
+ ### 0.44.0 (2026-11-11)
66
+
67
+ A second internal review, of 0.44.0 as published, over the areas the review of 0.43.0 left out: the token,
68
+ Token-2022 and Metaplex CPI wrappers' emitters, the oracle readers, the Stake wrappers and signature introspection,
69
+ SBPF v1 and v2 builds, optional accounts, `Dup<…>`, and the heap and stack limits. It probed each with targeted
70
+ programs run in LiteSVM against the real token programs, and read the runtime header and the C generated for them.
71
+
72
+ Defects found, fixed in 0.44.1 (its CHANGELOG section, with a test for each):
73
+
74
+ - **A None authority in `mint.create`'s `transferFee` was 33 bytes.** Token-2022 reads a None COption as one byte,
75
+ so the 32 zero bytes after it became the next fields: a mint with a null config authority got no withdraw
76
+ authority and a fee of 0. The standalone `initializeTransferFeeConfig` was right.
77
+ - **A reference held across a resize through another slot.** The reference rule compared names only: with a
78
+ `Dup<…>` pair, a read-only and a writable account of one type, or a loaded struct naming one account, a reference
79
+ made through one slot outlived a push, pop or clear through the other and reached another record. Such programs are
80
+ now refused, as with one name.
81
+ - **Wrapper arguments out of source order.** Twelve token wrappers and the Stake wrappers read their signer seeds
82
+ before an earlier argument's code ran (a PDA other than the one the source names); amounts of `transfer` and the
83
+ like, and account text given to the metadata wrappers, were read after a later argument's code ran.
84
+ - **A 355-byte mint.** Extensions adding up to a Multisig's length made `mint.create` fail every time (Token-2022
85
+ sizes such a mint 357).
86
+ - **`updateExtraAccountMetas` growth.** The 10 KiB limit was counted from the current length, so after a
87
+ `resizeAccount` it could write past the runtime's room into the next account's record.
88
+ - **Heap Vec aliasing in the runtime.** `ts_hvec_reserve` wrote through a type the C aliasing rules let the optimizer
89
+ treat as unrelated to the generated code's (latent; no miscompile seen).
90
+ - **Oracle documentation.** What `pythPrice` and `switchboardValue` do not check was not said plainly; the readers are
91
+ unchanged (docs/security-model.md).
92
+
93
+ Examined and found sound: the other token and Token-2022 wrappers' optional keys (the standalone initializers'
94
+ COptions and Borsh Options, the OptionalNonZero keys of the pointer, hook, group and interest extensions); Token-2022
95
+ mints and accounts with extensions not taken for one another; several large token-metadata buffers in one
96
+ instruction; the Ed25519 signature readers against hostile offsets (into another instruction, a zero count, the same
97
+ bytes under another program id, a fake Instructions sysvar); optional accounts left out or passed unsigned; `Dup<…>`
98
+ pairs without references across a resize; the heap frame and stack limits; and checked arithmetic at every integer
99
+ width, built for SBPF v0, v1 and v2 from the same source, with the same results.
100
+
101
+ Not reviewed: the Metaplex wrappers for unusual argument shapes beyond reading them, the large ports (Marginfi,
102
+ Phoenix, Raydium, the Stake Pool) built for SBPF v1 and v2, and Windows.
103
+
57
104
  ### 0.43.0 (2026-11-11)
58
105
 
59
106
  An internal review of 0.43.0 as published. It probed the compiler's semantics with targeted programs (helpers,
package/docs/cli.md CHANGED
@@ -8,9 +8,9 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
8
8
  | --- | --- |
9
9
  | `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow]` | Create a project: `typesol.json`, `programs/<name>.ts`, `tests/<name>.test.ts` (LiteSVM), `package.json`, `tsconfig.json`, `programs/tsconfig.json` (with the editor plugin), `.vscode/settings.json` (the workspace TypeScript, so the plugin loads), `.gitignore`, the rules for AI coding agents (`AGENTS.md`, `CLAUDE.md` importing it, `.cursor/rules/typesol.mdc`) and the MCP server configuration (`.mcp.json`, `.cursor/mcp.json`; see [ai.md](ai.md)). `<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). Refuses to overwrite files. It warns, with the install commands, when the platform-tools that building needs are missing. |
10
10
  | `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name. |
11
- | `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
12
- | `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. |
13
- | `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
11
+ | `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, Docker (optional: only `--docker` builds need it; it says when they run emulated), its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
12
+ | `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--docker [--typesol-version <v>] [--release-record <file>]] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. `--docker` builds in the pinned container instead ([below](#build---docker-and-verify---docker)). |
13
+ | `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--docker …] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
14
14
  | `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }`, always (a missing file or unreadable `--files` input is a diagnostic too, exit 1 or 2); `--stdin` checks the text given on stdin as that file (its imports come from disk); `--files` reads `{ "files": { "<absolute path>": "<text>", … } }` from stdin and checks with those texts instead of the disk (an editor's unsaved buffers). |
15
15
  | `typesol clone [<address>…] [--url <rpc>] [--config <cli config>] [--out <dir>]` | Copy cluster accounts and programs for the tests (Anchor's `[test.validator.clone]`): each account to `<address>.json` (lamports, owner, data), each program to `<address>.so` (its ELF, from the ProgramData account for upgradeable programs), in `tests/accounts` (`"accounts"` in `typesol.json`) or `--out`. Without addresses it clones the project's `"clone"` list. `testProgram` loads that directory into its LiteSVM; commit it so the tests run offline. |
16
16
  | `typesol emit-c <file.ts> [--out <file.c>] [--profile]` | Print or write the generated C. |
@@ -20,7 +20,7 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
20
20
  | `typesol cpi <idl.json> [--out <file.ts>] [--prefix <name>] [--address <base58>]` | Generate TypeSOL helpers that call another program from its IDL. Unsupported instructions are listed on stderr. |
21
21
  | `typesol port <idl.json> [--out <file.ts>]` | A TypeSOL program skeleton from an Anchor IDL (0.30+/1.x), to port an Anchor program: account structs, enums, errors, events and one function per instruction with its accounts and arguments, each body `require(false, …NotPorted)` until written. Instruction discriminators (an explicit `@discriminator` when the name derives another), account names and error codes are kept, so existing clients keep working where the layouts match; notes on stderr list where they do not (Borsh `String`/`Option` in account data, a `Vec` that is not the last field). Error codes that skip ahead are kept with `@code`, and zero-copy types keep their IDL `repr`, `serialization` and field names (`@repr`, `@serialization`, `@idlName`). |
22
22
  | `typesol client <idl.json> [--out <file.ts>] [--address <base58>]`, `typesol client --address <program id> [--url <rpc>] [--config <cli config>] [--out <file.ts>]` | Generate a typed TypeScript client on `@solana/kit` from an Anchor IDL (0.30+/1.x or TypeSOL); the IDL is validated first, and what the client leaves out is printed as notes. Without a file, the IDL is read from the chain: the canonical Program Metadata IDL, else Anchor's IDL account. See [client.md](client.md). |
23
- | `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. On a mismatch it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given `.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a program on chain records none). |
23
+ | `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>] [--docker …]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. On a mismatch it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given `.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a program on chain records none). A host difference alone is named as such; it counts only between builds of 0.44.1 or earlier, whose programs with 128-bit or signed division linked platform-tools' compiler-builtins (laid out differently by each host package). `--docker` rebuilds in the pinned container and, on a match, prints what was verified ([below](#build---docker-and-verify---docker)). |
24
24
  | `typesol profile <logs.txt\|-> [--program <id>]` | Compute units per TypeScript line from the logs of a `--profile` build's transaction (exit 1 when the logs have no markers). |
25
25
  | `typesol help <command>` | Same as `typesol <command> --help`. |
26
26
  | `typesol --version` | Print the version. |
@@ -33,6 +33,33 @@ Builds (`build`, `deploy`, `verify`, `typesol/testing`) compare the active clang
33
33
  with (`TESTED_TOOLCHAIN` in `typesol/compiler`: Agave 3.1.10, platform-tools v1.52): another one gets one warning per
34
34
  process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `warn` is the default.
35
35
 
36
+ ## build --docker and verify --docker
37
+
38
+ `--docker` builds in a container made on your machine from `docker/Dockerfile` (shipped in the package): linux/amd64
39
+ on every machine (emulated on arm64), Node 24, the platform-tools v1.52 of Agave 3.1.10, and a TypeSOL version from
40
+ npm whose tarball is checked against `releases/<version>.json` (sha512 integrity, sha1 shasum, every file's sha256)
41
+ before it is installed, with its npm dependencies installed by `npm ci` from `docker/deps/<version>.lock.json` (every
42
+ package checked against the lock's integrity; the package's lock, or the version's own tarball's). Every input is
43
+ pinned by digest, checksum or integrity. The image is `typesol-build:<version>-<first 12
44
+ of the Dockerfile's sha256>`, built the first time it is needed (progress on stderr; about 750 MB of downloads) and
45
+ reused after. Builds run with `--network none`, the sources read-only (the project root, or a single file's
46
+ directory: imports from outside it are not there), the output directory writable, no capabilities, a read-only root
47
+ file system, as your uid and gid (root for a root caller, still without capabilities). The written files are the
48
+ ones `build` writes; `<name>.build.json` adds `container` (platform, Dockerfile sha256, base images, downloads, the
49
+ TypeSOL tarball's hashes and the commit its record names, where the release record came from and the record's sha256,
50
+ the dependency lock with its sha256, the local image id). An image is reused only when its labels carry this
51
+ record's integrity, shasum, commit and file list and this lock's sha256; an image of the same tag made from other
52
+ values is an error that names it (remove it to build from this record).
53
+
54
+ | Option | |
55
+ | --- | --- |
56
+ | `--typesol-version <v>` | The TypeSOL in the container. Default: this `typesol`'s version (in a project that installs another `typesol` than the one running, an error naming both); for `verify`, the version of the deployed build's manifest when one is known (`--manifest`, `<deployed>.build.json`, or the local build's whose binary hash is the deployed one's). |
57
+ | `--release-record <file>` | The record to check that version's tarball against. Default: the package's (a package ships the records of the releases before it: a record is written after its release is published), else `releases/<version>.json` fetched from the repository's main branch over HTTPS (said on stderr; where it came from and the sha256 of its bytes go into `container.typesol.record`), so that the npm tarball is checked against a second, independent source (as with a file given here; a record the package ships came from npm too). Offline, or for a version the repository has no record of, an error names this option. Versions before 0.43.0 have no record and are refused. |
58
+
59
+ Without Docker, with its daemon stopped or when the image build fails, `--docker` is an error and nothing is built;
60
+ it never falls back to the local toolchain. `TYPESOL_DOCKER_CPUS` and `TYPESOL_DOCKER_MEMORY` (e.g. `2`, `4g`) limit
61
+ the build container on a shared machine. Why one platform: [stability.md](stability.md#what-builds-the-same-bytes-where).
62
+
36
63
  ## typesol.json
37
64
 
38
65
  ```json
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 remaining account
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/mainnet.md CHANGED
@@ -9,11 +9,17 @@ You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the R
9
9
 
10
10
  **The toolchain you deploy with.** The binary is what the platform-tools' clang makes of the generated C, so the
11
11
  toolchain is part of what you trust. Deploy with the one TypeSOL is tested with (Agave 3.1.10, platform-tools v1.52;
12
- `typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another). Keep
12
+ `typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another). The host does not
13
+ matter from 0.45.0 on: with the same TypeSOL and toolchain a program builds to the same bytes on macOS arm64, Linux
14
+ arm64 and Linux x86_64 (measured over 76 programs for SBPF v0 and 14 for v1 and v2; up to 0.44.1 a program with
15
+ 128-bit or signed division did not, [stability.md](stability.md#what-builds-the-same-bytes-where)). For a program others should be able to verify, build
16
+ it with `--docker` (step 2) all the same: a pinned linux/amd64 container that anyone can rebuild, so the whole
17
+ environment is one recipe. Keep
13
18
  `target/my_app/my_app.build.json` with each deployment, next to the commit you deployed: it records the TypeSOL,
14
- TypeScript, clang and platform-tools versions and the host, and the deployed bytes' sha256. Step 6's `verify` matches
15
- only when it rebuilds with the same TypeSOL version and toolchain, and on a mismatch `--manifest` with that file shows
16
- what differs.
19
+ TypeScript, clang and platform-tools versions, the host, the container when there was one, and the deployed bytes'
20
+ sha256. Step 6's `verify` matches only when it rebuilds with the same TypeSOL version and toolchain (and, for a program
21
+ with 128-bit or signed division built with 0.44.1 or earlier, the same kind of host), and on a mismatch `--manifest`
22
+ with that file shows what differs.
17
23
 
18
24
  ## 1. Create and test
19
25
 
@@ -40,6 +46,54 @@ program's address, and records the address in `typesol.json`.
40
46
  **Back up `target/deploy/my_app-keypair.json` now.** It is not committed (`.gitignore`), and without it you cannot
41
47
  redeploy to that address.
42
48
 
49
+ ### A build others can verify
50
+
51
+ ```sh
52
+ npx --no-install typesol build --docker
53
+ ```
54
+
55
+ The same files, built inside a container instead of with your platform-tools. The container is made on your machine
56
+ from `docker/Dockerfile`, which ships in the package; every input is pinned: the Node and busybox base images by their
57
+ linux/amd64 digests, the Agave 3.1.10 and platform-tools v1.52 release files by sha256, the TypeSOL package (the
58
+ version your project uses) by its release record, `releases/<version>.json`: the npm tarball's sha512 integrity and
59
+ sha1 shasum and every file's sha256, checked before it is installed, and its npm dependencies (TypeScript, the
60
+ compiler's front end, among them) by that version's lock, `docker/deps/<version>.lock.json`, which `npm ci` installs
61
+ checking every package's integrity, with no install scripts. The lock of a version ships in the package of that
62
+ version (and in later ones); the locks of 0.43.0, 0.44.0 and 0.44.1, released before locks existed, were resolved
63
+ from the npm registry on 2026-11-12, so their integrity values are what the registry served then, not what an image
64
+ built at their release installed. The first `--docker` build of a TypeSOL version
65
+ builds the image (about 750 MB of downloads, a few minutes; Docker must be running, `typesol doctor` shows it); later
66
+ ones take seconds. The build runs with no network, the project mounted read-only, the output directory writable,
67
+ with no capabilities, as your uid and gid (root for a root caller). `my_app.build.json` then records the container:
68
+ the platform, the Dockerfile's sha256, the pinned base images and downloads, the TypeSOL tarball's hashes, the commit
69
+ its release record names, where the record came from (with the record's sha256), the dependency lock and its sha256,
70
+ and the local image id.
71
+
72
+ Deploy that `my_app.so` with the Solana CLI, `solana program deploy target/my_app/my_app.so --program-id
73
+ target/deploy/my_app-keypair.json --use-rpc` (with your `--url`). What replaces the container build: `typesol deploy`
74
+ (`--dry-run` included) and `typesol build` without `--docker`, which build again with your local platform-tools and
75
+ overwrite it; and `npm test` once the program's sources, SBPF version or address changed, which rebuilds it locally
76
+ and says so (`note: … held a --docker build that is out of date`). What does not: `npm test` while the sources are
77
+ the ones `my_app.build.json` records and the `.so` is the one it records, on any host: the tests then run the
78
+ container's binary. After a local build, `typesol build --docker` again before deploying. Commit the source, keep
79
+ `my_app.build.json`, and publish the commit and that file with the program id.
80
+
81
+ The TypeSOL inside the container is the version this `typesol` is, the one your project installs (`npx --no-install
82
+ typesol`); a global `typesol` of another version than the project's `node_modules/typesol` refuses rather than
83
+ guess. `--typesol-version <v>` picks another. Only versions with a release record can be installed (0.43.0 and later).
84
+ A package carries the records of the releases before it, because a release's record is written after it is
85
+ published; for a release the package does not record (the newest one, or a later one asked for), `--docker` fetches
86
+ `releases/<version>.json` from the repository's main branch
87
+ (`https://raw.githubusercontent.com/typesol-lang/typesol/main/releases/<version>.json`, unauthenticated HTTPS), prints
88
+ where it came from and its sha256, and records both in `my_app.build.json` (`container.typesol.record`). The check is
89
+ then two independent sources agreeing: the tarball npm serves must be the one the repository's record describes, so a
90
+ tampered package would have to be matched by a tampered repository. That holds for a fetched record and for a
91
+ `--release-record` file; for a version whose record ships in the running package, the record came from npm too (in
92
+ an earlier package), so the check is then against what npm served before. Offline, or when the repository has no
93
+ record for that version, it is an error that names `--release-record <file>`, which passes the record yourself (from
94
+ a checkout, `releases/<version>.json`). Between `npm publish` and the commit of the release's record the repository
95
+ answers HTTP 404: `--release-record` is the way then.
96
+
43
97
  ## 3. A wallet with SOL
44
98
 
45
99
  ```sh
@@ -93,8 +147,34 @@ npx --no-install typesol verify my_app
93
147
 
94
148
  `verify` rebuilds the program from `programs/my_app.ts`, reads the deployed one at the address in `typesol.json` from
95
149
  the cluster in your Solana CLI config, and compares the bytes. `match` means anyone with your source and the same
96
- TypeSOL version and toolchain gets exactly the program on chain. It also prints the upgrade authority and checks the IDL you
97
- published in step 5. Anyone can run it against your program with `--address <program id> --url mainnet-beta`.
150
+ TypeSOL version and toolchain gets exactly the program on chain (from 0.45.0 on, on any of the hosts measured: macOS arm64, Linux arm64, Linux x86_64; with 0.44.1 or earlier, a
151
+ program with 128-bit or signed division also needs the same kind of host). It also prints the upgrade authority and checks the IDL you published in step 5.
152
+
153
+ ### Verifying someone else's program
154
+
155
+ With the source at the deployed commit, the program id and, ideally, the deployer's `<name>.build.json`:
156
+
157
+ ```sh
158
+ git clone <repository> && cd <repository> && git checkout <commit>
159
+ npx --no-install typesol verify my_app --address <program id> --url mainnet-beta --docker --manifest my_app.build.json
160
+ ```
161
+
162
+ `--docker` rebuilds in the same container recipe, built on your machine from the Dockerfile and checked inputs. The
163
+ TypeSOL version is the deployed build's (from the manifest whose binary hash is the deployed bytes'), or
164
+ `--typesol-version <v>`; months later, the current `@typesol/cli` installs the old version in the container, checked
165
+ against its release record. On a match it prints what was verified: the program, the source directory and its git
166
+ commit (and whether it has uncommitted changes), the TypeSOL version and tarball, the commit its record names and
167
+ where the record came from, the dependency lock and its sha256, the clang and platform-tools, the container's
168
+ Dockerfile sha256, base images and downloads, and the command that repeats it (with every option given that changes
169
+ the result: `--address`, `--url`, `--config`, `--sbpf`, `--manifest`, `--release-record`). A program built with
170
+ 0.44.x on macOS or Linux arm64 that calls 128-bit or signed division does not match a `--docker` rebuild (those
171
+ versions' binaries depended on the host package; [troubleshooting](troubleshooting.md)). On a mismatch it shows the
172
+ toolchain of each side that is known, as without `--docker`. Exit codes: 0 match, 3 mismatch.
173
+
174
+ What this is not: the container is built locally from pinned inputs, not pulled from a published image, so the first
175
+ verification downloads the inputs and builds it. Its local image id can differ between machines; the Dockerfile's
176
+ sha256 and the pinned inputs are what to compare. The result is not registered with an external verified-build
177
+ registry: the evidence is the command and its output, which anyone can rerun.
98
178
 
99
179
  ## 7. Call it
100
180
 
@@ -10,7 +10,7 @@ auditors, [SECURITY.md](../SECURITY.md) how to report a problem.
10
10
  | --- | --- |
11
11
  | The program's author | the program's logic: what it allows, to whom, for how much |
12
12
  | TypeSOL (this repository) | that the binary does what the source and these guarantees say, and nothing an attacker can steer beyond it |
13
- | The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. The guarantees are tested with one platform-tools release (v1.52, from Agave 3.1.10); a build with another warns, or fails with `--toolchain-strict`, and `<name>.build.json` records which one built a binary |
13
+ | The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. The guarantees are tested with one platform-tools release (v1.52, from Agave 3.1.10); a build with another warns, or fails with `--toolchain-strict`, and `<name>.build.json` records which one built a binary and on which host. The compiler builtins (128-bit multiplication, division and shifts, signed 64-bit division) are TypeSOL's own (`runtime/typesol_builtins.c`), compiled with the program; nothing is linked from platform-tools' Rust libraries, whose layout differed by host package, so from 0.45.0 on the programs measured build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64 ([stability.md](stability.md#what-builds-the-same-bytes-where): 76 programs for SBPF v0, 14 for v1 and v2). `--docker` builds pin the whole environment in one linux/amd64 container whose inputs are checked by digest, checksum and integrity (base images, release files, the TypeSOL tarball and every npm dependency) |
14
14
  | The Solana runtime | account ownership and signer flags as passed, the loader's account serialization, CPI privilege rules, sysvars |
15
15
 
16
16
  Everything a transaction carries is attacker-controlled: the instruction data, which accounts are passed in which
@@ -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. A helper that can write gets its Pubkey, Option and
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), the payer is a `Mut<Signer>`, new bytes are
69
- zero and the new rent is paid; shrinking keeps the lamports in the account.
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). `invoke` marks an account writable or signer only when the parameter is `Mut` / `Signer` or the program
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 verification, feed and age (pass the exponent you scale by); the raw `update.*`
102
- fields are unchecked. `switchboardValue` needs the expected feed; set `minSamples`.
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.43.0 (above); its findings are fixed in
144
- 0.44.0. It was an internal review, not an independent audit, and it did not cover the Metaplex and
145
- token CPI wrappers' emitters, the oracles, SBPF v1/v2 builds or Windows. There has been no external audit: see
146
- [audit.md](audit.md).
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).