@typesol/cli 0.43.0 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +173 -0
  2. package/NOTICE +71 -0
  3. package/README.md +25 -11
  4. package/SECURITY.md +32 -5
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.js +5 -5
  7. package/dist/cli.js +196 -72
  8. package/dist/compiler/analyze.js +4 -0
  9. package/dist/compiler/emit/alias.d.ts +16 -2
  10. package/dist/compiler/emit/alias.js +70 -6
  11. package/dist/compiler/emit/base.d.ts +3 -1
  12. package/dist/compiler/emit/base.js +20 -3
  13. package/dist/compiler/emit/borsh.js +11 -5
  14. package/dist/compiler/emit/calls.d.ts +13 -0
  15. package/dist/compiler/emit/calls.js +105 -14
  16. package/dist/compiler/emit/cpi-core.d.ts +9 -1
  17. package/dist/compiler/emit/cpi-core.js +51 -10
  18. package/dist/compiler/emit/create.js +22 -11
  19. package/dist/compiler/emit/expressions.js +6 -1
  20. package/dist/compiler/emit/function.js +15 -5
  21. package/dist/compiler/emit/metaplex.js +17 -4
  22. package/dist/compiler/emit/shared.d.ts +17 -0
  23. package/dist/compiler/emit/shared.js +36 -3
  24. package/dist/compiler/emit/statements.js +17 -4
  25. package/dist/compiler/emit/storage.d.ts +2 -0
  26. package/dist/compiler/emit/storage.js +16 -8
  27. package/dist/compiler/emit/token.js +64 -39
  28. package/dist/compiler/index.d.ts +15 -1
  29. package/dist/compiler/index.js +40 -3
  30. package/dist/compiler/toolchain.d.ts +41 -1
  31. package/dist/compiler/toolchain.js +102 -3
  32. package/dist/testing-stake.d.ts +2 -1
  33. package/dist/testing-stake.js +2 -1
  34. package/dist/testing.js +6 -4
  35. package/dist/tools/clientgen.d.ts +15 -0
  36. package/dist/tools/clientgen.js +173 -7
  37. package/dist/tools/cpigen.d.ts +0 -15
  38. package/dist/tools/cpigen.js +19 -8
  39. package/dist/tools/doctor.d.ts +17 -2
  40. package/dist/tools/doctor.js +64 -4
  41. package/dist/tools/portgen.js +43 -18
  42. package/dist/workspace.d.ts +20 -0
  43. package/dist/workspace.js +173 -6
  44. package/docs/ai.md +10 -5
  45. package/docs/architecture.md +1 -1
  46. package/docs/audit.md +103 -18
  47. package/docs/case-study-escrow.md +1 -1
  48. package/docs/case-study-phoenix.md +10 -10
  49. package/docs/case-study-raydium-amm.md +3 -3
  50. package/docs/case-study-spl-stake-pool.md +5 -5
  51. package/docs/cli.md +17 -8
  52. package/docs/client.md +11 -3
  53. package/docs/errors.md +2 -2
  54. package/docs/language.md +16 -9
  55. package/docs/mainnet.md +21 -10
  56. package/docs/migrate-from-anchor.md +2 -1
  57. package/docs/runtime.md +11 -1
  58. package/docs/security-model.md +79 -12
  59. package/docs/stability.md +21 -2
  60. package/docs/testing.md +25 -0
  61. package/docs/troubleshooting.md +12 -0
  62. package/llms-full.txt +216 -63
  63. package/llms.txt +1 -1
  64. package/package.json +3 -1
  65. package/runtime/typesol_rt.h +30 -18
  66. package/test/programs/LICENSE-Apache-2.0.txt +201 -0
package/docs/mainnet.md CHANGED
@@ -2,9 +2,18 @@
2
2
 
3
3
  From an empty directory to a program on Solana mainnet-beta: create, test, deploy, publish the IDL, then check that
4
4
  the deployed binary is the one your source builds. The program here is the counter that `typesol init` creates
5
- (13.2 KiB); any TypeSOL project works the same way.
5
+ (11,400 bytes, 11.1 KiB, built with TypeSOL 0.43.0 and platform-tools clang 20.1.7 for SBPF v0; other versions differ
6
+ slightly); any TypeSOL project works the same way.
6
7
 
7
- You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the README's Requirements).
8
+ You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the README's Quick start).
9
+
10
+ **The toolchain you deploy with.** The binary is what the platform-tools' clang makes of the generated C, so the
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
13
+ `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.
8
17
 
9
18
  ## 1. Create and test
10
19
 
@@ -21,7 +30,7 @@ Write your program in `programs/my_app.ts` and keep the tests passing before you
21
30
  ## 2. Build
22
31
 
23
32
  ```sh
24
- npx typesol build
33
+ npx --no-install typesol build
25
34
  ```
26
35
 
27
36
  This writes `target/my_app/`: the program (`my_app.so`), its Anchor IDL (`my_app.json`), a TypeScript client
@@ -46,8 +55,10 @@ ever close the program:
46
55
  solana rent $(wc -c < target/my_app/my_app.so)
47
56
  ```
48
57
 
49
- The counter needs 0.069 SOL of rent. During the deploy the program is first written to a buffer account that holds
50
- the same amount again; it is returned when the deploy finishes. Fund about twice the rent plus 0.01 SOL for fees.
58
+ For the counter that is about 0.080 SOL (rent is (128 + size) × 6,960 lamports at the current rate: 80,234,880
59
+ lamports for 11,400 bytes; the program data account holds 45 bytes more). During the deploy the program is first
60
+ written to a buffer account that holds the same amount again; it is returned when the deploy finishes. Fund about
61
+ twice the rent plus 0.01 SOL for fees: 0.17 SOL for the counter.
51
62
 
52
63
  The public mainnet RPC is rate-limited; for deploys, set `--url` (or `solana config set --url`) to your RPC
53
64
  provider's endpoint.
@@ -55,8 +66,8 @@ provider's endpoint.
55
66
  ## 4. Deploy
56
67
 
57
68
  ```sh
58
- npx typesol deploy --dry-run # builds and prints the solana command it will run
59
- npx typesol deploy
69
+ npx --no-install typesol deploy --dry-run # builds and prints the solana command it will run
70
+ npx --no-install typesol deploy
60
71
  ```
61
72
 
62
73
  It runs `solana program deploy` at the address in `target/deploy/my_app-keypair.json`, with your wallet as payer and
@@ -68,7 +79,7 @@ with `solana program close <buffer address>`, or list yours with `solana program
68
79
  ## 5. Publish the IDL
69
80
 
70
81
  ```sh
71
- npx typesol idl publish
82
+ npx --no-install typesol idl publish
72
83
  ```
73
84
 
74
85
  It writes the IDL to the Program Metadata program, signed by the upgrade authority, where Anchor clients and
@@ -77,12 +88,12 @@ explorers look for it. It costs a few thousandths of a SOL of rent.
77
88
  ## 6. Verify
78
89
 
79
90
  ```sh
80
- npx typesol verify my_app
91
+ npx --no-install typesol verify my_app
81
92
  ```
82
93
 
83
94
  `verify` rebuilds the program from `programs/my_app.ts`, reads the deployed one at the address in `typesol.json` from
84
95
  the cluster in your Solana CLI config, and compares the bytes. `match` means anyone with your source and the same
85
- TypeSOL version gets exactly the program on chain. It also prints the upgrade authority and checks the IDL you
96
+ TypeSOL version and toolchain gets exactly the program on chain. It also prints the upgrade authority and checks the IDL you
86
97
  published in step 5. Anyone can run it against your program with `--address <program id> --url mainnet-beta`.
87
98
 
88
99
  ## 7. Call it
@@ -10,8 +10,9 @@ original side by side, the checks run against it and its cost, see [Case study:
10
10
  ```sh
11
11
  anchor build # in the Anchor project: target/idl/my_program.json
12
12
  npx @typesol/cli init my-program && cd my-program
13
+ npm install # the project's own TypeSOL, run below as npx --no-install typesol
13
14
  rm programs/my_program.ts tests/my_program.test.ts # the counter template's program and test
14
- npx typesol port ../anchor/target/idl/my_program.json --out programs/my_program.ts
15
+ npx --no-install typesol port ../anchor/target/idl/my_program.json --out programs/my_program.ts
15
16
  ```
16
17
 
17
18
  `typesol port` writes the account structs, enums, errors and one function per instruction with its accounts and
package/docs/runtime.md CHANGED
@@ -12,7 +12,17 @@ This page is for people changing it; programs never call it directly.
12
12
  many call sites would otherwise each grow the binary (`ts_fail`, the rent fallback `ts_rent_slow`, PDA search).
13
13
  - **Errors are return values.** A function that can fail returns `uint64_t`: `SUCCESS`, or an error code. Fail with
14
14
  `TS_FAIL(code, "TypeSOL: …")` (logs the message, then returns the code) and propagate with `TS_TRY(call)`.
15
- Nothing aborts: the instruction returns the code, and the runtime reports it as `Custom(code)`.
15
+ The instruction returns the code, and the runtime reports it as `Custom(code)`. The exceptions abort the program
16
+ instead: Rust-style panics (`panic`, `PANIC_ON_OVERFLOW`, `PANIC_STYLE`, `panicsAt`) and a RedBlackTree whose bytes
17
+ are inconsistent (`ts_rbt_bad_index`, `ts_rbt_too_deep`, as lib-sokoban panics), which end with the runtime's
18
+ "SBF program panicked".
19
+ - **No C struct by value where it may alias.** The SBF target passes a C struct argument as a pointer to the caller's
20
+ object and makes no copy, so a function that writes memory the argument came from would see its own writes. A
21
+ runtime function taking a struct and an out-pointer it writes reads the struct into scalars first (`ts_str_append`
22
+ is an always-inlined wrapper of `ts_str_append_n`); generated helpers take such values by pointer.
23
+ - **Bounds without wrapping.** Size checks compare `a + b > limit` only when the sum cannot overflow, else
24
+ `n > limit - at` with `at <= limit` known (`ts_alloc`); a check such as `n > len - at - rest` is wrong when `at` may
25
+ be past `len - rest`.
16
26
  - **Error codes follow Anchor.** Where Anchor has a framework error with the same meaning, its number is used (2006
17
27
  ConstraintSeeds, 3003 AccountDidNotDeserialize, …), so Anchor and Codama clients name failures correctly.
18
28
  TypeSOL-only conditions are 5100–5199; user errors start at 6000. Every code is listed in [errors.md](errors.md).
@@ -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 (3000), and an address someone
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,25 @@ 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. 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
66
+ string arguments as they were at the call (a copy unless nothing it is given reaches them), and a closed account
67
+ is not used after `close()` (compile error).
60
68
  10. **Remaining accounts.** Writing one (`.lamports`, `loadAccountMut`) checks it is writable (3006) and not another
61
69
  account of the instruction (2040); `loadAccountMut` loads a given account once per instruction (2040);
62
70
  `loadAccount<T>` checks owner, discriminator and size, and validates the data as instruction arguments are.
63
- 11. **Growth.** An account grows by at most 10 KiB per instruction (3016), the payer is a `Mut<Signer>`, new bytes are
64
- 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.
65
74
  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
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
67
79
  signs for it; remaining accounts keep the flags they were passed with, or are checked for the role requested.
68
80
  `invokeInstruction` is the exception by design: its program, account flags and data come from values (stored in
69
81
  account data or passed in), so the compiler cannot check them; the runtime does, refusing any account the
@@ -86,15 +98,23 @@ Each holds for every instruction of every program the compiler accepts. A break
86
98
  - **`requirePda(account, seeds, bump)`.** Any valid bump passes (Anchor's `bump = expr`). Use a stored bump, never one
87
99
  from the arguments.
88
100
  - **`Dup<…>`.** A parameter marked `Dup` may be the same account as another writable one. Reads see every write
89
- (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.)
90
103
  - **`NATIVE_ACCOUNT_WRITES`.** A program that declares it gives up the up-front writability check and the
91
104
  one-view-per-account refusal for `loadRawMut`, `storeBorsh` and BigVec writes, as a native program has neither: the
92
105
  runtime still refuses a changed read-only account, but two loads of one account alias each other. Make the
93
106
  original's address and type checks before loading.
94
107
  - **Instruction introspection.** The Instructions sysvar holds what the transaction's author put there. Require things
95
108
  of the transaction with it (that a repay instruction follows), never treat it as proof of who did what.
96
- - **Oracles.** `pythPrice` checks verification, feed and age (pass the exponent you scale by); the raw `update.*`
97
- 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.
98
118
  - **`merkleVerify`.** Leaves and inner nodes hash alike: build leaves as `keccak256(keccak256(data))` in the program.
99
119
  - **Existing accounts in `createIfNeeded`.** An existing token account's delegate and close authority, and a mint's
100
120
  extensions the call does not name, are not checked (as in Anchor).
@@ -107,8 +127,55 @@ Each holds for every instruction of every program the compiler accepts. A break
107
127
  - Arithmetic overflow returns an error code (5100) in every build; Anchor aborts the program, and only when
108
128
  overflow checks are enabled.
109
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
+
149
+ ## Review of 0.43.0 (2026-11-11)
150
+
151
+ An internal review of 0.43.0 found that some of the guarantees above did not hold in every case; the defects are
152
+ listed in [audit.md](audit.md#0430-2026-11-11) and fixed in 0.44.0. Programs built with 0.43.0 or
153
+ earlier should be rebuilt with it and redeployed: the fixes change the binary of programs that have a helper
154
+ 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
155
+ binary, 41 to another).
156
+
157
+ The defect that can break an authorization check is the first: a Pubkey, Option, string or u256 argument of a
158
+ helper was not a copy. A program was exposed where all of these hold:
159
+
160
+ - a helper takes a parameter of one of those types and also an account it writes (or remaining accounts, or an
161
+ `Inout` place);
162
+ - a call passes that parameter a field of the same account (`rotate(v, v.admin, caller)`), or a value stored in it;
163
+ - the helper reads the parameter after writing the field (`v.admin = v.pending`, then a check on `admin`): it read
164
+ the new value;
165
+ - the helper was not inlined. A `/** @noinline */` helper never is; for the others it was clang's choice, which the
166
+ source does not show, so count every such call as exposed.
167
+
168
+ Each of the other defects needs the construct it names: a seed list bound to a name, given to a helper or written
169
+ beside an argument with side effects; a reference held across a helper that is given an account-group field or a
170
+ loaded account; Borsh input with an Option of a struct that holds an Option (a bounded read past the input, no
171
+ write); a closure or callback that changes a local read before it; a string viewing an `Inout` place; `close()` into
172
+ the account itself, `Dup<…>` on a closed account, or an account used after `close()`. A program without them was not
173
+ exposed to them.
174
+
110
175
  ## Status
111
176
 
112
- The compiler and runtime have had internal security reviews; the findings of the latest are fixed in 0.25.0
113
- (CHANGELOG). The releases after it have not had such a review yet, and there has been no external audit: see
114
- [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).
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.** A release that changes the binary of a program that uses
15
- none of 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 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
+
@@ -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.