@typesol/cli 0.38.0 → 0.40.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 +373 -2
- package/README.md +43 -26
- package/SECURITY.md +1 -1
- package/dist/cli.js +37 -3
- package/dist/compiler/analyze.d.ts +6 -11
- package/dist/compiler/analyze.js +331 -34
- package/dist/compiler/emit/alias.js +3 -2
- package/dist/compiler/emit/base.d.ts +7 -1
- package/dist/compiler/emit/base.js +2 -0
- package/dist/compiler/emit/borsh.js +63 -2
- package/dist/compiler/emit/calls.d.ts +14 -1
- package/dist/compiler/emit/calls.js +311 -21
- package/dist/compiler/emit/cpi-core.js +17 -5
- package/dist/compiler/emit/cpi.js +81 -27
- package/dist/compiler/emit/create.d.ts +7 -0
- package/dist/compiler/emit/create.js +27 -0
- package/dist/compiler/emit/expressions.d.ts +6 -0
- package/dist/compiler/emit/expressions.js +102 -6
- package/dist/compiler/emit/function.d.ts +7 -0
- package/dist/compiler/emit/function.js +164 -29
- package/dist/compiler/emit/program.js +27 -2
- package/dist/compiler/emit/shared.d.ts +15 -5
- package/dist/compiler/emit/shared.js +5 -0
- package/dist/compiler/emit/statements.d.ts +28 -1
- package/dist/compiler/emit/statements.js +270 -13
- package/dist/compiler/emit/storage.d.ts +10 -1
- package/dist/compiler/emit/storage.js +50 -11
- package/dist/compiler/hints.d.ts +5 -0
- package/dist/compiler/hints.js +88 -0
- package/dist/compiler/idl.d.ts +1 -1
- package/dist/compiler/idl.js +42 -11
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/index.js +6 -1
- package/dist/compiler/model.d.ts +47 -10
- package/dist/compiler/model.js +14 -4
- package/dist/testing.js +8 -0
- package/dist/tools/clientgen.js +10 -1
- package/dist/tools/portgen.d.ts +6 -0
- package/dist/tools/portgen.js +68 -17
- package/docs/architecture.md +5 -4
- package/docs/audit.md +31 -19
- package/docs/case-study-escrow.md +5 -5
- package/docs/case-study-jito-mev.md +9 -5
- package/docs/case-study-marginfi.md +797 -0
- package/docs/case-study-multisig.md +3 -3
- package/docs/case-study-raydium-amm.md +80 -0
- package/docs/case-study-raydium-clmm.md +44 -33
- package/docs/case-study-raydium-cp-swap.md +3 -3
- package/docs/cli.md +5 -5
- package/docs/client.md +1 -1
- package/docs/errors.md +13 -5
- package/docs/language.md +65 -32
- package/docs/migrate-from-anchor.md +4 -1
- package/docs/runtime.md +1 -1
- package/docs/security-model.md +2 -1
- package/docs/testing.md +34 -1
- package/docs/troubleshooting.md +6 -0
- package/lib/typesol.d.ts +118 -10
- package/package.json +9 -7
- package/runtime/typesol_rt.h +158 -17
- package/ts-plugin/index.js +24 -1
package/docs/audit.md
CHANGED
|
@@ -7,21 +7,21 @@ with TypeSOL are out of scope; their authors audit them.
|
|
|
7
7
|
|
|
8
8
|
## Scope
|
|
9
9
|
|
|
10
|
-
In order of priority. Line counts at 0.
|
|
10
|
+
In order of priority. Line counts at 0.38.0 plus main (November 2026).
|
|
11
11
|
|
|
12
12
|
| Priority | Component | Files | Lines | Why |
|
|
13
13
|
| --- | --- | --- | ---: | --- |
|
|
14
|
-
| 1 | C runtime | `runtime/typesol_rt.h` |
|
|
15
|
-
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` |
|
|
16
|
-
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 2,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 3,
|
|
18
|
-
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,
|
|
19
|
-
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,
|
|
20
|
-
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,
|
|
21
|
-
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,
|
|
14
|
+
| 1 | C runtime | `runtime/typesol_rt.h` | 2,407 | In every program: input parsing, account checks, checked arithmetic, PDAs, system and token CPIs, account creation, resizing and closing, oracles, signature checks, the heap |
|
|
15
|
+
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 733 | Which checks each account parameter gets, and their order |
|
|
16
|
+
| 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 2,577 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
|
|
17
|
+
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 3,730 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
|
|
18
|
+
| 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,454 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
|
|
19
|
+
| 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 1,656 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
|
|
20
|
+
| 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 2,715 | What the language accepts; constraints and account types as parsed from the source |
|
|
21
|
+
| 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,293 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
|
|
22
22
|
| 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
|
|
23
23
|
|
|
24
|
-
The language surface is `lib/typesol.d.ts` (
|
|
24
|
+
The language surface is `lib/typesol.d.ts` (2,057 lines): every type and built-in a program can use, with its
|
|
25
25
|
documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
|
|
26
26
|
the code, [docs/runtime.md](runtime.md) the runtime's conventions.
|
|
27
27
|
|
|
@@ -48,7 +48,12 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
|
|
|
48
48
|
|
|
49
49
|
## Earlier reviews
|
|
50
50
|
|
|
51
|
-
Internal reviews, by the maintainers, in October 2026. Their findings and fixes are in the CHANGELOG
|
|
51
|
+
Internal reviews, by the maintainers, in October 2026. Their findings and fixes are in the CHANGELOG. The releases
|
|
52
|
+
after 0.25.0 (0.26.0 to 0.38.0, and main since) have had no review of this kind yet; they add, among others, `u256`,
|
|
53
|
+
big-endian seeds and accounts loaded in the body (0.37.0), stored bumps in nested fields and error members without
|
|
54
|
+
messages (0.38.0), and on main `@code`, `@repr` / `@serialization`, `@bytes` / `@idlName`, `f64`, Options inside
|
|
55
|
+
Options in arguments and events, and loop-scoped `loadAccountMut` with `Dup<T>`. An external review should include
|
|
56
|
+
them.
|
|
52
57
|
|
|
53
58
|
- **0.25.0** (runtime and emitted checks): two Medium issues fixed, a remaining account loaded mutably twice through
|
|
54
59
|
the same slot, and a Vec element written after its right side resized the Vec; plus a token program ambiguity,
|
|
@@ -60,22 +65,29 @@ Internal reviews, by the maintainers, in October 2026. Their findings and fixes
|
|
|
60
65
|
|
|
61
66
|
## Evidence
|
|
62
67
|
|
|
63
|
-
- **Tests**:
|
|
68
|
+
- **Tests**: by subject under `test/` (`docs/architecture.md`); the count of each run is in CI's log (727 on main on
|
|
69
|
+
2026-11-01). `test/security/` holds the attacks.
|
|
64
70
|
- **Differential tests**: the same transactions to TypeSOL and to Anchor twins (`test/anchor-twins`), comparing
|
|
65
71
|
outcomes, account contents and balances after every step.
|
|
66
|
-
- **Model-based fuzzing** (`test/verification/`): arithmetic against BigInt at every width
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
- **Model-based fuzzing** (`test/verification/`): arithmetic against BigInt at every width, `u256` against BigInt,
|
|
73
|
+
Marginfi's I80F48 against vectors the `fixed` crate wrote; honest and hostile action sequences against state models
|
|
74
|
+
with value conservation; account layout with two growable Vecs and aliasing through remaining accounts. Each run
|
|
75
|
+
prints its seed (`FUZZ_SEED`), `pnpm fuzz` runs them wide.
|
|
76
|
+
- **Random transactions against mainnet binaries**: Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`),
|
|
77
|
+
Marginfi's administration and interest (`showcase/test/fuzz-marginfi.test.ts`) and Raydium CLMM (the `fuzz:`
|
|
78
|
+
case of its differential test) take random sequences of honest and hostile
|
|
79
|
+
transactions, in the original and the port alike, with the same outcome, account bytes and events required after
|
|
80
|
+
every step. A new seed on every run, CI's included.
|
|
69
81
|
- **Ported programs**: all 46 programs of solana-developers/program-examples, run through their original tests' flows
|
|
70
|
-
and failure paths ([
|
|
71
|
-
- **Four-way comparison**: [typesol/benchmarks](https://github.com/typesol/benchmarks) runs 17 of those programs in
|
|
82
|
+
and failure paths ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)).
|
|
83
|
+
- **Four-way comparison**: [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) runs 17 of those programs in
|
|
72
84
|
TypeSOL, Anchor, native Rust and Pinocchio, requires the same outcome, and records how each refuses the hostile calls
|
|
73
85
|
and with which error.
|
|
74
86
|
|
|
75
87
|
## Running it
|
|
76
88
|
|
|
77
89
|
```sh
|
|
78
|
-
git clone https://github.com/typesol/typesol && cd typesol
|
|
90
|
+
git clone https://github.com/typesol-lang/typesol && cd typesol
|
|
79
91
|
pnpm install && pnpm build
|
|
80
92
|
pnpm fetch:programs # Metaplex binaries for the token-metadata, Core and Bubblegum tests
|
|
81
93
|
pnpm build:twins # the Anchor twins (Rust + Anchor 1.0.2)
|
|
@@ -88,5 +100,5 @@ way to review what a construct compiles to; `test/golden/counter.c` is a pinned
|
|
|
88
100
|
|
|
89
101
|
## Contact
|
|
90
102
|
|
|
91
|
-
Coordinate through a private advisory on https://github.com/typesol/typesol/security, or report findings the same way
|
|
103
|
+
Coordinate through a private advisory on https://github.com/typesol-lang/typesol/security, or report findings the same way
|
|
92
104
|
(SECURITY.md).
|
|
@@ -4,7 +4,7 @@ This page follows one complete Anchor program into TypeSOL: the token escrow fro
|
|
|
4
4
|
[solana-developers/program-examples](https://github.com/solana-developers/program-examples/tree/de090195e4de698e150572c4f886c333323a64a5/tokens/escrow/anchor)
|
|
5
5
|
(`tokens/escrow`, commit `de09019`). It shows the original and the port side by side, what changed, how the two were
|
|
6
6
|
checked against each other, where they still differ, and what the port costs to run. The port is
|
|
7
|
-
[`
|
|
7
|
+
[`showcase/program-examples/tokens/escrow.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/tokens/escrow.ts); [Migrate from Anchor](migrate-from-anchor.md) is the
|
|
8
8
|
general reference.
|
|
9
9
|
|
|
10
10
|
## The program
|
|
@@ -160,17 +160,17 @@ tokenProgram.closeAccount(vault, maker, offer, ["offer", maker.key, offer.id, of
|
|
|
160
160
|
| `ErrorCode::CustomError` (unused upstream) | `enum ErrorCode`, the same code 6000 |
|
|
161
161
|
|
|
162
162
|
Nothing in the program needed a construct TypeSOL lacks, and every account constraint has its TypeSOL form; the port
|
|
163
|
-
is marked PORTED in [the ports table](https://github.com/typesol/typesol/blob/main/
|
|
163
|
+
is marked PORTED in [the ports table](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md).
|
|
164
164
|
|
|
165
165
|
## Same inputs, same results
|
|
166
166
|
|
|
167
167
|
Two independent checks run the original and the port against each other.
|
|
168
168
|
|
|
169
|
-
- **The port's own test** ([`test/porting/ports-tokens.test.ts`](https://github.com/typesol/typesol/blob/main/test/porting/ports-tokens.test.ts)) runs the upstream flow with SPL
|
|
169
|
+
- **The port's own test** ([`showcase/test/porting/ports-tokens.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/porting/ports-tokens.test.ts)) runs the upstream flow with SPL
|
|
170
170
|
Token mints and again with Token-2022 mints: make, take (creating the taker's and the maker's missing token accounts),
|
|
171
171
|
make again, a refund attempt by someone other than the maker, and the refund. It checks balances, the decoded offer
|
|
172
172
|
and that offer and vault are closed.
|
|
173
|
-
- **The four-way comparison** in [typesol/benchmarks](https://github.com/typesol/benchmarks) builds the upstream Anchor,
|
|
173
|
+
- **The four-way comparison** in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) builds the upstream Anchor,
|
|
174
174
|
native and Pinocchio versions unmodified and sends all four the same 21 offers (ten taken, ten refunded, one left
|
|
175
175
|
open). The decoded open offer, every token balance, the vault's authority and which accounts were closed must be
|
|
176
176
|
identical before any number is reported. They are.
|
|
@@ -191,7 +191,7 @@ token account. A client that matches on this code needs to accept either.
|
|
|
191
191
|
## Cost
|
|
192
192
|
|
|
193
193
|
Mean compute units per instruction in LiteSVM (21 make_offer, 10 take_offer and 10 refund_offer calls), and the
|
|
194
|
-
program size, from typesol/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
|
|
194
|
+
program size, from typesol-lang/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
|
|
195
195
|
|
|
196
196
|
| | TypeSOL | Anchor | Native Rust | Pinocchio |
|
|
197
197
|
| --- | ---: | ---: | ---: | ---: |
|
|
@@ -6,9 +6,9 @@ Anchor 0.31.1, Apache-2.0). Each one is checked against the binary that runs on
|
|
|
6
6
|
|
|
7
7
|
| Program | Mainnet id | Port |
|
|
8
8
|
| --- | --- | --- |
|
|
9
|
-
| Tip payment | `T1pyyaTNZsKv2WcRAB8oVnk93mLJw2XzjtVYqCsaHqt` | [`tip_payment.ts`](https://github.com/typesol/typesol/blob/main/
|
|
10
|
-
| Tip distribution | `4R3gSG8BpU4t19KYj8CfnbtRpnT8gtk4dvTHxVRwc2r7` | [`tip_distribution.ts`](https://github.com/typesol/typesol/blob/main/
|
|
11
|
-
| Priority fee distribution | `Priority6weCZ5HwDn29NxLFpb7TDp2iLZ6XKc5e8d3` | [`priority_fee_distribution.ts`](https://github.com/typesol/typesol/blob/main/
|
|
9
|
+
| Tip payment | `T1pyyaTNZsKv2WcRAB8oVnk93mLJw2XzjtVYqCsaHqt` | [`tip_payment.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/tip_payment.ts) |
|
|
10
|
+
| Tip distribution | `4R3gSG8BpU4t19KYj8CfnbtRpnT8gtk4dvTHxVRwc2r7` | [`tip_distribution.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/tip_distribution.ts) |
|
|
11
|
+
| Priority fee distribution | `Priority6weCZ5HwDn29NxLFpb7TDp2iLZ6XKc5e8d3` | [`priority_fee_distribution.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/mainnet/jito-mev/priority_fee_distribution.ts) |
|
|
12
12
|
|
|
13
13
|
Searchers pay tips into eight fixed tip payment accounts. When the leader changes, the tip payment program pays them
|
|
14
14
|
out to the current tip receiver and the block builder's commission to the block builder. The tip receiver is
|
|
@@ -74,9 +74,9 @@ The rest uses what TypeSOL already had:
|
|
|
74
74
|
|
|
75
75
|
## How it was checked
|
|
76
76
|
|
|
77
|
-
[`test/
|
|
77
|
+
[`showcase/test/jito-mev.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/jito-mev.test.ts) loads
|
|
78
78
|
the binaries dumped from mainnet on 2026-10-31 (sha256 in
|
|
79
|
-
[`test/programs/SOURCES.md`](https://github.com/typesol/typesol/blob/main/test/programs/SOURCES.md)). A dump is padded
|
|
79
|
+
[`test/programs/SOURCES.md`](https://github.com/typesol-lang/typesol/blob/main/test/programs/SOURCES.md)). A dump is padded
|
|
80
80
|
with zeros to its program account's size, 10 MB for tip distribution, so the files are cut where the ELF ends. Each
|
|
81
81
|
original runs in one LiteSVM and its port in another, under the same program id and with the same clock.
|
|
82
82
|
|
|
@@ -117,6 +117,10 @@ There are 150 transactions:
|
|
|
117
117
|
- a go-live epoch in the future, then the current one;
|
|
118
118
|
- a transfer into last epoch's account.
|
|
119
119
|
|
|
120
|
+
Besides these, `showcase/test/fuzz-jito.test.ts` sends random sequences of the same transactions, honest and
|
|
121
|
+
hostile, to the originals and the ports, with a new seed on every run (CI's included). It requires the same outcome,
|
|
122
|
+
bytes, events and log lines after every step; `FUZZ_SEED=<seed>` reproduces a run, `FUZZ_STEPS=<n>` lengthens it.
|
|
123
|
+
|
|
120
124
|
## Cost
|
|
121
125
|
|
|
122
126
|
Compute units per transaction, mainnet original against the port, from one run of that test:
|