@typesol/cli 0.43.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +123 -0
- package/NOTICE +71 -0
- package/README.md +25 -11
- package/SECURITY.md +32 -5
- package/dist/ai.d.ts +1 -1
- package/dist/ai.js +5 -5
- package/dist/cli.js +196 -72
- package/dist/compiler/analyze.js +4 -0
- package/dist/compiler/emit/alias.d.ts +1 -1
- package/dist/compiler/emit/alias.js +10 -4
- package/dist/compiler/emit/base.d.ts +3 -1
- package/dist/compiler/emit/base.js +20 -3
- package/dist/compiler/emit/borsh.js +11 -5
- package/dist/compiler/emit/calls.d.ts +13 -0
- package/dist/compiler/emit/calls.js +91 -8
- package/dist/compiler/emit/cpi-core.d.ts +3 -1
- package/dist/compiler/emit/cpi-core.js +35 -7
- package/dist/compiler/emit/create.js +3 -0
- package/dist/compiler/emit/expressions.js +6 -1
- package/dist/compiler/emit/function.js +10 -0
- package/dist/compiler/emit/shared.d.ts +17 -0
- package/dist/compiler/emit/shared.js +36 -3
- package/dist/compiler/emit/statements.js +17 -4
- package/dist/compiler/emit/storage.d.ts +2 -0
- package/dist/compiler/emit/storage.js +16 -8
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +40 -3
- package/dist/compiler/toolchain.d.ts +41 -1
- package/dist/compiler/toolchain.js +102 -3
- package/dist/testing-stake.d.ts +2 -1
- package/dist/testing-stake.js +2 -1
- package/dist/testing.js +6 -4
- package/dist/tools/clientgen.d.ts +15 -0
- package/dist/tools/clientgen.js +173 -7
- package/dist/tools/cpigen.d.ts +0 -15
- package/dist/tools/cpigen.js +19 -8
- package/dist/tools/doctor.d.ts +17 -2
- package/dist/tools/doctor.js +64 -4
- package/dist/tools/portgen.js +43 -18
- package/dist/workspace.d.ts +20 -0
- package/dist/workspace.js +173 -6
- package/docs/ai.md +10 -5
- package/docs/architecture.md +1 -1
- package/docs/audit.md +63 -17
- package/docs/case-study-escrow.md +1 -1
- package/docs/case-study-phoenix.md +10 -10
- package/docs/case-study-raydium-amm.md +3 -3
- package/docs/case-study-spl-stake-pool.md +5 -5
- package/docs/cli.md +17 -8
- package/docs/client.md +11 -3
- package/docs/errors.md +1 -1
- package/docs/language.md +10 -5
- package/docs/mainnet.md +21 -10
- package/docs/migrate-from-anchor.md +2 -1
- package/docs/runtime.md +11 -1
- package/docs/security-model.md +38 -6
- package/docs/stability.md +21 -2
- package/docs/testing.md +25 -0
- package/docs/troubleshooting.md +12 -0
- package/llms-full.txt +168 -52
- package/llms.txt +1 -1
- package/package.json +3 -1
- package/runtime/typesol_rt.h +22 -13
- package/test/programs/LICENSE-Apache-2.0.txt +201 -0
package/docs/security-model.md
CHANGED
|
@@ -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 |
|
|
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 |
|
|
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
|
|
@@ -48,7 +48,8 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
48
48
|
7. **Bounds.** Every index into an array, Vec, FixedVec or remaining-account list is checked (5104); a
|
|
49
49
|
growable Vec's stored length is checked against the account's size before it is used (3003).
|
|
50
50
|
8. **Account creation.** `create` / `createIfNeeded` is a top-level statement, and the account cannot be read or
|
|
51
|
-
written before it (compile error). Creation refuses an account that already exists (
|
|
51
|
+
written before it (compile error). Creation refuses an account that already exists (the System Program's
|
|
52
|
+
own error, custom 0; `initAccount<T>` over an account already holding a T is 3000), and an address someone
|
|
52
53
|
pre-funded still gets created. `createIfNeeded` on an existing account re-derives the canonical PDA and checks
|
|
53
54
|
owner, discriminator and size (token accounts: mint and owner; mints: decimals, authorities and the extensions it
|
|
54
55
|
names). A `Migrate<From, To>` account is checked as an existing `From`; `migrate(…)` is a top-level statement every
|
|
@@ -56,14 +57,18 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
56
57
|
errors).
|
|
57
58
|
9. **Writes through references.** A place is never written after the code that computes its value may have moved it:
|
|
58
59
|
replacing or resizing what a live reference points into is a compile error, as is writing a Vec element with a
|
|
59
|
-
right side that may resize the Vec.
|
|
60
|
+
right side that may resize the Vec. A helper given a writable struct account may replace anything in it, however
|
|
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
|
|
63
|
+
string arguments as they were at the call (a copy unless nothing it is given reaches them), and a closed account
|
|
64
|
+
is not used after `close()` (compile error).
|
|
60
65
|
10. **Remaining accounts.** Writing one (`.lamports`, `loadAccountMut`) checks it is writable (3006) and not another
|
|
61
66
|
account of the instruction (2040); `loadAccountMut` loads a given account once per instruction (2040);
|
|
62
67
|
`loadAccount<T>` checks owner, discriminator and size, and validates the data as instruction arguments are.
|
|
63
68
|
11. **Growth.** An account grows by at most 10 KiB per instruction (3016), the payer is a `Mut<Signer>`, new bytes are
|
|
64
69
|
zero and the new rent is paid; shrinking keeps the lamports in the account.
|
|
65
70
|
12. **CPIs.** A program signs only for its own PDAs (the runtime enforces it; the seeds are those written in the
|
|
66
|
-
source). `invoke` marks an account writable or signer only when the parameter is `Mut` / `Signer` or the program
|
|
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
|
|
67
72
|
signs for it; remaining accounts keep the flags they were passed with, or are checked for the role requested.
|
|
68
73
|
`invokeInstruction` is the exception by design: its program, account flags and data come from values (stored in
|
|
69
74
|
account data or passed in), so the compiler cannot check them; the runtime does, refusing any account the
|
|
@@ -107,8 +112,35 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
107
112
|
- Arithmetic overflow returns an error code (5100) in every build; Anchor aborts the program, and only when
|
|
108
113
|
overflow checks are enabled.
|
|
109
114
|
|
|
115
|
+
## Review of 0.43.0 (2026-11-11)
|
|
116
|
+
|
|
117
|
+
An internal review of 0.43.0 found that some of the guarantees above did not hold in every case; the defects are
|
|
118
|
+
listed in [audit.md](audit.md#0430-2026-11-11) and fixed in 0.44.0. Programs built with 0.43.0 or
|
|
119
|
+
earlier should be rebuilt with it and redeployed: the fixes change the binary of programs that have a helper
|
|
120
|
+
taking a Pubkey, Option, string or u256, exposed or not (35 of the 76 programs of the 0.43.0 sources build to the same
|
|
121
|
+
binary, 41 to another).
|
|
122
|
+
|
|
123
|
+
The defect that can break an authorization check is the first: a Pubkey, Option, string or u256 argument of a
|
|
124
|
+
helper was not a copy. A program was exposed where all of these hold:
|
|
125
|
+
|
|
126
|
+
- a helper takes a parameter of one of those types and also an account it writes (or remaining accounts, or an
|
|
127
|
+
`Inout` place);
|
|
128
|
+
- a call passes that parameter a field of the same account (`rotate(v, v.admin, caller)`), or a value stored in it;
|
|
129
|
+
- the helper reads the parameter after writing the field (`v.admin = v.pending`, then a check on `admin`): it read
|
|
130
|
+
the new value;
|
|
131
|
+
- the helper was not inlined. A `/** @noinline */` helper never is; for the others it was clang's choice, which the
|
|
132
|
+
source does not show, so count every such call as exposed.
|
|
133
|
+
|
|
134
|
+
Each of the other defects needs the construct it names: a seed list bound to a name, given to a helper or written
|
|
135
|
+
beside an argument with side effects; a reference held across a helper that is given an account-group field or a
|
|
136
|
+
loaded account; Borsh input with an Option of a struct that holds an Option (a bounded read past the input, no
|
|
137
|
+
write); a closure or callback that changes a local read before it; a string viewing an `Inout` place; `close()` into
|
|
138
|
+
the account itself, `Dup<…>` on a closed account, or an account used after `close()`. A program without them was not
|
|
139
|
+
exposed to them.
|
|
140
|
+
|
|
110
141
|
## Status
|
|
111
142
|
|
|
112
|
-
The compiler and runtime have had internal security reviews
|
|
113
|
-
|
|
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
|
|
114
146
|
[audit.md](audit.md).
|
package/docs/stability.md
CHANGED
|
@@ -11,8 +11,9 @@ 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.**
|
|
15
|
-
|
|
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.
|
|
16
17
|
- **The checks stay.** No check a program gets from its parameter types (owner, discriminator, signer, writability,
|
|
17
18
|
aliasing, checked arithmetic, constraints) is removed or weakened.
|
|
18
19
|
- **The tools keep their interfaces**: `typesol build`, `test` (via `typesol/testing`), `check --json`, `deploy`,
|
|
@@ -31,6 +32,24 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
|
|
|
31
32
|
- CPIs: System, SPL Token, Token-2022, Associated Token, Memo, generic `invoke` with PDA signing.
|
|
32
33
|
- Layouts: account data (Anchor's discriminator and fixed or `@layout borsh` layout), the IDL, the client.
|
|
33
34
|
|
|
35
|
+
## What a release gives you now
|
|
36
|
+
|
|
37
|
+
- **The npm package is the one that was checked.** From 0.43.0 on, `releases/<version>.json` in the repository holds
|
|
38
|
+
the published tarball's shasum and integrity and every file's sha256, packed from a clean export of the release tag
|
|
39
|
+
after install, build and lint. `npm pack` is reproducible here, so anyone can pack the tag again and compare, or
|
|
40
|
+
compare the registry with `node scripts/release-check.ts <version> --verify --registry`
|
|
41
|
+
([docs/testing.md](testing.md#the-npm-tarball)).
|
|
42
|
+
- **The tests cover one toolchain.** Each release declares the Agave and platform-tools it is tested with
|
|
43
|
+
(`TESTED_TOOLCHAIN`, exported from `typesol/compiler`; Agave 3.1.10 and platform-tools v1.52 now). A binary built with
|
|
44
|
+
another clang is outside what the tests cover: `typesol build` and `deploy` warn once, `--toolchain-strict` (or
|
|
45
|
+
`TYPESOL_TOOLCHAIN=strict`) refuses it, and `typesol doctor` shows which one is active.
|
|
46
|
+
- **A build says what made it.** `<name>.build.json` records the TypeSOL, TypeScript, clang and platform-tools versions,
|
|
47
|
+
the host, the SBPF version and the sha256 of every source and of the binary. `typesol verify` uses it to say, on a
|
|
48
|
+
mismatch, whether the toolchains differ. A program on chain records none of this: keep the file with the deployment.
|
|
49
|
+
- **Fixes come as patches of the latest minor.** From 0.44.0 on, a release that only fixes soundness or security
|
|
50
|
+
defects is a patch (0.44.1, …) with no new language surface, and its notes carry the binary diff against the
|
|
51
|
+
previous release ([SECURITY.md](../SECURITY.md#fix-releases)). Older minors are not maintained.
|
|
52
|
+
|
|
34
53
|
## Experimental
|
|
35
54
|
|
|
36
55
|
Useful today, but may still change before 1.0 (each change listed in the CHANGELOG):
|
package/docs/testing.md
CHANGED
|
@@ -13,6 +13,9 @@ run prints its seed; reproduce with `FUZZ_SEED=<n>`, widen with `FUZZ_RUNS` / `F
|
|
|
13
13
|
| `showcase/test/fuzz-jito.test.ts` | Jito's tip payment, tip distribution and priority fee distribution as deployed on mainnet | random sequences of tips, receiver and builder changes, accounts opened over epochs, roots uploaded, Merkle claims (wrong amounts, proofs and signers among them), closes and config changes, with at most one injected fault per transaction: the same outcome, account bytes, events and log lines as the original after every step; keys, amounts and choices all come from the seed |
|
|
14
14
|
| `showcase/test/fuzz-marginfi.test.ts` | Marginfi v2 as deployed on mainnet | random sequences of bank creation (random weights, curves and fees, most valid, some broken one way), configuration (operational states, curves, liquidation fees, the circuit breaker's switch and settings, frozen banks), accruals over balances written into both at every scale and clock jumps up to a year, limits, pauses, wrong signers: the same outcome, account bytes and events as the original after every step; inputs the original panics on (a negative fee rate) must fail in the port too |
|
|
15
15
|
| the `fuzz:` case of `showcase/test/raydium-clmm.test.ts` | Raydium CLMM as deployed on mainnet | random swaps (both ways, exact in and out, price limits, thresholds), positions opened at random ranges, and liquidity added and taken out (over the position's own, under slippage limits): the same outcome, account bytes and events as the original after every step; choices and amounts come from the seed (`CLMM_FUZZ_STEPS` lengthens it), keys are fresh each run; each transaction may use 1.4M compute units, so a swap the original needs more than 200,000 for still runs to its end |
|
|
16
|
+
| `showcase/test/spl-stake-pool-fuzz.test.ts` | SPL Stake Pool as deployed on mainnet | a random walk over many epochs: validators added and removed, deposits, withdrawals, stake increased and decreased, rewards and tips at each epoch boundary, some steps wrong on purpose; every step gives the same outcome, logs and account bytes as the original, and every account the walk knows is compared after each epoch and every 25 steps; choices and amounts come from the seed (`STAKE_POOL_FUZZ_STEPS` lengthens it, `STAKE_POOL_FUZZ_SWEEP=1` compares every account after each step), keys are fresh each run |
|
|
17
|
+
| `showcase/test/phoenix-fuzz.test.ts` | Phoenix v1 as deployed on mainnet, and a balance model | a random walk over two order books (512/128 and 4096/8321, each started nearly full): every kind of order, reductions and cancels, seats, evictions, fee collection, status changes, a moving clock and invalid packets; every step gives the same outcome, logs, inner instructions, return data and account bytes as the original, and after each step every trader's locked and free lots plus the uncollected fees equal what the vaults hold; choices and every key come from the seed, CI walks seeds 1, 2 and 3 (300 steps on each market) and requires minimum counts of fills, evictions, expiries and fees (`PHOENIX_FUZZ_STEPS` changes the length) |
|
|
18
|
+
| `test/verification/rbtree-trace.test.ts` | lib-sokoban 0.3.0 itself (`test/verification/rbtree/oracle`, a Rust program that records traces) | the built-in RedBlackTree replays 21,650 recorded operations (capacities 1 to 4096; u64 keys, Phoenix's order ids with their comparator, Pubkey keys), one a transaction: after each the tree's bytes (root, allocator, every node, freed ones included) hash as the crate's did and the operation returns what the crate's returned; a second pass replays every `remove(key)` as `removeAt(addrOf(key))`; `RBTREE_TRACES=<file>` replays another set |
|
|
16
19
|
| `test/verification/differential.test.ts` | Anchor twins in `test/anchor-twins` | identical transactions to TypeSOL and Anchor programs: same outcomes, same account contents, same wallet and token balances after every step |
|
|
17
20
|
| `showcase/test/porting/ports-*.test.ts` | the Anchor programs of solana-developers/program-examples and their tests | TypeSOL rewrites under `showcase/program-examples/` run the originals' flows and failure paths with the same outcomes, error codes and balances ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)) |
|
|
18
21
|
|
|
@@ -65,3 +68,25 @@ node scripts/release-manifest.ts --diff a.json b.json
|
|
|
65
68
|
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
|
|
66
69
|
the same binary and IDL with both packages.
|
|
67
70
|
|
|
71
|
+
### The npm tarball
|
|
72
|
+
|
|
73
|
+
From 0.43.0 on, `releases/<version>.json` in the repository describes the package on npm: the tag and its commit, the
|
|
74
|
+
tarball's size, sha1 shasum and sha512 integrity (the registry's `dist.shasum` and `dist.integrity`), and the sha256
|
|
75
|
+
of every file in it. `scripts/release-check.ts` writes it from a clean export of the tag (`git archive`: install with
|
|
76
|
+
the lockfile, build, lint, check the version and the CHANGELOG section, `npm pack`), and the maintainer publishes the
|
|
77
|
+
tarball it produced, by hand ([CONTRIBUTING.md](https://github.com/typesol-lang/typesol/blob/main/CONTRIBUTING.md#releasing)). To check a release yourself:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
node scripts/release-check.ts 0.43.0 # pack the tag again: git diff releases/ shows what moved
|
|
81
|
+
node scripts/release-check.ts 0.43.0 --verify --registry # the registry's hashes against the record
|
|
82
|
+
npm pack @typesol/cli@0.43.0 --pack-destination /tmp/pub
|
|
83
|
+
node scripts/release-check.ts 0.43.0 --verify --tarball /tmp/pub/typesol-cli-0.43.0.tgz # file by file
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
`npm pack` is reproducible here: two clean exports of v0.43.0 packed to the same bytes, and to the published tarball
|
|
87
|
+
(shasum `10c2883bf3a01fcb16a86c1dbbbb696e1e962b2c`, with Node 25.9.0, pnpm 11.9.0 and npm 11.12.1). npm writes every
|
|
88
|
+
entry with a fixed date and mode, in a fixed order; what can still change the bytes is another npm (its tar headers)
|
|
89
|
+
or another Node (its zlib compresses the archive). The record also keeps the uncompressed archive's sha256 and each
|
|
90
|
+
file's, which compare across those, and `--verify --tarball` says which files differ, if any. 0.42.0 and earlier
|
|
91
|
+
were published from a maintainer's checkout without a record.
|
|
92
|
+
|
package/docs/troubleshooting.md
CHANGED
|
@@ -6,6 +6,18 @@ and next to `cargo-build-sbf` on PATH; set `TYPESOL_SBF_SDK` to a `platform-tool
|
|
|
6
6
|
|
|
7
7
|
**"platform-tools missing" / "no SBPF v2 libraries"** — `cargo-build-sbf --force-tools-install`.
|
|
8
8
|
|
|
9
|
+
**"warning: this build uses clang … TypeSOL is tested with clang 20.1.7-rust-dev …"** — the active platform-tools are
|
|
10
|
+
not the ones the release is tested with (platform-tools v1.52, from Agave 3.1.10). The build goes on, but the C TypeSOL
|
|
11
|
+
generates is only checked against that clang: another one can compile it to other bytes, and what the C relies on
|
|
12
|
+
includes backend details (how the SBF backend passes struct arguments was behind a defect fixed after 0.43.0). Install the tested ones with
|
|
13
|
+
`cargo-build-sbf --install-only --force-tools-install --tools-version v1.52`; `typesol doctor` shows which are active.
|
|
14
|
+
In CI, `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) turns the warning into an error.
|
|
15
|
+
|
|
16
|
+
**`typesol verify` says MISMATCH** — first make sure the same sources (imports included), TypeSOL version and SBPF
|
|
17
|
+
version are used. Then the toolchain: verify prints the rebuild's clang and platform-tools, and the deployed build's
|
|
18
|
+
when a `<name>.build.json` describes the deployed bytes (`--manifest <file>`, one next to a given `.so`, or the local
|
|
19
|
+
build's). A program on chain carries no such record, so keep the build manifest of every deployment.
|
|
20
|
+
|
|
9
21
|
**Windows** — not tested; use WSL2 with the Linux Agave CLI.
|
|
10
22
|
|
|
11
23
|
**Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`** — use Node.js 22.12 or newer.
|