@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.
- package/CHANGELOG.md +166 -0
- package/NOTICE +14 -1
- package/README.md +52 -10
- package/SECURITY.md +1 -1
- package/dist/cli.js +194 -48
- package/dist/compiler/emit/alias.d.ts +16 -2
- package/dist/compiler/emit/alias.js +62 -4
- package/dist/compiler/emit/calls.js +15 -7
- package/dist/compiler/emit/cpi-core.d.ts +6 -0
- package/dist/compiler/emit/cpi-core.js +18 -5
- package/dist/compiler/emit/create.js +19 -11
- package/dist/compiler/emit/function.js +5 -5
- package/dist/compiler/emit/metaplex.js +17 -4
- package/dist/compiler/emit/token.js +64 -39
- package/dist/compiler/index.d.ts +51 -1
- package/dist/compiler/index.js +17 -2
- package/dist/compiler/toolchain.d.ts +23 -0
- package/dist/compiler/toolchain.js +128 -8
- package/dist/tools/docker.d.ts +183 -0
- package/dist/tools/docker.js +442 -0
- package/dist/tools/doctor.d.ts +3 -0
- package/dist/tools/doctor.js +12 -0
- package/dist/workspace.d.ts +2 -1
- package/dist/workspace.js +33 -6
- package/docker/Dockerfile +163 -0
- package/docker/deps/0.43.0.lock.json +1206 -0
- package/docker/deps/0.44.0.lock.json +1206 -0
- package/docker/deps/0.44.1.lock.json +1206 -0
- package/docker/deps/0.45.0.lock.json +1206 -0
- package/docs/architecture.md +13 -5
- package/docs/audit.md +54 -7
- package/docs/cli.md +31 -4
- package/docs/errors.md +1 -1
- package/docs/language.md +6 -4
- package/docs/mainnet.md +86 -6
- package/docs/security-model.md +47 -12
- package/docs/stability.md +62 -3
- package/docs/testing.md +49 -2
- package/docs/troubleshooting.md +46 -0
- package/llms-full.txt +283 -34
- package/package.json +3 -1
- package/releases/0.43.0.json +669 -0
- package/releases/0.44.0.json +672 -0
- package/releases/0.44.1.json +672 -0
- package/runtime/LICENSE-compiler-builtins.txt +275 -0
- package/runtime/typesol_builtins.c +484 -0
- package/runtime/typesol_rt.h +8 -5
package/llms-full.txt
CHANGED
|
@@ -39,10 +39,6 @@ sh -c "$(curl -sSfL https://release.anza.xyz/v3.1.10/install)"
|
|
|
39
39
|
cargo-build-sbf --install-only --force-tools-install --tools-version v1.52
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
Other versions work, but their binaries are not covered by the project's tests: `typesol build` warns once when the
|
|
43
|
-
clang is another one (`--toolchain-strict` or `TYPESOL_TOOLCHAIN=strict` makes that an error), and every build records
|
|
44
|
-
its clang, platform-tools and host in `<name>.build.json`.
|
|
45
|
-
|
|
46
42
|
```sh
|
|
47
43
|
npx @typesol/cli init my-app --name counter # typesol.json, programs/counter.ts, tests/counter.test.ts, tsconfig
|
|
48
44
|
cd my-app && npm install
|
|
@@ -50,6 +46,10 @@ npm test # builds the program and runs it i
|
|
|
50
46
|
npx --no-install typesol build # target/counter/{counter.so, counter.json (IDL), counter.client.ts, counter.build.json}
|
|
51
47
|
```
|
|
52
48
|
|
|
49
|
+
Other versions work, but their binaries are not covered by the project's tests: `typesol build` warns once when the
|
|
50
|
+
clang is another one (`--toolchain-strict` or `TYPESOL_TOOLCHAIN=strict` makes that an error), and every build records
|
|
51
|
+
its clang, platform-tools and host in `<name>.build.json`.
|
|
52
|
+
|
|
53
53
|
`npx --no-install typesol doctor` checks all of this (Node.js, platform-tools and whether they are the tested ones, Solana CLI, keypair, RPC) and prints the command
|
|
54
54
|
that fixes anything missing. Inside a project, `npx --no-install typesol …` (or `npm run build`, `npm run deploy`) runs the
|
|
55
55
|
project's own copy; outside one, use `npx @typesol/cli …`. Plain `npx typesol` is not TypeSOL: `typesol` is not the npm
|
|
@@ -124,7 +124,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
124
124
|
| Events | `emit<Deposited>({ owner: owner.key, amount })` — Anchor-format `Program data:` logs, listed under `events` in the IDL; event structs may hold `string`, `Option`, `FixedVec<T, N>` (its fixed layout, as in account data), `Vec<T>` (Borsh: from a Vec argument or a list in account data) and `Option<Vec<T>>`; a nested struct given as a literal is Borsh too |
|
|
125
125
|
| Enums | `export enum Status { Pending, Approved }` — unit variants stored as the Borsh u8 index; `Status.Approved`, `===` |
|
|
126
126
|
| Options | `best: Option<u64>` (or `u64 \| null`) — `null`, `=== null`, TypeScript narrowing; `===` between options or with a value follows JS (null equals null, empty never equals a value); empty use aborts (5108); `acct?.field` on an optional account and `x.home?.field` on an `Option<struct>` give an Option (empty when the account was left out / the option is empty), `a ?? b` takes b only when a is empty (b runs only then; the result is an Option when b can be null), `x!` is the value or aborts with 5108; `${opt}` prints the value or `null`. Borsh `option` in arguments/events, fixed `{ is_some, value }` in account data |
|
|
127
|
-
| Vecs | `entries: Vec<Entry>` in account data, any number of them, declared anywhere: they are stored after the fixed-size fields in the order declared (so every other field keeps its offset; the IDL lists that order), and a push, pop or clear moves the Vecs after it (a reference into one of those cannot be used across it). In a `@layout borsh` struct a Vec is the last field (Anchor's order) — `get`, `set`, `push(v, payer)`, `pop()`, `clear()`, `.length`; the account is resized (realloc) and rent topped up by `payer`; `Vec<u64>` arguments are read-only views; `Vec<string>` arguments (Anchor's `Vec<String>`) are views of the instruction data, each checked as UTF-8 on entry (102), and go back out as Borsh through `invoke`; `pop()` of a Vec of structs works as a statement |
|
|
127
|
+
| Vecs | `entries: Vec<Entry>` in account data, any number of them, declared anywhere: they are stored after the fixed-size fields in the order declared (so every other field keeps its offset; the IDL lists that order), and a push, pop or clear moves the Vecs after it (a reference into one of those cannot be used across it, also when it was made through another parameter that may be the same account: a `Dup<…>` pair, a read-only and a writable account of one type, a struct loaded with `loadAccount` / `loadAccountMut`). In a `@layout borsh` struct a Vec is the last field (Anchor's order) — `get`, `set`, `push(v, payer)`, `pop()`, `clear()`, `.length`; the account is resized (realloc) and rent topped up by `payer`; `Vec<u64>` arguments are read-only views; `Vec<string>` arguments (Anchor's `Vec<String>`) are views of the instruction data, each checked as UTF-8 on entry (102), and go back out as Borsh through `invoke`; `pop()` of a Vec of structs works as a statement |
|
|
128
128
|
| Anchor's account bytes | `/** @layout borsh */` on an account struct stores it as Anchor does (Borsh: a `FixedString<N>` is a String, a `FixedVec<T, N>` or `Vec<T>` a Vec, an `Option` one byte when empty, and the fields after them move), so a TypeSOL program can take over accounts an Anchor program wrote and the IDL lists Anchor's own types. The instruction unpacks it into the usual fixed layout when it starts (bad bytes fail with 3003) and packs it back when it returns (3004 when the account is too small for the new value), so everything else works on it unchanged. A `Vec<T>` field (any position; integers, booleans, Pubkeys, unit enums or fixed-size structs) is Anchor's own: held on the heap while the instruction runs, growing as Rust's Vec does, bounded only by the account when it is written back (3004); its elements move when it grows, so a reference into one cannot outlive a `push` or an assignment. `Init` of such a struct takes its space, `create(payer, seeds, space)`. Programs invoked from the body (CPIs) see the account's bytes as they were when the instruction started. Costs more compute than the fixed layout (the whole account is read and written each time; see the benchmarks); nested structs and list elements must be fixed-size (FixedString elements allowed). The same struct is Borsh as a whole instruction argument (checked like Borsh deserialization, UTF-8 included), as return data and as an event; as those (not as account data) it may also hold `string` fields and data enums carrying strings, Anchor's `String` and enums in argument structs (account data takes data enums without strings); not inside list or enum arguments or `loadAccount`, and a struct holding a `Vec<T>` is account data or a whole argument, not return data or an event |
|
|
129
129
|
| A native program's Borsh accounts | `const pool = loadBorsh<StakePool>(acct)` / `storeBorsh(acct, pool)`: Borsh from byte 0 with no discriminator and no owner check, read into a local struct and written back, as Rust's `try_from_slice_unchecked` and `serialize` do (trailing bytes ignored when reading, left as they were when writing; invalid bytes or an account too small fail with `ProgramError.BorshIoError`). Any struct of integers, booleans, Pubkeys, enums, FixedArrays, FixedStrings, FixedVecs, Options, data enums with fixed-size payloads and nested structs of those; see [Porting a native program](#porting-a-native-program) |
|
|
130
130
|
| Zero-copy types as Anchor's IDL describes them | `/** @repr c */` (`@repr c packed`, `@repr c align 8`, `@repr rust` on an enum) and `/** @serialization bytemuck */` on a struct or enum put the IDL's `repr` and `serialization` there, as Anchor's `#[account(zero_copy)]` / `#[repr(C)]` types have them. TypeSOL stores fields back to back, so an unpacked `@repr c` struct must have its fields where C puts them: a field off its alignment, or a size that is not a multiple of the struct's, is a compile error naming the padding to add (Anchor zero-copy types spell their padding out as `_pad` fields, so a port matches). A 16-byte integer's alignment differs between targets: hold it as below or mark the struct packed |
|
|
@@ -149,7 +149,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
149
149
|
| Strings at runtime | `"hello, " + name`, `` `#${n}` ``, `` `owner ${acct.owner}` `` (a Pubkey or Hash as base58; an `Option` of an integer, boolean, Pubkey or Hash as its value, or `null` when empty, as JS prints it: after `x !== null` that is the value) — built on the 32 KiB heap (5110 when full): a template is joined in one allocation, text known at compile time (literals, string and Pubkey constants) is folded in, and `s += …` grows the newest heap string in place |
|
|
150
150
|
| `switch` | on integers (128-bit ones too), enums and data-enum `.kind`, with JS `break` / fallthrough; case labels are literals, constants or enum members |
|
|
151
151
|
| Hashing & signatures | `sha256(...)`, `keccak256(...)` → `Hash` (a PDA seed too: its 32 bytes, as Marginfi seeds an order with the hash of its bank keys); `findProgramAddress(seeds, program)` → the canonical PDA of any program (Rust `Pubkey::find_program_address(..).0`, e.g. a Bubblegum asset id) and `findProgramAddressBump(seeds, program)` its bump, or both from one search with `const [address, bump] = findProgramAddressWithBump(seeds, program)` (Rust's `let (address, bump) = …`; each separate search costs about 450 CU per bump tried); `programId()` → this program's address; `a.compare(b)` orders Pubkeys and Hashes as Rust orders their 32 bytes (-1 / 0 / 1); `merkleVerify(leaf, proof: Vec<Hash>, root)` (sorted-pair keccak, OpenZeppelin convention; inner nodes and leaves are hashed alike, so hash leaves as OpenZeppelin does, `keccak256(keccak256(data))`, and never take the leaf itself from the arguments: an inner node would pass as a leaf); `verifyEd25519(instructionsSysvar, signer, message)` checks an Ed25519 precompile instruction in the same transaction; `stackHeight()` is 1 when the transaction calls the program directly, more under a CPI (`require(stackHeight() === 1n, …)` refuses CPI callers); `verifySecp256k1(keccak256(...message) | ethMessageHash(message), recoveryId, r, s, ethAddress)` (the hash must be computed in the program; a passed-in hash could be forged) |
|
|
152
|
-
| Oracles | `pythPrice(update: PythPriceUpdate, feedId, maxAgeSeconds, exponent?)` (fully verified, feed-matched, fresh; with `exponent`, a feed at another scale is refused); raw `update.price / conf / exponent / publishTime` are unchecked (any feed, partially verified or stale: check `feedId`, `fullyVerified` and the age yourself, or use `pythPrice`); `switchboardValue(feed: SwitchboardFeed, expectedFeed, maxStaleSlots, decimals, minSamples?)` (the feed must be the expected one: anyone can create feeds; `minSamples`, default 1, the fewest oracle samples accepted) (mainnet program unless `SwitchboardFeed<"devnet">`) |
|
|
152
|
+
| Oracles | `pythPrice(update: PythPriceUpdate, feedId, maxAgeSeconds, exponent?)` (fully verified, feed-matched, fresh; with `exponent`, a feed at another scale is refused); raw `update.price / conf / exponent / publishTime` are unchecked (any feed, partially verified or stale: check `feedId`, `fullyVerified` and the age yourself, or use `pythPrice`); `switchboardValue(feed: SwitchboardFeed, expectedFeed, maxStaleSlots, decimals, minSamples?)` (the feed must be the expected one: anyone can create feeds; `minSamples`, default 1, the fewest oracle samples accepted; staleness counts slots from the feed's `result.slot`; the 18-decimal result is scaled to `decimals` rounding toward zero) (mainnet program unless `SwitchboardFeed<"devnet">`). Neither reader checks the price's sign or zero, the confidence (Pyth's `conf`, Switchboard's spread of samples), or a publish time or result slot in the future (it counts as fresh): check what your program relies on |
|
|
153
153
|
| Randomness | A chain has no secret randomness of its own: slot hashes and timestamps are known to, or chosen by, the block producer. `SwitchboardRandomness` (Switchboard On-Demand's RandomnessAccountData; owner, discriminator and size checked) gives verifiable randomness by commit and reveal: commit while `r.seedSlot === currentSlot() - 1n` and store `r.key` and `r.seedSlot`; settle in a later transaction after checking both, with `r.value()` (32 bytes) or `r.valueU64()`, which fail (5111) unless the value was revealed in this slot. See test/fixtures/coinflip.ts |
|
|
154
154
|
| Multiple files | `import { Side, min } from "./math"` — structs, enums, constants and helpers can live in other files; only the entry file's exported functions are instructions; names are program-wide, so imports from TypeSOL files cannot be renamed; error codes number imported files first |
|
|
155
155
|
| Loops | `for (let i = 0n; i < n; i++)` (or two counters, `for (let i = 0n, j = n; i < j; i++, j--)`: several declarations, and comma-separated updates run in order after each pass, `continue` included), `while`, `do … while`, `for (const x of list)` over a `Vec` or `FixedArray` (each `x` is what `list.get(i)` gives: a value, or a reference into account data for structs; the length is read again every step, as in JS), `break`, `continue` — bounded by the compute budget. Remaining accounts are iterated by index |
|
|
@@ -195,7 +195,7 @@ The full reference. For a tour, start with the [README](../README.md).
|
|
|
195
195
|
| `Migrate<From, To>` | Anchor 1.0's `Migration`: an existing `From` account (owner, discriminator, size) rewritten as `To` by `acct.migrate(payer, value)`, a top-level statement the instruction must reach. `acct.from` (read-only) before it, `acct.to` after; the value is built in full before the rewrite, so it may read `acct.from`. Resized to `To` (the payer tops up rent when it grows, at most 10 KiB; shrinking keeps the lamports; growing needs `SystemProgram`). Fixed-layout structs without growable Vecs; no constraints yet; the account cannot be passed to a helper (use `acct.to` fields in the instruction). An account already migrated fails with 3002. Keep the old struct under a new name with its discriminator: `/** @discriminator account:Counter */ interface CounterV1 { … }` |
|
|
196
196
|
| `Zeroed<T>` | accounts (up to 10 MiB) the client allocated with System `CreateAccount`, Anchor's `zero`: discriminator still zero (2013, checked first as under Anchor), owned by this program, big enough, rent-exempt — then initialized. A `@layout borsh` struct starts empty and is written as Borsh when the instruction returns |
|
|
197
197
|
| `Signed<A>` | the account must sign the transaction (Anchor's `signer` constraint, 2002), e.g. `Signed<Zeroed<Multisig>>` for an account the client creates with a fresh keypair; the IDL marks it a signer |
|
|
198
|
-
| `Init<Mint>`, `InitIfNeeded<Mint>` | Anchor `init` / `init_if_needed` with `mint::decimals` / `mint::authority` / `mint::freeze_authority`: `const bump = mint.create(payer, ["mint", payer.key], 6n, authority, freezeAuthority \| null)` creates the mint at that PDA of this program, or with `null` seeds as a new keypair account that signs (3010 if it did not), under the instruction's token program (its only token program parameter, or one passed as the last argument of `create` / `createIfNeeded`; plus `SystemProgram`). Token-2022 extensions (Anchor's `extensions::…`) go after the freeze authority: `mint.create(payer, null, 6n, authority, null, { metadataPointer: { authority, metadataAddress: mint.key }, transferHook: { authority, programId }, closeAuthority, permanentDelegate, nonTransferable: true, defaultAccountState: true, interestBearing: { rateAuthority, rate }, transferFee: { configAuthority, withdrawAuthority, basisPoints, maximumFee }, groupPointer, groupMemberPointer })` sizes the mint for them and initializes each before InitializeMint2. With `createIfNeeded` an existing mint must carry groupPointer / groupMemberPointer / metadataPointer / closeAuthority / permanentDelegate / transferHook with those keys (Anchor's 2024–2039); extensions not listed are not looked at, so an existing mint may carry others (a permanent delegate, say). `createIfNeeded(…)` returns whether it created it; an existing one must be that PDA and have those decimals and authorities (2018 / 2016 / 2017) |
|
|
198
|
+
| `Init<Mint>`, `InitIfNeeded<Mint>` | Anchor `init` / `init_if_needed` with `mint::decimals` / `mint::authority` / `mint::freeze_authority`: `const bump = mint.create(payer, ["mint", payer.key], 6n, authority, freezeAuthority \| null)` creates the mint at that PDA of this program, or with `null` seeds as a new keypair account that signs (3010 if it did not), under the instruction's token program (its only token program parameter, or one passed as the last argument of `create` / `createIfNeeded`; plus `SystemProgram`). Token-2022 extensions (Anchor's `extensions::…`) go after the freeze authority: `mint.create(payer, null, 6n, authority, null, { metadataPointer: { authority, metadataAddress: mint.key }, transferHook: { authority, programId }, closeAuthority, permanentDelegate, nonTransferable: true, defaultAccountState: true, interestBearing: { rateAuthority, rate }, transferFee: { configAuthority, withdrawAuthority, basisPoints, maximumFee }, groupPointer, groupMemberPointer })` sizes the mint for them (as Token-2022 does: extensions adding up to a Multisig's 355 bytes give a 357-byte mint) and initializes each before InitializeMint2; a `null` authority is sent as Token-2022's empty COption. With `createIfNeeded` an existing mint must carry groupPointer / groupMemberPointer / metadataPointer / closeAuthority / permanentDelegate / transferHook with those keys (Anchor's 2024–2039); extensions not listed are not looked at, so an existing mint may carry others (a permanent delegate, say). `createIfNeeded(…)` returns whether it created it; an existing one must be that PDA and have those decimals and authorities (2018 / 2016 / 2017) |
|
|
199
199
|
| `Init<TokenAccount>`, `InitIfNeeded<TokenAccount>` (no `Ata<…>`) | Anchor `init` / `init_if_needed` with `token::mint` / `token::authority`: `vault.create(payer, ["vault", mint.key], mint, authority)` (the authority may be `vault.key` itself) creates a token account at that PDA (or a keypair account with `null`), sized for the mint's extensions under Token-2022. `createIfNeeded` checks an existing one has that mint and owner (2014 / 2015), not its delegate or close authority (as Anchor) |
|
|
200
200
|
| `TokenAccount` / `Mut<TokenAccount>` | owned by SPL Token or Token-2022 (extensions allowed, multisig accounts refused), initialized (an account never created: 3012, as Anchor; a `Mint` likewise); `mint`, `owner`, `amount`, `delegate`, `delegatedAmount`, `isFrozen`, `isNative`, `closeAuthority`, `tokenProgram` |
|
|
201
201
|
| `Mint` / `Mut<Mint>` | owned by SPL Token or Token-2022, initialized; `decimals`, `supply`, `mintAuthority`, `freezeAuthority`, `tokenProgram` |
|
|
@@ -218,7 +218,9 @@ Two writable parameters can never be the same account: aliasing is refused with
|
|
|
218
218
|
account written through `.lamports` or `loadAccountMut` is another account of the instruction). `Dup<Mut<T>>`
|
|
219
219
|
(Anchor's `dup`) lifts that for one parameter when both accounts are read and written in place (not created, closed
|
|
220
220
|
or `@layout borsh`; a close destination may be one, the rent reaching it through either): a write through either is
|
|
221
|
-
seen through the other, so read what you need before writing. A
|
|
221
|
+
seen through the other, so read what you need before writing. A reference into one of them (`const e = a.entries.get(i)`)
|
|
222
|
+
cannot be used after a push, pop or clear through the other moved that data, as with one name (compile error); copy
|
|
223
|
+
the fields first. A remaining account
|
|
222
224
|
can be loaded with `loadAccountMut` once per instruction: loading the same one again (`rest.get(i)` and `rest.get(j)`
|
|
223
225
|
with `i == j`) is refused with 2040 too, since the two views would alias. So is a second `loadAccountMut` of one
|
|
224
226
|
`AccountInfo` parameter; two `Dup<…>` parameters that are one account may each be loaded (one array holding both ticks
|
|
@@ -609,7 +611,7 @@ Framework errors use Anchor's numbers where Anchor has the same check, so client
|
|
|
609
611
|
| 3010 | account must sign (AccountNotSigner; also a new keypair account a `create(payer, null, …)` makes) |
|
|
610
612
|
| 3011 | a `SystemAccount` owned by another program (AccountNotSystemOwned) |
|
|
611
613
|
| 3012 | account not initialized: empty system account where a program account, a token account or a mint was expected (AccountNotInitialized; not for zero-copy accounts, which Anchor's AccountLoader reports as 3007) |
|
|
612
|
-
| 3016 | account would grow more than 10 KiB in one instruction, or grow without a payer (AccountReallocExceedsLimit) |
|
|
614
|
+
| 3016 | account would grow more than 10 KiB in one instruction (counted from its length when the instruction started), or grow without a payer (AccountReallocExceedsLimit) |
|
|
613
615
|
| 4101 | an `Init` / `create` whose payer is the account being created (TryingToInitPayerAsProgramAccount) |
|
|
614
616
|
| 4102 | cast overflow (InvalidNumericConversion) |
|
|
615
617
|
| 5100 / 5101 | arithmetic overflow (including shifts) / division by zero |
|
|
@@ -800,9 +802,9 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
800
802
|
| --- | --- |
|
|
801
803
|
| `typesol init [<dir>] [--name <program>] [--template counter\|vault\|escrow]` | Create a project: `typesol.json`, `programs/<name>.ts`, `tests/<name>.test.ts` (LiteSVM), `package.json`, `tsconfig.json`, `programs/tsconfig.json` (with the editor plugin), `.vscode/settings.json` (the workspace TypeScript, so the plugin loads), `.gitignore`, the rules for AI coding agents (`AGENTS.md`, `CLAUDE.md` importing it, `.cursor/rules/typesol.mdc`) and the MCP server configuration (`.mcp.json`, `.cursor/mcp.json`; see [ai.md](ai.md)). `<name>` must be snake_case; by default it is derived from `<dir>` (`my-app` → `my_app`). The template picks the program and its test: `counter` (default, a PDA counter per user), `vault` (SOL at a PDA: deposit, withdraw above rent, close) or `escrow` (SPL tokens: make, take, refund, the offer PDA signing for its vault). Refuses to overwrite files. It warns, with the install commands, when the platform-tools that building needs are missing. |
|
|
802
804
|
| `typesol new <program> [--template counter\|vault\|escrow]` | In a project: add a program, `programs/<program>.ts` and `tests/<program>.test.ts` from the template, and its entry in `typesol.json`. Refuses to overwrite files or reuse a name. |
|
|
803
|
-
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
804
|
-
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. |
|
|
805
|
-
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
|
|
805
|
+
| `typesol doctor [--url <rpc>] [--config <cli config>]` | Check what building, testing and deploying need: Node.js, the platform-tools (and a `toolchain` row: the tested ones, or untested with both versions), the Solana CLI, Docker (optional: only `--docker` builds need it; it says when they run emulated), its keypair, the RPC (`--url`, a cluster moniker, or the CLI config) and the keypair's balance there, and the project. Each problem is printed with the command that fixes it. Exit code 1 when building is impossible (Node.js or the platform-tools missing); deploy pieces are warnings. |
|
|
806
|
+
| `typesol build [<program>…] [--sbpf v0\|v1\|v2] [--profile] [--toolchain-strict] [--docker [--typesol-version <v>] [--release-record <file>]] [--quiet]` | In a project: build every program (or those named) into `<out>/<name>/`: `<name>.so`, `<name>.json` (Anchor IDL), `<name>.client.ts` (TypeScript client, see [client.md](client.md)), `<name>.c`, `<name>.build.json` (the TypeSOL, TypeScript, clang and platform-tools versions, the host, the SBPF version, each source's sha256 and the binary's). With platform-tools other than the tested ones it warns once; `--toolchain-strict` (or `TYPESOL_TOOLCHAIN=strict`) refuses them. The first build creates `<out>/deploy/<name>-keypair.json` and records the address in `typesol.json`; later builds refuse a different keypair. Without the keypair (a fresh clone, CI) it builds at the recorded address and says so; only `deploy` needs the keypair. `--docker` builds in the pinned container instead ([below](#build---docker-and-verify---docker)). |
|
|
807
|
+
| `typesol build <file.ts> [--out <dir>] [--program-id <keypair.json>] [--sbpf …] [--profile] [--toolchain-strict] [--docker …] [--quiet]` | Outside a project (or a file that is not one of its programs): build that file. Its keypair is `--program-id`, which must exist, or `<out>/<name>-keypair.json`, created on the first build. A project program's `.ts` builds as that program. |
|
|
806
808
|
| `typesol check [<program>… \| <file.ts>] [--json] [--stdin \| --files]` | Type-check and validate without building. In a project, no argument checks every program (or those named) and exits 1 if any has errors. `--json` prints `{ ok, diagnostics: [{ file, line, column, message }] }`, always (a missing file or unreadable `--files` input is a diagnostic too, exit 1 or 2); `--stdin` checks the text given on stdin as that file (its imports come from disk); `--files` reads `{ "files": { "<absolute path>": "<text>", … } }` from stdin and checks with those texts instead of the disk (an editor's unsaved buffers). |
|
|
807
809
|
| `typesol clone [<address>…] [--url <rpc>] [--config <cli config>] [--out <dir>]` | Copy cluster accounts and programs for the tests (Anchor's `[test.validator.clone]`): each account to `<address>.json` (lamports, owner, data), each program to `<address>.so` (its ELF, from the ProgramData account for upgradeable programs), in `tests/accounts` (`"accounts"` in `typesol.json`) or `--out`. Without addresses it clones the project's `"clone"` list. `testProgram` loads that directory into its LiteSVM; commit it so the tests run offline. |
|
|
808
810
|
| `typesol emit-c <file.ts> [--out <file.c>] [--profile]` | Print or write the generated C. |
|
|
@@ -812,7 +814,7 @@ error. Exit codes: **0** success, **1** failure (compile errors, failed deploy,
|
|
|
812
814
|
| `typesol cpi <idl.json> [--out <file.ts>] [--prefix <name>] [--address <base58>]` | Generate TypeSOL helpers that call another program from its IDL. Unsupported instructions are listed on stderr. |
|
|
813
815
|
| `typesol port <idl.json> [--out <file.ts>]` | A TypeSOL program skeleton from an Anchor IDL (0.30+/1.x), to port an Anchor program: account structs, enums, errors, events and one function per instruction with its accounts and arguments, each body `require(false, …NotPorted)` until written. Instruction discriminators (an explicit `@discriminator` when the name derives another), account names and error codes are kept, so existing clients keep working where the layouts match; notes on stderr list where they do not (Borsh `String`/`Option` in account data, a `Vec` that is not the last field). Error codes that skip ahead are kept with `@code`, and zero-copy types keep their IDL `repr`, `serialization` and field names (`@repr`, `@serialization`, `@idlName`). |
|
|
814
816
|
| `typesol client <idl.json> [--out <file.ts>] [--address <base58>]`, `typesol client --address <program id> [--url <rpc>] [--config <cli config>] [--out <file.ts>]` | Generate a typed TypeScript client on `@solana/kit` from an Anchor IDL (0.30+/1.x or TypeSOL); the IDL is validated first, and what the client leaves out is printed as notes. Without a file, the IDL is read from the chain: the canonical Program Metadata IDL, else Anchor's IDL account. See [client.md](client.md). |
|
|
815
|
-
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. On a mismatch it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given `.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a program on chain records none). |
|
|
817
|
+
| `typesol verify <program\|file.ts> [<deployed.so>] [--address <program id>] [--url <rpc>] [--config <cli config>] [--sbpf …] [--manifest <name.build.json>] [--docker …]` | Rebuild and compare with what is deployed. Without a `.so`, reads the program from the cluster (`--url`, cluster monikers such as `mainnet-beta` included, else the Solana CLI config) at `--address` or the address `typesol.json` records, under any loader (v2, upgradeable v3, v4); prints the upgrade authority (or that the program is immutable) and the last deploy slot, and compares the IDL published with `typesol idl publish` (a published IDL that differs is a mismatch). With a `.so` (e.g. `solana program dump`), compares with that file. Trailing zero padding is ignored; the SBPF version is read from the deployed ELF unless `--sbpf` is given. On a mismatch it prints the rebuild's toolchain (clang, platform-tools, host, TypeSOL) and the deployed build's when a build manifest's binary hash is the deployed bytes' (`--manifest`, `<deployed>.build.json` next to a given `.so`, or the local build's), and what differs; otherwise it says the deployed side's toolchain is unknown (a program on chain records none). A host difference alone is named as such; it counts only between builds of 0.44.1 or earlier, whose programs with 128-bit or signed division linked platform-tools' compiler-builtins (laid out differently by each host package). `--docker` rebuilds in the pinned container and, on a match, prints what was verified ([below](#build---docker-and-verify---docker)). |
|
|
816
818
|
| `typesol profile <logs.txt\|-> [--program <id>]` | Compute units per TypeScript line from the logs of a `--profile` build's transaction (exit 1 when the logs have no markers). |
|
|
817
819
|
| `typesol help <command>` | Same as `typesol <command> --help`. |
|
|
818
820
|
| `typesol --version` | Print the version. |
|
|
@@ -825,6 +827,33 @@ Builds (`build`, `deploy`, `verify`, `typesol/testing`) compare the active clang
|
|
|
825
827
|
with (`TESTED_TOOLCHAIN` in `typesol/compiler`: Agave 3.1.10, platform-tools v1.52): another one gets one warning per
|
|
826
828
|
process on stderr. `TYPESOL_TOOLCHAIN=strict` makes it an error everywhere, `warn` is the default.
|
|
827
829
|
|
|
830
|
+
## build --docker and verify --docker
|
|
831
|
+
|
|
832
|
+
`--docker` builds in a container made on your machine from `docker/Dockerfile` (shipped in the package): linux/amd64
|
|
833
|
+
on every machine (emulated on arm64), Node 24, the platform-tools v1.52 of Agave 3.1.10, and a TypeSOL version from
|
|
834
|
+
npm whose tarball is checked against `releases/<version>.json` (sha512 integrity, sha1 shasum, every file's sha256)
|
|
835
|
+
before it is installed, with its npm dependencies installed by `npm ci` from `docker/deps/<version>.lock.json` (every
|
|
836
|
+
package checked against the lock's integrity; the package's lock, or the version's own tarball's). Every input is
|
|
837
|
+
pinned by digest, checksum or integrity. The image is `typesol-build:<version>-<first 12
|
|
838
|
+
of the Dockerfile's sha256>`, built the first time it is needed (progress on stderr; about 750 MB of downloads) and
|
|
839
|
+
reused after. Builds run with `--network none`, the sources read-only (the project root, or a single file's
|
|
840
|
+
directory: imports from outside it are not there), the output directory writable, no capabilities, a read-only root
|
|
841
|
+
file system, as your uid and gid (root for a root caller, still without capabilities). The written files are the
|
|
842
|
+
ones `build` writes; `<name>.build.json` adds `container` (platform, Dockerfile sha256, base images, downloads, the
|
|
843
|
+
TypeSOL tarball's hashes and the commit its record names, where the release record came from and the record's sha256,
|
|
844
|
+
the dependency lock with its sha256, the local image id). An image is reused only when its labels carry this
|
|
845
|
+
record's integrity, shasum, commit and file list and this lock's sha256; an image of the same tag made from other
|
|
846
|
+
values is an error that names it (remove it to build from this record).
|
|
847
|
+
|
|
848
|
+
| Option | |
|
|
849
|
+
| --- | --- |
|
|
850
|
+
| `--typesol-version <v>` | The TypeSOL in the container. Default: this `typesol`'s version (in a project that installs another `typesol` than the one running, an error naming both); for `verify`, the version of the deployed build's manifest when one is known (`--manifest`, `<deployed>.build.json`, or the local build's whose binary hash is the deployed one's). |
|
|
851
|
+
| `--release-record <file>` | The record to check that version's tarball against. Default: the package's (a package ships the records of the releases before it: a record is written after its release is published), else `releases/<version>.json` fetched from the repository's main branch over HTTPS (said on stderr; where it came from and the sha256 of its bytes go into `container.typesol.record`), so that the npm tarball is checked against a second, independent source (as with a file given here; a record the package ships came from npm too). Offline, or for a version the repository has no record of, an error names this option. Versions before 0.43.0 have no record and are refused. |
|
|
852
|
+
|
|
853
|
+
Without Docker, with its daemon stopped or when the image build fails, `--docker` is an error and nothing is built;
|
|
854
|
+
it never falls back to the local toolchain. `TYPESOL_DOCKER_CPUS` and `TYPESOL_DOCKER_MEMORY` (e.g. `2`, `4g`) limit
|
|
855
|
+
the build container on a shared machine. Why one platform: [stability.md](stability.md#what-builds-the-same-bytes-where).
|
|
856
|
+
|
|
828
857
|
## typesol.json
|
|
829
858
|
|
|
830
859
|
```json
|
|
@@ -1152,6 +1181,52 @@ version are used. Then the toolchain: verify prints the rebuild's clang and plat
|
|
|
1152
1181
|
when a `<name>.build.json` describes the deployed bytes (`--manifest <file>`, one next to a given `.so`, or the local
|
|
1153
1182
|
build's). A program on chain carries no such record, so keep the build manifest of every deployment.
|
|
1154
1183
|
|
|
1184
|
+
**`--docker needs Docker: docker is not installed` / `the Docker daemon is not running`** — `build --docker` and
|
|
1185
|
+
`verify --docker` run in a container: install Docker, or start Docker Desktop (or `sudo systemctl start docker`).
|
|
1186
|
+
`typesol doctor` has a `docker` row. Nothing is built without it; drop `--docker` to build with your own platform-tools.
|
|
1187
|
+
|
|
1188
|
+
**`docker build of typesol-build:… failed`** — the first `--docker` build makes the image, which needs the network:
|
|
1189
|
+
the base images from Docker Hub, the Agave and platform-tools release files from GitHub, the TypeSOL tarball from npm.
|
|
1190
|
+
A `checksum` error means a downloaded file is not the one the Dockerfile pins (retry; if it persists, report it).
|
|
1191
|
+
`typesol tarball check: integrity …` means the tarball npm served is not the one `releases/<version>.json` records:
|
|
1192
|
+
do not use that version until it is explained. `typesol dependency lock: …` means the lock does not describe the
|
|
1193
|
+
package's dependencies or names a package without a registry integrity; an `EINTEGRITY` error from `npm ci` means a
|
|
1194
|
+
downloaded dependency is not the one the lock records: the same.
|
|
1195
|
+
|
|
1196
|
+
**`the local image typesol-build:… was not built from this release record and dependency lock`** — an image of that
|
|
1197
|
+
tag exists, made from a record or lock with other values (it names them). Two records of one version disagree, so
|
|
1198
|
+
find out which is right before going on; to build from the one given now, `docker image rm` the tag and run again.
|
|
1199
|
+
|
|
1200
|
+
**`no dependency lock for TypeSOL <version>`** — neither this package nor that version's tarball has
|
|
1201
|
+
`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
|
|
1202
|
+
Desktop provides the x86_64 emulation (QEMU or Rosetta); other Docker installs may need `binfmt` for amd64.
|
|
1203
|
+
|
|
1204
|
+
**`no release record for TypeSOL <version>`** / **`could not fetch the release record`** — the container installs only
|
|
1205
|
+
versions whose tarball has a record: the package's own, or `releases/<version>.json` on the repository's main branch,
|
|
1206
|
+
which `--docker` fetches for a release newer than the package. Offline (or behind a proxy that blocks
|
|
1207
|
+
raw.githubusercontent.com), pass the record yourself with `--release-record releases/<version>.json` from a checkout,
|
|
1208
|
+
or choose a version the package records with `--typesol-version`. HTTP 404 means the repository has no record for that
|
|
1209
|
+
version: check that it is a released version. 0.42.0 and earlier have no record.
|
|
1210
|
+
|
|
1211
|
+
**`this project installs typesol X …, but this is typesol Y`** — a `typesol` other than the project's ran `--docker`.
|
|
1212
|
+
Run the project's own (`npx --no-install typesol …`), or say which version to use with `--typesol-version`.
|
|
1213
|
+
|
|
1214
|
+
**`the container build failed … the container sees only <dir>`** — the compiler's error is printed above it. The
|
|
1215
|
+
container mounts only the project root (or a single file's directory): an import from outside it is missing there.
|
|
1216
|
+
|
|
1217
|
+
**`verify` says `differs host`** — the same TypeSOL (0.44.1 or earlier) and toolchain built the two sides on
|
|
1218
|
+
different hosts. That may be the cause if the program has 128-bit or signed division: those versions linked
|
|
1219
|
+
platform-tools' compiler-builtins, which each host package lays out differently. Rebuild on the deployed side's kind
|
|
1220
|
+
of host (or with `--docker`, if the deployed build was one). From 0.45.0 on the host is not a difference between
|
|
1221
|
+
macOS arm64, Linux arm64 and Linux x86_64 (the hosts measured); `differs host (not measured)` means one side was
|
|
1222
|
+
built on another host.
|
|
1223
|
+
|
|
1224
|
+
**A 0.44.x program with division, deployed from macOS or Linux arm64, does not match `verify --docker`** — 0.44.0 and
|
|
1225
|
+
0.44.1 linked platform-tools' compiler-builtins, so a program that calls 128-bit or signed division built to other
|
|
1226
|
+
bytes on each host package; the container is linux/amd64 and gives the Linux x86_64 bytes. What verifies it is a
|
|
1227
|
+
0.44.x install (the version in its `.build.json`) on the same kind of host as the one that built it, without
|
|
1228
|
+
`--docker`: `npx @typesol/cli@0.44.1 verify …` on macOS arm64 for a build made there.
|
|
1229
|
+
|
|
1155
1230
|
**Windows** — not tested; use WSL2 with the Linux Agave CLI.
|
|
1156
1231
|
|
|
1157
1232
|
**Node errors such as `ERR_UNKNOWN_FILE_EXTENSION` or `ERR_REQUIRE_ESM`** — use Node.js 22.12 or newer.
|
|
@@ -1202,11 +1277,17 @@ You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the R
|
|
|
1202
1277
|
|
|
1203
1278
|
**The toolchain you deploy with.** The binary is what the platform-tools' clang makes of the generated C, so the
|
|
1204
1279
|
toolchain is part of what you trust. Deploy with the one TypeSOL is tested with (Agave 3.1.10, platform-tools v1.52;
|
|
1205
|
-
`typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another).
|
|
1280
|
+
`typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another). The host does not
|
|
1281
|
+
matter from 0.45.0 on: with the same TypeSOL and toolchain a program builds to the same bytes on macOS arm64, Linux
|
|
1282
|
+
arm64 and Linux x86_64 (measured over 76 programs for SBPF v0 and 14 for v1 and v2; up to 0.44.1 a program with
|
|
1283
|
+
128-bit or signed division did not, [stability.md](stability.md#what-builds-the-same-bytes-where)). For a program others should be able to verify, build
|
|
1284
|
+
it with `--docker` (step 2) all the same: a pinned linux/amd64 container that anyone can rebuild, so the whole
|
|
1285
|
+
environment is one recipe. Keep
|
|
1206
1286
|
`target/my_app/my_app.build.json` with each deployment, next to the commit you deployed: it records the TypeSOL,
|
|
1207
|
-
TypeScript, clang and platform-tools versions
|
|
1208
|
-
only when it rebuilds with the same TypeSOL version and toolchain
|
|
1209
|
-
|
|
1287
|
+
TypeScript, clang and platform-tools versions, the host, the container when there was one, and the deployed bytes'
|
|
1288
|
+
sha256. Step 6's `verify` matches only when it rebuilds with the same TypeSOL version and toolchain (and, for a program
|
|
1289
|
+
with 128-bit or signed division built with 0.44.1 or earlier, the same kind of host), and on a mismatch `--manifest`
|
|
1290
|
+
with that file shows what differs.
|
|
1210
1291
|
|
|
1211
1292
|
## 1. Create and test
|
|
1212
1293
|
|
|
@@ -1233,6 +1314,54 @@ program's address, and records the address in `typesol.json`.
|
|
|
1233
1314
|
**Back up `target/deploy/my_app-keypair.json` now.** It is not committed (`.gitignore`), and without it you cannot
|
|
1234
1315
|
redeploy to that address.
|
|
1235
1316
|
|
|
1317
|
+
### A build others can verify
|
|
1318
|
+
|
|
1319
|
+
```sh
|
|
1320
|
+
npx --no-install typesol build --docker
|
|
1321
|
+
```
|
|
1322
|
+
|
|
1323
|
+
The same files, built inside a container instead of with your platform-tools. The container is made on your machine
|
|
1324
|
+
from `docker/Dockerfile`, which ships in the package; every input is pinned: the Node and busybox base images by their
|
|
1325
|
+
linux/amd64 digests, the Agave 3.1.10 and platform-tools v1.52 release files by sha256, the TypeSOL package (the
|
|
1326
|
+
version your project uses) by its release record, `releases/<version>.json`: the npm tarball's sha512 integrity and
|
|
1327
|
+
sha1 shasum and every file's sha256, checked before it is installed, and its npm dependencies (TypeScript, the
|
|
1328
|
+
compiler's front end, among them) by that version's lock, `docker/deps/<version>.lock.json`, which `npm ci` installs
|
|
1329
|
+
checking every package's integrity, with no install scripts. The lock of a version ships in the package of that
|
|
1330
|
+
version (and in later ones); the locks of 0.43.0, 0.44.0 and 0.44.1, released before locks existed, were resolved
|
|
1331
|
+
from the npm registry on 2026-11-12, so their integrity values are what the registry served then, not what an image
|
|
1332
|
+
built at their release installed. The first `--docker` build of a TypeSOL version
|
|
1333
|
+
builds the image (about 750 MB of downloads, a few minutes; Docker must be running, `typesol doctor` shows it); later
|
|
1334
|
+
ones take seconds. The build runs with no network, the project mounted read-only, the output directory writable,
|
|
1335
|
+
with no capabilities, as your uid and gid (root for a root caller). `my_app.build.json` then records the container:
|
|
1336
|
+
the platform, the Dockerfile's sha256, the pinned base images and downloads, the TypeSOL tarball's hashes, the commit
|
|
1337
|
+
its release record names, where the record came from (with the record's sha256), the dependency lock and its sha256,
|
|
1338
|
+
and the local image id.
|
|
1339
|
+
|
|
1340
|
+
Deploy that `my_app.so` with the Solana CLI, `solana program deploy target/my_app/my_app.so --program-id
|
|
1341
|
+
target/deploy/my_app-keypair.json --use-rpc` (with your `--url`). What replaces the container build: `typesol deploy`
|
|
1342
|
+
(`--dry-run` included) and `typesol build` without `--docker`, which build again with your local platform-tools and
|
|
1343
|
+
overwrite it; and `npm test` once the program's sources, SBPF version or address changed, which rebuilds it locally
|
|
1344
|
+
and says so (`note: … held a --docker build that is out of date`). What does not: `npm test` while the sources are
|
|
1345
|
+
the ones `my_app.build.json` records and the `.so` is the one it records, on any host: the tests then run the
|
|
1346
|
+
container's binary. After a local build, `typesol build --docker` again before deploying. Commit the source, keep
|
|
1347
|
+
`my_app.build.json`, and publish the commit and that file with the program id.
|
|
1348
|
+
|
|
1349
|
+
The TypeSOL inside the container is the version this `typesol` is, the one your project installs (`npx --no-install
|
|
1350
|
+
typesol`); a global `typesol` of another version than the project's `node_modules/typesol` refuses rather than
|
|
1351
|
+
guess. `--typesol-version <v>` picks another. Only versions with a release record can be installed (0.43.0 and later).
|
|
1352
|
+
A package carries the records of the releases before it, because a release's record is written after it is
|
|
1353
|
+
published; for a release the package does not record (the newest one, or a later one asked for), `--docker` fetches
|
|
1354
|
+
`releases/<version>.json` from the repository's main branch
|
|
1355
|
+
(`https://raw.githubusercontent.com/typesol-lang/typesol/main/releases/<version>.json`, unauthenticated HTTPS), prints
|
|
1356
|
+
where it came from and its sha256, and records both in `my_app.build.json` (`container.typesol.record`). The check is
|
|
1357
|
+
then two independent sources agreeing: the tarball npm serves must be the one the repository's record describes, so a
|
|
1358
|
+
tampered package would have to be matched by a tampered repository. That holds for a fetched record and for a
|
|
1359
|
+
`--release-record` file; for a version whose record ships in the running package, the record came from npm too (in
|
|
1360
|
+
an earlier package), so the check is then against what npm served before. Offline, or when the repository has no
|
|
1361
|
+
record for that version, it is an error that names `--release-record <file>`, which passes the record yourself (from
|
|
1362
|
+
a checkout, `releases/<version>.json`). Between `npm publish` and the commit of the release's record the repository
|
|
1363
|
+
answers HTTP 404: `--release-record` is the way then.
|
|
1364
|
+
|
|
1236
1365
|
## 3. A wallet with SOL
|
|
1237
1366
|
|
|
1238
1367
|
```sh
|
|
@@ -1286,8 +1415,34 @@ npx --no-install typesol verify my_app
|
|
|
1286
1415
|
|
|
1287
1416
|
`verify` rebuilds the program from `programs/my_app.ts`, reads the deployed one at the address in `typesol.json` from
|
|
1288
1417
|
the cluster in your Solana CLI config, and compares the bytes. `match` means anyone with your source and the same
|
|
1289
|
-
TypeSOL version and toolchain gets exactly the program on chain.
|
|
1290
|
-
|
|
1418
|
+
TypeSOL version and toolchain gets exactly the program on chain (from 0.45.0 on, on any of the hosts measured: macOS arm64, Linux arm64, Linux x86_64; with 0.44.1 or earlier, a
|
|
1419
|
+
program with 128-bit or signed division also needs the same kind of host). It also prints the upgrade authority and checks the IDL you published in step 5.
|
|
1420
|
+
|
|
1421
|
+
### Verifying someone else's program
|
|
1422
|
+
|
|
1423
|
+
With the source at the deployed commit, the program id and, ideally, the deployer's `<name>.build.json`:
|
|
1424
|
+
|
|
1425
|
+
```sh
|
|
1426
|
+
git clone <repository> && cd <repository> && git checkout <commit>
|
|
1427
|
+
npx --no-install typesol verify my_app --address <program id> --url mainnet-beta --docker --manifest my_app.build.json
|
|
1428
|
+
```
|
|
1429
|
+
|
|
1430
|
+
`--docker` rebuilds in the same container recipe, built on your machine from the Dockerfile and checked inputs. The
|
|
1431
|
+
TypeSOL version is the deployed build's (from the manifest whose binary hash is the deployed bytes'), or
|
|
1432
|
+
`--typesol-version <v>`; months later, the current `@typesol/cli` installs the old version in the container, checked
|
|
1433
|
+
against its release record. On a match it prints what was verified: the program, the source directory and its git
|
|
1434
|
+
commit (and whether it has uncommitted changes), the TypeSOL version and tarball, the commit its record names and
|
|
1435
|
+
where the record came from, the dependency lock and its sha256, the clang and platform-tools, the container's
|
|
1436
|
+
Dockerfile sha256, base images and downloads, and the command that repeats it (with every option given that changes
|
|
1437
|
+
the result: `--address`, `--url`, `--config`, `--sbpf`, `--manifest`, `--release-record`). A program built with
|
|
1438
|
+
0.44.x on macOS or Linux arm64 that calls 128-bit or signed division does not match a `--docker` rebuild (those
|
|
1439
|
+
versions' binaries depended on the host package; [troubleshooting](troubleshooting.md)). On a mismatch it shows the
|
|
1440
|
+
toolchain of each side that is known, as without `--docker`. Exit codes: 0 match, 3 mismatch.
|
|
1441
|
+
|
|
1442
|
+
What this is not: the container is built locally from pinned inputs, not pulled from a published image, so the first
|
|
1443
|
+
verification downloads the inputs and builds it. Its local image id can differ between machines; the Dockerfile's
|
|
1444
|
+
sha256 and the pinned inputs are what to compare. The result is not registered with an external verified-build
|
|
1445
|
+
registry: the evidence is the command and its output, which anyone can rerun.
|
|
1291
1446
|
|
|
1292
1447
|
## 7. Call it
|
|
1293
1448
|
|
|
@@ -1317,7 +1472,7 @@ auditors, [SECURITY.md](../SECURITY.md) how to report a problem.
|
|
|
1317
1472
|
| --- | --- |
|
|
1318
1473
|
| The program's author | the program's logic: what it allows, to whom, for how much |
|
|
1319
1474
|
| TypeSOL (this repository) | that the binary does what the source and these guarantees say, and nothing an attacker can steer beyond it |
|
|
1320
|
-
| 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 |
|
|
1475
|
+
| The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. The guarantees are tested with one platform-tools release (v1.52, from Agave 3.1.10); a build with another warns, or fails with `--toolchain-strict`, and `<name>.build.json` records which one built a binary and on which host. The compiler builtins (128-bit multiplication, division and shifts, signed 64-bit division) are TypeSOL's own (`runtime/typesol_builtins.c`), compiled with the program; nothing is linked from platform-tools' Rust libraries, whose layout differed by host package, so from 0.45.0 on the programs measured build to the same bytes on macOS arm64, Linux arm64 and Linux x86_64 ([stability.md](stability.md#what-builds-the-same-bytes-where): 76 programs for SBPF v0, 14 for v1 and v2). `--docker` builds pin the whole environment in one linux/amd64 container whose inputs are checked by digest, checksum and integrity (base images, release files, the TypeSOL tarball and every npm dependency) |
|
|
1321
1476
|
| The Solana runtime | account ownership and signer flags as passed, the loader's account serialization, CPI privilege rules, sysvars |
|
|
1322
1477
|
|
|
1323
1478
|
Everything a transaction carries is attacker-controlled: the instruction data, which accounts are passed in which
|
|
@@ -1366,16 +1521,23 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
1366
1521
|
replacing or resizing what a live reference points into is a compile error, as is writing a Vec element with a
|
|
1367
1522
|
right side that may resize the Vec. A helper given a writable struct account may replace anything in it, however
|
|
1368
1523
|
the account is named at the call (a parameter, an account group's field, a struct loaded with `loadAccountMut`): a
|
|
1369
|
-
reference into it read after the call is a compile error.
|
|
1524
|
+
reference into it read after the call is a compile error. Data that moves (a Vec of the account resized, so the
|
|
1525
|
+
Vecs after it shift, or a helper given the account) moves under every name of the account: a reference made
|
|
1526
|
+
through another parameter that may be the same account (a `Dup<…>` pair, a read-only and a writable account of one
|
|
1527
|
+
type, a struct loaded with `loadAccount` / `loadAccountMut`) is held to the same rule. A helper that can write gets its Pubkey, Option and
|
|
1370
1528
|
string arguments as they were at the call (a copy unless nothing it is given reaches them), and a closed account
|
|
1371
1529
|
is not used after `close()` (compile error).
|
|
1372
1530
|
10. **Remaining accounts.** Writing one (`.lamports`, `loadAccountMut`) checks it is writable (3006) and not another
|
|
1373
1531
|
account of the instruction (2040); `loadAccountMut` loads a given account once per instruction (2040);
|
|
1374
1532
|
`loadAccount<T>` checks owner, discriminator and size, and validates the data as instruction arguments are.
|
|
1375
|
-
11. **Growth.** An account grows by at most 10 KiB per instruction (3016),
|
|
1376
|
-
zero and the new rent is paid; shrinking keeps
|
|
1533
|
+
11. **Growth.** An account grows by at most 10 KiB per instruction (3016), counted from its length when the
|
|
1534
|
+
instruction started, the payer is a `Mut<Signer>`, new bytes are zero and the new rent is paid; shrinking keeps
|
|
1535
|
+
the lamports in the account.
|
|
1377
1536
|
12. **CPIs.** A program signs only for its own PDAs (the runtime enforces it; the seeds are those written in the
|
|
1378
|
-
source, with the values they had where the list was written, also for a named list or one given to a helper
|
|
1537
|
+
source, with the values they had where the list was written, also for a named list or one given to a helper; a
|
|
1538
|
+
wrapper's arguments are evaluated left to right, as JS evaluates them, the seeds after the arguments before
|
|
1539
|
+
them). Token-2022 and SPL Token instruction data is laid out as the program reads it (a `COption` key that is
|
|
1540
|
+
None is one byte). `invoke` marks an account writable or signer only when the parameter is `Mut` / `Signer` or the program
|
|
1379
1541
|
signs for it; remaining accounts keep the flags they were passed with, or are checked for the role requested.
|
|
1380
1542
|
`invokeInstruction` is the exception by design: its program, account flags and data come from values (stored in
|
|
1381
1543
|
account data or passed in), so the compiler cannot check them; the runtime does, refusing any account the
|
|
@@ -1398,15 +1560,23 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
1398
1560
|
- **`requirePda(account, seeds, bump)`.** Any valid bump passes (Anchor's `bump = expr`). Use a stored bump, never one
|
|
1399
1561
|
from the arguments.
|
|
1400
1562
|
- **`Dup<…>`.** A parameter marked `Dup` may be the same account as another writable one. Reads see every write
|
|
1401
|
-
(both are the same bytes), so a value read before a write through the other slot is stale: read, then write.
|
|
1563
|
+
(both are the same bytes), so a value read before a write through the other slot is stale: read, then write. (A
|
|
1564
|
+
reference held across a resize through the other slot is a compile error, guarantee 9.)
|
|
1402
1565
|
- **`NATIVE_ACCOUNT_WRITES`.** A program that declares it gives up the up-front writability check and the
|
|
1403
1566
|
one-view-per-account refusal for `loadRawMut`, `storeBorsh` and BigVec writes, as a native program has neither: the
|
|
1404
1567
|
runtime still refuses a changed read-only account, but two loads of one account alias each other. Make the
|
|
1405
1568
|
original's address and type checks before loading.
|
|
1406
1569
|
- **Instruction introspection.** The Instructions sysvar holds what the transaction's author put there. Require things
|
|
1407
1570
|
of the transaction with it (that a repay instruction follows), never treat it as proof of who did what.
|
|
1408
|
-
- **Oracles.** `pythPrice` checks
|
|
1409
|
-
fields are unchecked. `switchboardValue`
|
|
1571
|
+
- **Oracles.** `pythPrice` checks the owner and account type, full verification, the feed id, the age and (when
|
|
1572
|
+
passed) the exponent; the raw `update.*` fields are unchecked. `switchboardValue` checks the owner, the account
|
|
1573
|
+
type, the expected feed, the sample count (`minSamples`, default 1) and staleness, measured in slots from the
|
|
1574
|
+
feed's `result.slot`. Neither checks, and both leave to the author:
|
|
1575
|
+
- the price's sign and zero: a negative or zero price is returned as it is;
|
|
1576
|
+
- the confidence: Pyth's `conf` and Switchboard's spread of samples are not compared with anything;
|
|
1577
|
+
- a publish time (Pyth) or result slot (Switchboard) in the future: it counts as fresh;
|
|
1578
|
+
- rounding: `switchboardValue` scales the 18-decimal result to `decimals` rounding toward zero, and a price scaled
|
|
1579
|
+
by its exponent in the program rounds as that code does.
|
|
1410
1580
|
- **`merkleVerify`.** Leaves and inner nodes hash alike: build leaves as `keccak256(keccak256(data))` in the program.
|
|
1411
1581
|
- **Existing accounts in `createIfNeeded`.** An existing token account's delegate and close authority, and a mint's
|
|
1412
1582
|
extensions the call does not name, are not checked (as in Anchor).
|
|
@@ -1419,6 +1589,25 @@ Each holds for every instruction of every program the compiler accepts. A break
|
|
|
1419
1589
|
- Arithmetic overflow returns an error code (5100) in every build; Anchor aborts the program, and only when
|
|
1420
1590
|
overflow checks are enabled.
|
|
1421
1591
|
|
|
1592
|
+
## Review of 0.44.0 (2026-11-11)
|
|
1593
|
+
|
|
1594
|
+
A second internal review, of 0.44.0, found guarantees 9 and 12 and the token wrappers' instruction data broken in the
|
|
1595
|
+
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
|
|
1596
|
+
sources, 74 build to the same binary with 0.44.1 and 2 to another (mint-close-authority and allow-block-list-token);
|
|
1597
|
+
none is refused. A program was exposed only if it uses the construct a defect names:
|
|
1598
|
+
|
|
1599
|
+
- `mint.create` / `createIfNeeded` with `transferFee` whose config or withdraw authority is `null` or a run-time None
|
|
1600
|
+
(the mint got another fee and no withdraw authority: check the mint), or extensions adding up to 355 bytes (the
|
|
1601
|
+
call always failed);
|
|
1602
|
+
- a `Dup<…>` pair, a read-only and a writable account of one struct type, or a struct loaded with `loadAccount` /
|
|
1603
|
+
`loadAccountMut`, with a reference made through one held across a push, pop or clear (or a helper given the
|
|
1604
|
+
account) through the other, when the transaction passes one account for both;
|
|
1605
|
+
- a token or Stake wrapper call with signer seeds and an argument that runs code (a helper call, an assignment) whose
|
|
1606
|
+
effects the seeds, the amount or a metadata string read;
|
|
1607
|
+
- `updateExtraAccountMetas` after the account was already grown in the same instruction.
|
|
1608
|
+
|
|
1609
|
+
A program that uses none of them was not exposed to these defects; rebuilding it with 0.44.1 gives the same binary.
|
|
1610
|
+
|
|
1422
1611
|
## Review of 0.43.0 (2026-11-11)
|
|
1423
1612
|
|
|
1424
1613
|
An internal review of 0.43.0 found that some of the guarantees above did not hold in every case; the defects are
|
|
@@ -1447,10 +1636,11 @@ exposed to them.
|
|
|
1447
1636
|
|
|
1448
1637
|
## Status
|
|
1449
1638
|
|
|
1450
|
-
The compiler and runtime have had internal security reviews, the latest of 0.
|
|
1451
|
-
0.44.
|
|
1452
|
-
|
|
1453
|
-
|
|
1639
|
+
The compiler and runtime have had internal security reviews, the latest of 0.44.0 (above); its findings are fixed in
|
|
1640
|
+
0.44.1. It was an internal review, not an independent audit; it covered the token, Token-2022, Metaplex and Stake
|
|
1641
|
+
wrappers, the oracles and SBPF v1/v2 builds of the examples that the review of 0.43.0 left out, but not the Metaplex
|
|
1642
|
+
wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows. There has been no
|
|
1643
|
+
external audit: see [audit.md](audit.md).
|
|
1454
1644
|
|
|
1455
1645
|
<!-- docs/ai.md -->
|
|
1456
1646
|
|
|
@@ -1527,9 +1717,12 @@ From 1.0 on, within a major version:
|
|
|
1527
1717
|
|
|
1528
1718
|
- **Sources keep compiling.** A program that compiles with 1.x compiles with every later 1.y, to a program with the same
|
|
1529
1719
|
account layouts, IDL, instruction and account discriminators and error codes. New releases add; they do not take away.
|
|
1530
|
-
- **Binaries are reproducible and only change for a reason.** With the same TypeSOL release and the
|
|
1531
|
-
|
|
1532
|
-
|
|
1720
|
+
- **Binaries are reproducible and only change for a reason.** With the same TypeSOL release and the tested
|
|
1721
|
+
toolchain, a source builds to the same bytes in the build container (`--docker`) as on the hosts measured: from
|
|
1722
|
+
0.45.0 on, macOS arm64, Linux arm64 and Linux x86_64, for the programs and SBPF versions listed
|
|
1723
|
+
[below](#what-builds-the-same-bytes-where).
|
|
1724
|
+
A release that changes the binary of a program that uses none of its new features says so, with the release
|
|
1725
|
+
manifest's diff (`typesol-<version>-binary-diff.txt`) as the evidence.
|
|
1533
1726
|
- **The checks stay.** No check a program gets from its parameter types (owner, discriminator, signer, writability,
|
|
1534
1727
|
aliasing, checked arithmetic, constraints) is removed or weakened.
|
|
1535
1728
|
- **The tools keep their interfaces**: `typesol build`, `test` (via `typesol/testing`), `check --json`, `deploy`,
|
|
@@ -1562,10 +1755,66 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
|
|
|
1562
1755
|
- **A build says what made it.** `<name>.build.json` records the TypeSOL, TypeScript, clang and platform-tools versions,
|
|
1563
1756
|
the host, the SBPF version and the sha256 of every source and of the binary. `typesol verify` uses it to say, on a
|
|
1564
1757
|
mismatch, whether the toolchains differ. A program on chain records none of this: keep the file with the deployment.
|
|
1758
|
+
- **A deployed program anyone can rebuild.** `typesol build --docker` builds in a container made from
|
|
1759
|
+
`docker/Dockerfile` (in the package), whose inputs are all pinned: base images by digest, the Agave and
|
|
1760
|
+
platform-tools release files by sha256, the TypeSOL tarball by its `releases/<version>.json`. `typesol verify
|
|
1761
|
+
--docker` rebuilds there and says what it verified. The image is built locally from those inputs; no image is
|
|
1762
|
+
published, and the result is not registered with any external verified-build registry
|
|
1763
|
+
([docs/mainnet.md](mainnet.md#6-verify)).
|
|
1565
1764
|
- **Fixes come as patches of the latest minor.** From 0.44.0 on, a release that only fixes soundness or security
|
|
1566
1765
|
defects is a patch (0.44.1, …) with no new language surface, and its notes carry the binary diff against the
|
|
1567
1766
|
previous release ([SECURITY.md](../SECURITY.md#fix-releases)). Older minors are not maintained.
|
|
1568
1767
|
|
|
1768
|
+
## What builds the same bytes where
|
|
1769
|
+
|
|
1770
|
+
From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with this release's
|
|
1771
|
+
compiler and platform-tools v1.52 on macOS arm64 (the platform-tools `osx-aarch64` package, native), Linux arm64 and
|
|
1772
|
+
Linux x86_64 (the `linux-aarch64` and `linux-x86_64` packages, in containers; x86_64 is the `--docker` image): for
|
|
1773
|
+
SBPF v0 (the default), the 76 programs of the sources (`scripts/release-manifest.ts`, every program under `examples/`
|
|
1774
|
+
and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault, escrow, multisig
|
|
1775
|
+
and the 10 below).
|
|
1776
|
+
|
|
1777
|
+
| What | Same on the three hosts? |
|
|
1778
|
+
| --- | --- |
|
|
1779
|
+
| The generated C and the IDL (all 76) | yes |
|
|
1780
|
+
| The binary, SBPF v0 (all 76) | yes |
|
|
1781
|
+
| The binary, SBPF v1 and v2 (the 14) | yes |
|
|
1782
|
+
| 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 |
|
|
1783
|
+
| 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 |
|
|
1784
|
+
|
|
1785
|
+
The 10 are the programs that call 128-bit or signed 64-bit division (the Phoenix, Marginfi, Raydium AMM, CLMM and
|
|
1786
|
+
CP-Swap, Jito priority-fee and Stake Pool ports, transfer-fee, token-fundraiser, token-swap). With 0.44.1 each of them
|
|
1787
|
+
built to three different binaries on the three hosts (token-fundraiser: the two Linux ones agreed). The cause was one
|
|
1788
|
+
library: platform-tools' SBF `compiler-builtins` Rust library (`libcompiler_builtins-<hash>.rlib`, a different file in
|
|
1789
|
+
each host package). Its functions have the same instructions in the three packages (compared function by function for
|
|
1790
|
+
SBPF v0, v1 and v2), but each package splits them into differently numbered archive members, so the linker placed the
|
|
1791
|
+
ones a division pulls in (`__udivti3`, its shared `u128_div_rem`, `__ashlti3`, `__lshrti3`, …) in another order, and
|
|
1792
|
+
the program's calls into them had other offsets. Programs that called at most `__multi3` linked one member and agreed.
|
|
1793
|
+
|
|
1794
|
+
TypeSOL now links none of that library: `runtime/typesol_builtins.c` defines every builtin the tested clang calls for
|
|
1795
|
+
C integer code on SBF (`__multi3`, `__udivti3`, `__umodti3`, `__divti3`, `__modti3`, `__ashlti3`, `__lshrti3`, `__ashrti3`, `__divdi3`,
|
|
1796
|
+
`__moddi3`) and is compiled with each program, by the same clang, and linked after it. Multiplication and shifts are
|
|
1797
|
+
the instructions compiler-builtins has for them, so on SBPF v0 programs that use only those keep their bytes;
|
|
1798
|
+
division is new C that costs no more compute units than compiler-builtins' on any input measured, and fewer on most
|
|
1799
|
+
(`test/language/builtins.test.ts`). On SBPF v1, `__multi3` (128-bit multiplication, which checked 64-bit
|
|
1800
|
+
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),
|
|
1801
|
+
so a v1 program that
|
|
1802
|
+
multiplies that way builds to other bytes than with 0.44.1 (every one of the 14 measured does); SBPF v2 multiplies
|
|
1803
|
+
with its own instructions and calls no `__multi3`, and its signed 64-bit division is an instruction too, which is
|
|
1804
|
+
why token-fundraiser keeps its v2 bytes.
|
|
1805
|
+
libc's `memcpy` and `memset` still come from platform-tools; the programs that link them build the same on the three
|
|
1806
|
+
hosts. Nothing in the emitted C, the paths or the build directory reaches the binary.
|
|
1807
|
+
|
|
1808
|
+
The reference environment stays one platform, so that the whole environment is one recipe: the build container is
|
|
1809
|
+
`linux/amd64` on every machine (emulated on arm64 hosts). CI checks on every change that a Linux x86_64 runner with
|
|
1810
|
+
independently installed platform-tools builds the programs of `test/golden/binaries.json` (the 14 for SBPF v0, and
|
|
1811
|
+
counter, escrow, Phoenix and Marginfi for v1 and v2) to the container's bytes; that is the same host package as the
|
|
1812
|
+
container's, installed separately. The macOS workflow (on demand) runs the same check on macOS arm64, and anyone can
|
|
1813
|
+
run it on another host, binary included. `<name>.build.json` records the host; `typesol verify` counts a host
|
|
1814
|
+
difference between builds made before 0.45.0 (which linked compiler-builtins: a possible cause if the program uses
|
|
1815
|
+
128-bit or signed division), and between later builds only when one of the hosts is not among the three measured
|
|
1816
|
+
(`host (not measured)`).
|
|
1817
|
+
|
|
1569
1818
|
## Experimental
|
|
1570
1819
|
|
|
1571
1820
|
Useful today, but may still change before 1.0 (each change listed in the CHANGELOG):
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typesol/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "Compile a TypeScript-syntax language directly to Solana SBF programs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,6 +58,8 @@
|
|
|
58
58
|
"CHANGELOG.md",
|
|
59
59
|
"SECURITY.md",
|
|
60
60
|
"docs",
|
|
61
|
+
"docker",
|
|
62
|
+
"releases",
|
|
61
63
|
"llms.txt",
|
|
62
64
|
"llms-full.txt"
|
|
63
65
|
],
|