@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
package/docs/stability.md CHANGED
@@ -11,9 +11,12 @@ From 1.0 on, within a major version:
11
11
 
12
12
  - **Sources keep compiling.** A program that compiles with 1.x compiles with every later 1.y, to a program with the same
13
13
  account layouts, IDL, instruction and account discriminators and error codes. New releases add; they do not take away.
14
- - **Binaries are reproducible and only change for a reason.** With the same TypeSOL release and the toolchain it is
15
- tested with, a source builds to the same bytes. A release that changes the binary of a program that uses none of
16
- its new features says so, with the release manifest's diff (`binary-diff.txt`) as the evidence.
14
+ - **Binaries are reproducible and only change for a reason.** With the same TypeSOL release and the tested
15
+ toolchain, a source builds to the same bytes in the build container (`--docker`) as on the hosts measured: from
16
+ 0.45.0 on, macOS arm64, Linux arm64 and Linux x86_64, for the programs and SBPF versions listed
17
+ [below](#what-builds-the-same-bytes-where).
18
+ A release that changes the binary of a program that uses none of its new features says so, with the release
19
+ manifest's diff (`typesol-<version>-binary-diff.txt`) as the evidence.
17
20
  - **The checks stay.** No check a program gets from its parameter types (owner, discriminator, signer, writability,
18
21
  aliasing, checked arithmetic, constraints) is removed or weakened.
19
22
  - **The tools keep their interfaces**: `typesol build`, `test` (via `typesol/testing`), `check --json`, `deploy`,
@@ -46,10 +49,66 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
46
49
  - **A build says what made it.** `<name>.build.json` records the TypeSOL, TypeScript, clang and platform-tools versions,
47
50
  the host, the SBPF version and the sha256 of every source and of the binary. `typesol verify` uses it to say, on a
48
51
  mismatch, whether the toolchains differ. A program on chain records none of this: keep the file with the deployment.
52
+ - **A deployed program anyone can rebuild.** `typesol build --docker` builds in a container made from
53
+ `docker/Dockerfile` (in the package), whose inputs are all pinned: base images by digest, the Agave and
54
+ platform-tools release files by sha256, the TypeSOL tarball by its `releases/<version>.json`. `typesol verify
55
+ --docker` rebuilds there and says what it verified. The image is built locally from those inputs; no image is
56
+ published, and the result is not registered with any external verified-build registry
57
+ ([docs/mainnet.md](mainnet.md#6-verify)).
49
58
  - **Fixes come as patches of the latest minor.** From 0.44.0 on, a release that only fixes soundness or security
50
59
  defects is a patch (0.44.1, …) with no new language surface, and its notes carry the binary diff against the
51
60
  previous release ([SECURITY.md](../SECURITY.md#fix-releases)). Older minors are not maintained.
52
61
 
62
+ ## What builds the same bytes where
63
+
64
+ From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with this release's
65
+ compiler and platform-tools v1.52 on macOS arm64 (the platform-tools `osx-aarch64` package, native), Linux arm64 and
66
+ Linux x86_64 (the `linux-aarch64` and `linux-x86_64` packages, in containers; x86_64 is the `--docker` image): for
67
+ SBPF v0 (the default), the 76 programs of the sources (`scripts/release-manifest.ts`, every program under `examples/`
68
+ and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault, escrow, multisig
69
+ and the 10 below).
70
+
71
+ | What | Same on the three hosts? |
72
+ | --- | --- |
73
+ | The generated C and the IDL (all 76) | yes |
74
+ | The binary, SBPF v0 (all 76) | yes |
75
+ | The binary, SBPF v1 and v2 (the 14) | yes |
76
+ | The binary, SBPF v0, against 0.44.1 | 66 programs build to 0.44.1's bytes on each of the three; the 10 below build to new bytes, the same on the three |
77
+ | The binary, SBPF v1 and v2, against 0.44.1 (on macOS arm64) | v1: all 14 build to new bytes; v2: 9 (the 10 below but token-fundraiser) build to new bytes, the other 5 (counter, vault, escrow, multisig, token-fundraiser) to 0.44.1's |
78
+
79
+ The 10 are the programs that call 128-bit or signed 64-bit division (the Phoenix, Marginfi, Raydium AMM, CLMM and
80
+ CP-Swap, Jito priority-fee and Stake Pool ports, transfer-fee, token-fundraiser, token-swap). With 0.44.1 each of them
81
+ built to three different binaries on the three hosts (token-fundraiser: the two Linux ones agreed). The cause was one
82
+ library: platform-tools' SBF `compiler-builtins` Rust library (`libcompiler_builtins-<hash>.rlib`, a different file in
83
+ each host package). Its functions have the same instructions in the three packages (compared function by function for
84
+ SBPF v0, v1 and v2), but each package splits them into differently numbered archive members, so the linker placed the
85
+ ones a division pulls in (`__udivti3`, its shared `u128_div_rem`, `__ashlti3`, `__lshrti3`, …) in another order, and
86
+ the program's calls into them had other offsets. Programs that called at most `__multi3` linked one member and agreed.
87
+
88
+ TypeSOL now links none of that library: `runtime/typesol_builtins.c` defines every builtin the tested clang calls for
89
+ C integer code on SBF (`__multi3`, `__udivti3`, `__umodti3`, `__divti3`, `__modti3`, `__ashlti3`, `__lshrti3`, `__ashrti3`, `__divdi3`,
90
+ `__moddi3`) and is compiled with each program, by the same clang, and linked after it. Multiplication and shifts are
91
+ the instructions compiler-builtins has for them, so on SBPF v0 programs that use only those keep their bytes;
92
+ division is new C that costs no more compute units than compiler-builtins' on any input measured, and fewer on most
93
+ (`test/language/builtins.test.ts`). On SBPF v1, `__multi3` (128-bit multiplication, which checked 64-bit
94
+ multiplication uses too) is C as well, cheaper than compiler-builtins' there (175 against 177.5 compute units a call on average in that test),
95
+ so a v1 program that
96
+ multiplies that way builds to other bytes than with 0.44.1 (every one of the 14 measured does); SBPF v2 multiplies
97
+ with its own instructions and calls no `__multi3`, and its signed 64-bit division is an instruction too, which is
98
+ why token-fundraiser keeps its v2 bytes.
99
+ libc's `memcpy` and `memset` still come from platform-tools; the programs that link them build the same on the three
100
+ hosts. Nothing in the emitted C, the paths or the build directory reaches the binary.
101
+
102
+ The reference environment stays one platform, so that the whole environment is one recipe: the build container is
103
+ `linux/amd64` on every machine (emulated on arm64 hosts). CI checks on every change that a Linux x86_64 runner with
104
+ independently installed platform-tools builds the programs of `test/golden/binaries.json` (the 14 for SBPF v0, and
105
+ counter, escrow, Phoenix and Marginfi for v1 and v2) to the container's bytes; that is the same host package as the
106
+ container's, installed separately. The macOS workflow (on demand) runs the same check on macOS arm64, and anyone can
107
+ run it on another host, binary included. `<name>.build.json` records the host; `typesol verify` counts a host
108
+ difference between builds made before 0.45.0 (which linked compiler-builtins: a possible cause if the program uses
109
+ 128-bit or signed division), and between later builds only when one of the hosts is not among the three measured
110
+ (`host (not measured)`).
111
+
53
112
  ## Experimental
54
113
 
55
114
  Useful today, but may still change before 1.0 (each change listed in the CHANGELOG):
package/docs/testing.md CHANGED
@@ -47,12 +47,13 @@ From 0.39.0 on, each release's GitHub Release carries its manifest, `typesol-<ve
47
47
  hand after the npm publish (written by `scripts/release-manifest.ts` from the tag's sources; the scripts need Node 22.18
48
48
  or later):
49
49
 
50
- - the compiler and toolchain versions (clang, platform-tools, Node, TypeScript, the runtime header's sha256);
50
+ - the compiler and toolchain versions (clang, platform-tools, Node, TypeScript, the sha256 of the runtime header and,
51
+ from 0.45.0 on, of the runtime's compiler builtins);
51
52
  - the sha256 of the SBF binary, IDL and C that every program under `examples/` and `showcase/program-examples/` builds to;
52
53
  - the sha256 of the reference binaries the differential tests run against (`test/programs/`);
53
54
  - a hash of the test corpus.
54
55
 
55
- It also carries `binary-diff.txt`: the previous release's sources built by the previous package and by this one,
56
+ It also carries `typesol-<version>-binary-diff.txt` (older releases: `binary-diff.txt`): the previous release's sources built by the previous package and by this one,
56
57
  compared program by program. That is the check behind a changelog line such as "programs that use none of these compile to the
57
58
  same binaries". To redo it, or to compare other versions:
58
59
 
@@ -68,6 +69,41 @@ node scripts/release-manifest.ts --diff a.json b.json
68
69
  For 0.37.0 → 0.38.0 (run by hand before release manifests existed): all 67 programs of the 0.37.0 sources build to
69
70
  the same binary and IDL with both packages.
70
71
 
72
+ ### Across hosts
73
+
74
+ From 0.45.0 on the C, IDL and linked binary TypeSOL's builds produce are the same on the hosts measured
75
+ ([stability.md](stability.md#what-builds-the-same-bytes-where) has the measurement over 76 programs on macOS arm64,
76
+ Linux arm64 and Linux x86_64, and why 0.44.1 and earlier differed for programs with 128-bit or signed division). The
77
+ reference environment is the `--docker` build container (linux/amd64). `test/golden/binaries.json` holds what 14
78
+ programs build to there with the checkout's compiler: counter, vault, escrow, multisig, and the 10 that call 128-bit or
79
+ signed division (the Phoenix, Marginfi, Raydium AMM, CLMM and CP-Swap, Jito priority-fee and Stake Pool ports,
80
+ transfer-fee, token-fundraiser, token-swap), the ones whose binary used to depend on the host, for SBPF v0; and
81
+ counter, escrow, Phoenix and Marginfi for v1 and v2 (`<path>:v1`, `<path>:v2`). CI checks on every change that its
82
+ Linux x86_64 runner, with platform-tools installed by `cargo-build-sbf`, gives the same C, IDL and bytes (the same
83
+ host package as the container's, installed separately); the macOS workflow, run on demand, checks macOS arm64. On
84
+ another host the check is the same (binary included):
85
+
86
+ ```sh
87
+ node scripts/release-manifest.ts --check test/golden/binaries.json # what CI runs; the same result on macOS
88
+ node scripts/release-manifest.ts --docker --out test/golden/binaries.json --programs \
89
+ examples/counter.ts,examples/vault.ts,examples/escrow.ts,showcase/mainnet/multisig/multisig.ts,showcase/mainnet/phoenix/phoenix.ts,showcase/mainnet/marginfi/marginfi.ts,showcase/mainnet/raydium-amm/raydium_amm.ts,showcase/mainnet/raydium-clmm/raydium_clmm.ts,showcase/mainnet/raydium-cp-swap/raydium_cp_swap.ts,showcase/mainnet/jito-mev/priority_fee_distribution.ts,showcase/mainnet/spl-stake-pool/stake_pool.ts,showcase/program-examples/tokens/token-2022/transfer-fee.ts,showcase/program-examples/tokens/token-fundraiser.ts,showcase/program-examples/tokens/token-swap/lib.ts,examples/counter.ts:v1,examples/escrow.ts:v1,showcase/mainnet/phoenix/phoenix.ts:v1,showcase/mainnet/marginfi/marginfi.ts:v1,examples/counter.ts:v2,examples/escrow.ts:v2,showcase/mainnet/phoenix/phoenix.ts:v2,showcase/mainnet/marginfi/marginfi.ts:v2
90
+ ```
91
+
92
+ The second regenerates the file in the container (Docker, the checkout built with `pnpm build`, committed: `--docker`
93
+ refuses a tree with uncommitted changes, as the file records the commit; no network once the image exists), after a
94
+ change that alters what those programs compile to. `--check` says `STALE` when the C or IDL differ (regenerate) and
95
+ `DIFFERS` when the same C and IDL give other bytes (a toolchain problem); it fails on a reference that lists no
96
+ program, has an entry that did not build, or was made from uncommitted changes (`sources.dirty`).
97
+ `test/cli/release-manifest.test.ts` covers each outcome. The whole set, on more
98
+ hosts: build `scripts/release-manifest.ts` (every program) on each and compare with `--diff`, as for a release. The
99
+ compiler builtins themselves are tested by `test/language/builtins.test.ts`: each against a BigInt reference and
100
+ against platform-tools' compiler-builtins on edge cases and a seeded random set (`FUZZ_SEED`, `BUILTINS_RANDOM`), run as
101
+ SBF in LiteSVM for SBPF v0, v1 and v2, with each call's compute units compared to compiler-builtins' (never more).
102
+ With the default seed that is 84,741 to 91,289 calls per multiplication or division function and 59,506 per shift on
103
+ v0, and 41,506 to 73,289 on v1 and v2. The container itself is tested by `test/cli/docker.test.ts` with
104
+ `TYPESOL_DOCKER_TESTS=1` (off in CI: the first image build downloads about 750 MB); without Docker the same file
105
+ checks the Dockerfile's tarball and dependency-lock scripts on crafted inputs.
106
+
71
107
  ### The npm tarball
72
108
 
73
109
  From 0.43.0 on, `releases/<version>.json` in the repository describes the package on npm: the tag and its commit, the
@@ -90,3 +126,14 @@ or another Node (its zlib compresses the archive). The record also keeps the unc
90
126
  file's, which compare across those, and `--verify --tarball` says which files differ, if any. 0.42.0 and earlier
91
127
  were published from a maintainer's checkout without a record.
92
128
 
129
+ ### The build container's dependencies
130
+
131
+ The `--docker` image installs a TypeSOL version's npm dependencies with `npm ci` from `docker/deps/<version>.lock.json`
132
+ (an npm lockfile v3 of the package's runtime dependencies only), so every package is checked against the integrity
133
+ the lock records and nothing is resolved when the image is built. `node scripts/release-check.ts <version> --lock`
134
+ writes it from `package.json` (when it has that version) or from the published package's dependencies (`npm view`),
135
+ resolved from the registry at that moment; the release procedure runs it before the release commit, so the lock of
136
+ version N ships in package N, and the check of the tag refuses a release without it (or with one for other
137
+ dependencies) and installs it with `npm ci` in a temporary directory. The locks of 0.43.0, 0.44.0 and 0.44.1 were
138
+ made this way on 2026-11-12, after those releases: their integrity values are what the registry served that day.
139
+
@@ -18,6 +18,52 @@ version are used. Then the toolchain: verify prints the rebuild's clang and plat
18
18
  when a `<name>.build.json` describes the deployed bytes (`--manifest <file>`, one next to a given `.so`, or the local
19
19
  build's). A program on chain carries no such record, so keep the build manifest of every deployment.
20
20
 
21
+ **`--docker needs Docker: docker is not installed` / `the Docker daemon is not running`** — `build --docker` and
22
+ `verify --docker` run in a container: install Docker, or start Docker Desktop (or `sudo systemctl start docker`).
23
+ `typesol doctor` has a `docker` row. Nothing is built without it; drop `--docker` to build with your own platform-tools.
24
+
25
+ **`docker build of typesol-build:… failed`** — the first `--docker` build makes the image, which needs the network:
26
+ the base images from Docker Hub, the Agave and platform-tools release files from GitHub, the TypeSOL tarball from npm.
27
+ A `checksum` error means a downloaded file is not the one the Dockerfile pins (retry; if it persists, report it).
28
+ `typesol tarball check: integrity …` means the tarball npm served is not the one `releases/<version>.json` records:
29
+ do not use that version until it is explained. `typesol dependency lock: …` means the lock does not describe the
30
+ package's dependencies or names a package without a registry integrity; an `EINTEGRITY` error from `npm ci` means a
31
+ downloaded dependency is not the one the lock records: the same.
32
+
33
+ **`the local image typesol-build:… was not built from this release record and dependency lock`** — an image of that
34
+ tag exists, made from a record or lock with other values (it names them). Two records of one version disagree, so
35
+ find out which is right before going on; to build from the one given now, `docker image rm` the tag and run again.
36
+
37
+ **`no dependency lock for TypeSOL <version>`** — neither this package nor that version's tarball has
38
+ `docker/deps/<version>.lock.json`: use a later `@typesol/cli`, which ships the locks of the versions before it. On arm64 machines the image is linux/amd64 and runs emulated: Docker
39
+ Desktop provides the x86_64 emulation (QEMU or Rosetta); other Docker installs may need `binfmt` for amd64.
40
+
41
+ **`no release record for TypeSOL <version>`** / **`could not fetch the release record`** — the container installs only
42
+ versions whose tarball has a record: the package's own, or `releases/<version>.json` on the repository's main branch,
43
+ which `--docker` fetches for a release newer than the package. Offline (or behind a proxy that blocks
44
+ raw.githubusercontent.com), pass the record yourself with `--release-record releases/<version>.json` from a checkout,
45
+ or choose a version the package records with `--typesol-version`. HTTP 404 means the repository has no record for that
46
+ version: check that it is a released version. 0.42.0 and earlier have no record.
47
+
48
+ **`this project installs typesol X …, but this is typesol Y`** — a `typesol` other than the project's ran `--docker`.
49
+ Run the project's own (`npx --no-install typesol …`), or say which version to use with `--typesol-version`.
50
+
51
+ **`the container build failed … the container sees only <dir>`** — the compiler's error is printed above it. The
52
+ container mounts only the project root (or a single file's directory): an import from outside it is missing there.
53
+
54
+ **`verify` says `differs host`** — the same TypeSOL (0.44.1 or earlier) and toolchain built the two sides on
55
+ different hosts. That may be the cause if the program has 128-bit or signed division: those versions linked
56
+ platform-tools' compiler-builtins, which each host package lays out differently. Rebuild on the deployed side's kind
57
+ of host (or with `--docker`, if the deployed build was one). From 0.45.0 on the host is not a difference between
58
+ macOS arm64, Linux arm64 and Linux x86_64 (the hosts measured); `differs host (not measured)` means one side was
59
+ built on another host.
60
+
61
+ **A 0.44.x program with division, deployed from macOS or Linux arm64, does not match `verify --docker`** — 0.44.0 and
62
+ 0.44.1 linked platform-tools' compiler-builtins, so a program that calls 128-bit or signed division built to other
63
+ bytes on each host package; the container is linux/amd64 and gives the Linux x86_64 bytes. What verifies it is a
64
+ 0.44.x install (the version in its `.build.json`) on the same kind of host as the one that built it, without
65
+ `--docker`: `npx @typesol/cli@0.44.1 verify …` on macOS arm64 for a build made there.
66
+
21
67
  **Windows** — not tested; use WSL2 with the Linux Agave CLI.
22
68
 
23
69
  **Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`** — use Node.js 22.12 or newer.