@typesol/cli 0.47.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +299 -0
  2. package/NOTICE +17 -0
  3. package/README.md +106 -37
  4. package/SECURITY.md +5 -0
  5. package/dist/compiler/emit/base.d.ts +12 -4
  6. package/dist/compiler/emit/base.js +19 -5
  7. package/dist/compiler/emit/calls.js +59 -1
  8. package/dist/compiler/emit/cpi.js +3 -1
  9. package/dist/compiler/emit/expressions.js +3 -1
  10. package/dist/compiler/emit/function.js +7 -2
  11. package/dist/compiler/emit/program.js +9 -4
  12. package/dist/compiler/emit/statements.d.ts +29 -2
  13. package/dist/compiler/emit/statements.js +149 -6
  14. package/dist/compiler/emit/storage.js +8 -3
  15. package/dist/compiler/emit/token.js +18 -1
  16. package/dist/compiler/hints.js +3 -0
  17. package/dist/compiler/toolchain.js +1 -0
  18. package/dist/idl-coder.d.ts +21 -2
  19. package/dist/idl-coder.js +42 -4
  20. package/dist/testing.d.ts +14 -3
  21. package/dist/testing.js +87 -17
  22. package/docker/deps/0.48.0.lock.json +1206 -0
  23. package/docker/deps/0.49.0.lock.json +1206 -0
  24. package/docs/architecture.md +2 -2
  25. package/docs/audit.md +31 -15
  26. package/docs/case-study-escrow.md +7 -5
  27. package/docs/case-study-marginfi.md +15 -2
  28. package/docs/case-study-multisig.md +2 -1
  29. package/docs/case-study-raydium-amm.md +2 -1
  30. package/docs/case-study-spl-stake-pool.md +4 -3
  31. package/docs/language-accounts.md +5 -6
  32. package/docs/language-basics.md +2 -1
  33. package/docs/language-builtins.md +5 -1
  34. package/docs/language-chain.md +13 -1
  35. package/docs/language-cpi.md +26 -0
  36. package/docs/language-errors-events.md +16 -1
  37. package/docs/language-native.md +23 -3
  38. package/docs/language-statements.md +4 -2
  39. package/docs/language.md +2 -2
  40. package/docs/mainnet.md +1 -1
  41. package/docs/runtime.md +7 -0
  42. package/docs/security-model.md +11 -4
  43. package/docs/stability.md +9 -4
  44. package/docs/test-your-program.md +43 -4
  45. package/docs/testing.md +16 -4
  46. package/docs/troubleshooting.md +1 -1
  47. package/lib/typesol.d.ts +46 -1
  48. package/llms-full.txt +164 -34
  49. package/llms.txt +2 -1
  50. package/package.json +3 -3
  51. package/releases/0.47.0.json +837 -0
  52. package/releases/0.48.0.json +847 -0
  53. package/runtime/typesol_rt.h +276 -1
@@ -32,9 +32,9 @@ program.so + program.build.json (manifest: versions, sha256 of sources and binar
32
32
  | `ts-plugin/` | The editor plugin (`typesol/ts-plugin`) |
33
33
  | `examples/` | Example programs; the `typesol init` templates are copies of three of them |
34
34
  | `test/` | The compiler's test suite (`pnpm test:core`), by subject: `language/`, `security/`, `examples/`, `integrations/` (token, Metaplex, oracle and other CPIs), `client/`, `cli/`, `verification/` (differential and fuzz tests). Shared: `harness.ts` and the `*-helpers.ts`, `fixtures/` (programs the tests compile), `golden/` (pinned generated C and clients, and what 14 programs build to in the build container: SBPF v0, and v1 and v2 for four of them), `programs/` (third-party program binaries, see its SOURCES.md), `anchor-twins/` (below) |
35
- | `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, CP-Swap and CLMM, Jito's MEV programs, Marginfi, coral-xyz/multisig, each checked against the binary on mainnet), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
35
+ | `showcase/` | Ports, apart from the compiler's own tests (`pnpm test:showcase`, its own CI job): `mainnet/` (Phoenix v1, SPL Stake Pool, Raydium AMM v4, CP-Swap and CLMM, Jito's MEV programs, Marginfi, Percolator v12.20, coral-xyz/multisig, each checked against the binary on mainnet, and Meteora DBC 0.2.2, under Meteora's Non-commercial Licence and compared without its log text and compute units), `program-examples/` (TypeSOL rewrites of solana-developers/program-examples), `test/` (their differential tests, fuzzers, helpers and fixtures; `porting/` for the program-examples) |
36
36
  | `test/anchor-twins/` | Anchor twins of the counter, vault and escrow examples, for the differential tests (`pnpm build:twins`) and the zero-copy client test; the benchmarks themselves are in [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) |
37
- | `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`), `language-builtins.ts` (`docs/language-builtins.md`, generated from `lib/typesol.d.ts`; `--check` in CI) |
37
+ | `scripts/` | `smoke.ts`, `localnet.sh` and `localnet-fixtures.ts` (a local validator run), `fetch-programs.sh` (third-party binaries), `readme-bench.ts` (the README numbers), `codegen-snapshot.ts` (the generated C and IDL of every program, to diff a refactor), `release-manifest.ts` (a release's binary, IDL and toolchain hashes; the cross-host check against `test/golden/binaries.json`), `language-builtins.ts` (`docs/language-builtins.md`, generated from `lib/typesol.d.ts`; `--check` in CI), `percolator-author-suite.sh` (the Percolator author's own test suite against the mainnet binary and the port) |
38
38
  | `docker/` | The Dockerfile of the `--docker` build container |
39
39
  | `releases/` | Each release's npm tarball record (`scripts/release-check.ts`); shipped, so `--docker` can check the tarball it installs |
40
40
  | `docs/` | User and contributor documentation (also published on typesol.com) |
package/docs/audit.md CHANGED
@@ -1,28 +1,29 @@
1
1
  # Audit package
2
2
 
3
3
  For a security firm reviewing TypeSOL. TypeSOL compiles a subset of TypeScript to C and then to Solana SBF; every
4
- program it builds includes one C runtime header. The question for an audit is whether a program compiled by TypeSOL
4
+ program it builds includes one C runtime header and, from 0.45.0 on, links one C file of compiler builtins. The question for an audit is whether a program compiled by TypeSOL
5
5
  can be made to do something its source and [the security model](security-model.md) say it cannot. Programs written
6
6
  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.45.0 (November 2026).
10
+ In order of priority. Line counts at 0.49.0 (November 2026).
11
11
 
12
12
  | Priority | Component | Files | Lines | Why |
13
13
  | --- | --- | --- | ---: | --- |
14
- | 1 | C runtime | `runtime/typesol_rt.h` | 2,998 | 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` | 876 | 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` | 3,867 | 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` | 5,711 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
14
+ | 1 | C runtime | `runtime/typesol_rt.h` | 3,273 | 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 | Compiler builtins | `runtime/typesol_builtins.c` | 484 | Compiled and linked with every program (0.45.0): the functions clang calls for 128-bit multiplication, division and shifts and signed 64-bit division (`__multi3`, `__udivti3`, `__divti3`, `__divdi3`, …), in place of platform-tools' compiler-builtins |
16
+ | 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 886 | Which checks each account parameter gets, and their order |
17
+ | 1 | Account data, Vecs and assignment | `src/compiler/emit/alias.ts`, `storage.ts`, `statements.ts`, `base.ts` | 4,027 | Reads and writes of account data, growable Vec layout and resizing, references and aliasing, closure and helper expansion |
18
+ | 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,781 | Built-ins, remaining accounts, `invoke` / `invokeInstruction` and their account flags, signer seeds, token CPIs, account creation |
18
19
  | 1 | Raw views and the red-black tree | `src/compiler/emit/views.ts`, `rbtree.ts` | 655 | Accounts read without a discriminator at run-time offsets (`loadRaw`, `loadRawAt`, `rawArrayAt`, `BigVec`), their bounds, and the red-black tree's node indexes (`rbTreeAt`) |
19
20
  | 1 | Metaplex CPIs | `src/compiler/emit/metaplex.ts` | 1,465 | Token Metadata, Core and Bubblegum instruction layouts and their account lists |
20
- | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,168 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
21
+ | 1 | Expressions | `src/compiler/emit/expressions.ts`, `shared.ts`, `borsh.ts` | 2,170 | Checked arithmetic and casts, Borsh encoding of arguments and `@layout borsh` accounts |
21
22
  | 2 | Front end | `src/compiler/analyze.ts`, `model.ts` | 3,545 | What the language accepts; constraints and account types as parsed from the source |
22
23
  | 2 | Interface | `src/compiler/idl.ts`, `src/tools/clientgen.ts` | 2,460 | The IDL and the generated client must describe the program exactly (a mismatch can make clients sign the wrong thing) |
23
24
  | 3 | Build and tooling | `src/compiler/toolchain.ts`, `src/cli.ts`, `src/workspace.ts`, `src/tools/` | | Build flags, deploy and verification commands |
24
25
 
25
- The language surface is `lib/typesol.d.ts` (2,626 lines): every type and built-in a program can use, with its
26
+ The language surface is `lib/typesol.d.ts` (2,671 lines): every type and built-in a program can use, with its
26
27
  documented behavior. [docs/language.md](language.md) is the reference; [docs/architecture.md](architecture.md) maps
27
28
  the code, [docs/runtime.md](runtime.md) the runtime's conventions.
28
29
 
@@ -33,7 +34,8 @@ one warn, and the review of 0.43.0 traced one defect to how that backend passes
33
34
  host package mattered too, up to 0.44.1: its compiler-builtins library, which each of the macOS, Linux arm64 and
34
35
  Linux x86_64 packages lays out differently, made a program with 128-bit or signed division link to different bytes on
35
36
  each. From 0.45.0 on the builtins are TypeSOL's own C, compiled with the program, and the programs measured build to
36
- the same bytes on the three hosts (the 76 of the sources for SBPF v0, 14 for v1 and v2;
37
+ the same bytes on the three hosts (measured with 0.45.0: the 76 programs then in the sources for SBPF v0, 14 for v1
38
+ and v2;
37
39
  [stability.md](stability.md#what-builds-the-same-bytes-where)). The reference environment for binaries is the
38
40
  `--docker` build container (`docker/Dockerfile`, linux/amd64; base images by digest, release files by sha256, the
39
41
  TypeSOL tarball by its release record and its npm dependencies by a lock whose every integrity `npm ci` checks), which
@@ -62,6 +64,15 @@ accepts. Areas where a bug would be most damaging, and where earlier internal re
62
64
  Internal reviews, by the maintainers: none of them is an independent audit. Their findings and fixes are in the
63
65
  CHANGELOG.
64
66
 
67
+ ### Not reviewed: 0.45.0 and later
68
+
69
+ 0.45.0 to 0.49.0 have had no security review. They add, among others,
70
+ `runtime/typesol_builtins.c` (the compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`,
71
+ `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), and `zeroData`, `log64`,
72
+ `PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
73
+ `NATIVE_ACCOUNT_WRITES` (0.49.0). An external review should include them
74
+ with the areas the reviews below left out.
75
+
65
76
  ### 0.44.0 (2026-11-11)
66
77
 
67
78
  A second internal review, of 0.44.0 as published, over the areas the review of 0.43.0 left out: the token,
@@ -168,11 +179,16 @@ since it skips the account checks Anchor-style parameters get, and the areas the
168
179
  Marginfi's I80F48 against vectors the `fixed` crate wrote; honest and hostile action sequences against state models
169
180
  with value conservation; account layout with two growable Vecs and aliasing through remaining accounts. Each run
170
181
  prints its seed (`FUZZ_SEED`), `pnpm fuzz` runs them wide.
171
- - **Random transactions against mainnet binaries**: Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`),
172
- Marginfi's administration and interest (`showcase/test/fuzz-marginfi.test.ts`) and Raydium CLMM (the `fuzz:`
173
- case of its differential test) take random sequences of honest and hostile
174
- transactions, in the original and the port alike, with the same outcome, account bytes and events required after
175
- every step. A new seed on every run, CI's included.
182
+ - **Random transactions against mainnet binaries**: random sequences of honest and hostile transactions go to the
183
+ original and the port alike, with the same outcome, account bytes and events required after every step (and the log
184
+ lines, for the native ports), in Jito's three MEV programs (`showcase/test/fuzz-jito.test.ts`), Marginfi's
185
+ administration and interest (`showcase/test/fuzz-marginfi.test.ts`), Raydium CLMM and CP-Swap (the `fuzz:` case of
186
+ each differential test), SPL Stake Pool (`spl-stake-pool-fuzz.test.ts`) and Meteora DBC
187
+ (`meteora-dbc-fuzz.test.ts`, `meteora-dbc-migration-fuzz.test.ts`): each takes a new seed from the clock on every
188
+ run, CI's included, and prints it. Phoenix (`phoenix-fuzz.test.ts`: seeds 1, 2 and 3), Percolator
189
+ (`percolator-fuzz.test.ts`: seeds 1 to 6 and two per oracle shape) and Raydium AMM v4 (the last case of its
190
+ differential test: seed 7) walk fixed seeds, the same in CI, unless `FUZZ_SEED` names another
191
+ ([testing.md](testing.md)).
176
192
  - **Ported programs**: all 46 programs of solana-developers/program-examples, run through their original tests' flows
177
193
  and failure paths ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)).
178
194
  - **Four-way comparison**: [typesol-lang/benchmarks](https://github.com/typesol-lang/benchmarks) runs 17 of those programs in
@@ -184,7 +200,7 @@ since it skips the account checks Anchor-style parameters get, and the areas the
184
200
  ```sh
185
201
  git clone https://github.com/typesol-lang/typesol && cd typesol
186
202
  pnpm install && pnpm build
187
- pnpm fetch:programs # Metaplex binaries for the token-metadata, Core and Bubblegum tests
203
+ pnpm fetch:programs # third-party binaries not kept in the repository: Metaplex, Kamino, JupLend, Meteora, …
188
204
  pnpm build:twins # the Anchor twins (Rust + Anchor 1.0.2)
189
205
  pnpm test # everything; CI runs it on Ubuntu (Node 22, 24) per change, macOS on demand (macos.yml)
190
206
  pnpm fuzz # the randomized checks, wide
@@ -191,16 +191,18 @@ 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-lang/benchmarks (TypeSOL at this version; Anchor 1.0.2). Lower is better.
194
+ program size, from typesol-lang/benchmarks (`results.json`, `official`: measured with TypeSOL 0.48.0 and Anchor 1.0.2
195
+ on 2026-11-14). Lower is better.
195
196
 
196
197
  | | TypeSOL | Anchor | Native Rust | Pinocchio |
197
198
  | --- | ---: | ---: | ---: | ---: |
198
- | make_offer | **19,697** | 35,726 | 33,206 | 20,581 |
199
- | take_offer | **7,053** | 29,235 | 24,995 | 21,606 |
199
+ | make_offer | **19,683** | 35,726 | 33,206 | 20,581 |
200
+ | take_offer | **7,054** | 29,235 | 24,995 | 21,606 |
200
201
  | refund_offer | **4,271** | 15,326 | 12,477 | 8,137 |
201
- | Binary | 32.0 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
202
+ | Binary | 32.1 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
202
203
 
203
- Most of `make_offer` in every version is the Associated Token Account program creating the vault. The native and
204
+ Much of `make_offer` in every version is the Associated Token Account program creating the vault (13,480 to
205
+ 22,480 CU a call in the mainnet transactions the README links), most of it in TypeSOL's and Pinocchio's. The native and
204
206
  Pinocchio versions are teaching code with fewer checks (no owner or type check on the offer, `Transfer` instead of
205
207
  `TransferChecked`; Pinocchio takes the offer's bump from the client).
206
208
 
@@ -472,7 +472,7 @@ circuit-breaker halt, a frozen bank, the fee state's pause, an account's flags a
472
472
 
473
473
  There are 244 transactions in that file, 174 in
474
474
  [`showcase/test/marginfi-oracle.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/marginfi-oracle.test.ts)
475
- for the oracles, and 1,022 in
475
+ for the oracles, and 1,032 in
476
476
  [`showcase/test/marginfi-risk.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/marginfi-risk.test.ts)
477
477
  for withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine. The last two write Pyth and Switchboard accounts byte for
478
478
  byte into both ledgers:
@@ -521,7 +521,7 @@ byte into both ledgers:
521
521
  window walked up and down with its anchor creeping after it ran out, a reference at the floor reseeded, a tier past
522
522
  3 in raw state (a panic).
523
523
 
524
- - **Withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine (1,022, with the deposits they start from).** Part of a deposit, more than it, from a bank without a balance, by
524
+ - **Withdrawals, borrows, health pulses, liquidation records, bankruptcy, liquidation, receivership, deleverage, flash loans, account, group and fee state administration, bank administration and the risk engine (1,032, with the deposits they start from).** Part of a deposit, more than it, from a bank without a balance, by
525
525
  another signer, to the wrong mint, from disabled and frozen accounts, paused and reduce-only banks; the health
526
526
  accounts left out, short an oracle, out of order, with extras; healthy and unhealthy after; a stale liability
527
527
  oracle (fails) and a stale collateral oracle (skipped, recorded), an undecodable collateral oracle (skipped,
@@ -589,6 +589,18 @@ byte into both ledgers:
589
589
  fraction left, only the fraction, more than the vault holds); super-admin moves (by someone else, on the mainnet
590
590
  build).
591
591
 
592
+ The integration banks have five files of their own, each with the other program's mainnet binary (or its accounts)
593
+ loaded beside both: `marginfi-lst.test.ts` (98 transactions: staked SOL banks priced at a single pool's rate),
594
+ `marginfi-venues.test.ts` (150: Solend banks over Solend's program), `marginfi-kamino.test.ts` (237: Kamino banks over
595
+ klend and kfarms), `marginfi-drift.test.ts` (185: Drift banks over Drift v2) and `marginfi-juplend.test.ts` (201:
596
+ JupLend banks over its lending, liquidity and rewards programs). The Kamino and JupLend binaries are under the Business
597
+ Source License and fetched, not kept (`pnpm fetch:programs`); without them those two files skip.
598
+
599
+ In all, a test run compares 2,321 transactions with the mainnet binary in eight files: 244 + 174 + 1,032 in the three
600
+ above and 98 + 150 + 237 + 185 + 201 in the venue files (1,883 when the Kamino and JupLend binaries are absent).
601
+ `marginfi-state.test.ts` checks the port's account types against the on-chain IDL and the mainnet accounts, and sends
602
+ no transactions to the binary.
603
+
592
604
  Besides these, [`showcase/test/fuzz-marginfi.test.ts`](https://github.com/typesol-lang/typesol/blob/main/showcase/test/fuzz-marginfi.test.ts)
593
605
  sends random sequences of the same instructions: random bank configs and curves (most valid, some broken in one
594
606
  way), fees, balances across scales, clock jumps, frozen banks, circuit-breaker settings and halts, accounts opened and
@@ -609,6 +621,7 @@ end index now and then wrong. The keys come from the seed too (the order of keys
609
621
  reproduces a run exactly.
610
622
  Every step must match. Inputs the original panics on (a negative fee rate trips its asserts) only have to fail in the
611
623
  port too. Each run takes a new seed, CI's included; `FUZZ_SEED=<seed>` reproduces one, `FUZZ_STEPS=<n>` lengthens it.
624
+ At the default 150 steps a run compares about 160 more transactions (161 in one run), not counted in the 2,321.
612
625
 
613
626
  ## Differences
614
627
 
@@ -103,7 +103,8 @@ existing clients and existing accounts work with the port unchanged.
103
103
  another, both at `msigUdDB…`, then sends each transaction to both. After each one it requires the same outcome (success,
104
104
  or the same error down to the code) and the same lamports, owner and data bytes for every account involved.
105
105
 
106
- There are 52 transactions:
106
+ There are 55 transactions (8 in the upstream flow, 11 in the `create_multisig` refusals, 14 in the other refusals,
107
+ 12 in the owner-set changes, 7 in the payouts, 3 with the 40-owner account):
107
108
 
108
109
  - **The upstream test suite** (`tests/multisig.js`): create a 2-of-3 multisig, propose `set_owners`, approve, and
109
110
  execute through the PDA. Then `Assert Unique Owners` (6008).
@@ -54,7 +54,8 @@ account forms; refusals (slippage, more than held, zero, the whole pool out, wro
54
54
  as the user's account, a wrong token program); deposits on either side with and without the minimum, withdrawals with
55
55
  and without minimums, amounts past u64; status, state, fees and open time changes and their refusals; the P&L taken by
56
56
  the P&L owner after the pool grew; config creation and updates; the retired tags; excess lamports; and a random mix of
57
- swaps, deposits and withdrawals (`FUZZ_SEED`, `FUZZ_STEPS`). 484 transactions in all at 400 fuzz steps.
57
+ swaps, deposits and withdrawals (`FUZZ_SEED`, `FUZZ_STEPS`). A default run compares 144 transactions: 84 fixed ones and 60 random steps (seed 7
58
+ unless `FUZZ_SEED` names another); 484 at 400 random steps.
58
59
 
59
60
  ## Differences
60
61
 
@@ -58,9 +58,10 @@ to the same C as before):
58
58
  The mainnet binary and the port run in two LiteSVMs under the same program id, with the same clock and the same
59
59
  StakeHistory written into both by one `StakeCluster`. Every transaction must give the same outcome, the same log
60
60
  lines (the "Instruction: …" lines, every message with its numbers, the error lines, panic locations) and the same
61
- bytes in every account it names. There are 2,107 such transactions in six files:
61
+ bytes in every account it names. There are 2,107 such transactions in five files (the random walk below comes on
62
+ top):
62
63
 
63
- - **The instructions** (`spl-stake-pool.test.ts`, `-stake`, `-rebalance`, `-metadata`; 1,406): every instruction's
64
+ - **The instructions** (`spl-stake-pool.test.ts` 505, `-stake` 274, `-rebalance` 360, `-metadata` 267; 1,406): every instruction's
64
65
  success paths and every refusal that can be built, account by account (wrong signers, PDAs, owners, mints and
65
66
  Token-2022 extensions, sysvars, short account lists), fee limits, slippage, preferred validators, funding
66
67
  authorities, read-only and repeated accounts (the original's RefCell panics included), pools of 50 to 60 validators,
@@ -71,7 +72,7 @@ bytes in every account it names. There are 2,107 such transactions in six files:
71
72
  - **A random walk over epochs** (`spl-stake-pool-fuzz.test.ts`): validators added and removed, users depositing and
72
73
  withdrawing SOL and stake, rebalancing, updates in random chunks, fee and authority changes, rewards, slow warmup,
73
74
  and invalid inputs at a low rate (`FUZZ_SEED`, `STAKE_POOL_FUZZ_STEPS`). Five seeds of 600 steps (215 epochs, about
74
- 3,700 transactions) found no difference. Each run is 1,000 steps by default and requires every main kind of
75
+ 3,700 transactions) found no difference. Each run is 1,000 steps by default, with a new seed each time, and requires every main kind of
75
76
  instruction (SOL and stake deposits and withdrawals, increases, decreases, both updates, adding a validator) to
76
77
  succeed at least once.
77
78
 
@@ -188,8 +188,8 @@ export interface Log {
188
188
  entries: u64;
189
189
  }
190
190
 
191
- export function grow(payer: Mut<Signer>, log: Mut<Log>, systemProgram: SystemProgram, size: u64): void {
192
- realloc(log, size, payer);
191
+ export function grow(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">, systemProgram: SystemProgram, size: u64): void {
192
+ realloc(log, size, owner);
193
193
  }
194
194
 
195
195
  export function remove(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">): void {
@@ -201,9 +201,8 @@ export function remove(owner: Mut<Signer>, log: HasOne<Mut<Log>, "owner">): void
201
201
  account) and its data is zeroed. The account is not used after it in the function, except its `key` (compile
202
202
  errors, or 2040 at run time in a helper given one account twice). `CloseTo<A, "dest">` does the same when the
203
203
  instruction succeeds ([constraints](#constraints)).
204
- - Who may call them: the lamports of a closed account are value, so `HasOne` above lets only the log's owner close it.
205
- `grow` moves no value out of the account (growing charges the payer, shrinking keeps the lamports in it), so it is
206
- left open here; restrict it too if the extra bytes, or their absence, matter to your program.
204
+ - Who may call them: `HasOne` above lets only the log's owner close it (the lamports of a closed account are value)
205
+ or resize it. Without that check anyone could pay to grow, or shrink, another user's account.
207
206
  - `realloc(account, newSize, payer)` on a `Mut<Struct>`: growing charges the payer the extra rent (at most 10 KiB per
208
207
  instruction, 3016); shrinking keeps the lamports in the account; never below the struct. Refused on a struct with a
209
208
  growable `Vec` (its push / pop / clear size the account).
@@ -398,7 +397,7 @@ export function count(tally: Mut<Tally>): void {
398
397
  `remainingAccounts()` gives the accounts passed after the declared ones, in order.
399
398
 
400
399
  - `.length`, `.get(i)` (5104 past the end) → `key`, `owner`, `lamports` (writes check writability, 3006), `isSigner`,
401
- `isWritable`, the data length and data.
400
+ `isWritable`, `executable`, the data length and data.
402
401
  - `loadAccount<T>(acct)` / `loadAccountMut<T>(acct)` give checked struct views (owner, discriminator and size, as
403
402
  `Account<T>` / `Mut<T>`), also of an `AccountInfo` parameter (Anchor's `AccountLoader::try_from` on an
404
403
  `UncheckedAccount`).
@@ -278,7 +278,8 @@ export function setup(config: Mut<Config>): void {
278
278
  other than its accounts.
279
279
  - A few names configure the compiler: `HEAP_SIZE_KIB` ([below](#memory-stack-and-heap)), `MAX_ACCOUNTS`
280
280
  ([accounts](language-accounts.md#how-many-accounts)), `NATIVE_ACCOUNT_WRITES`, `PANIC_ON_OVERFLOW`, `PANIC_STYLE`,
281
- `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)).
281
+ `ERROR_LOG_PREFIX`, `PROGRAM_ERROR_LOG_PREFIX` ([native programs](language-native.md)), `EVENT_AUTHORITY_CHECK`
282
+ ([events through CPI](language-errors-events.md#events-through-cpi)).
282
283
 
283
284
  ## Type aliases
284
285
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- Generated by scripts/language-builtins.ts from lib/typesol.d.ts; do not edit by hand. -->
4
4
 
5
- Every name `"typesol"` exports (216 names, 229 declarations), grouped, with its declaration and the first sentence of its doc
5
+ Every name `"typesol"` exports (220 names, 233 declarations), grouped, with its declaration and the first sentence of its doc
6
6
  comment in `lib/typesol.d.ts`. Each group links to the part of the [language guide](language.md) that explains it;
7
7
  your editor shows the full doc comment on hover. Methods of account and program types (`systemProgram.transfer`,
8
8
  `acct.create`, …) are described with their types in the guide.
@@ -346,6 +346,8 @@ Explained in [Sysvars, hashes, signatures and oracles: Sysvars](language-chain.m
346
346
  | `SlotHashesSysvar` | `interface SlotHashesSysvar` | The SlotHashes sysvar (`SysvarS1otHashes…`), read as an account: it is too large for the sysvar syscalls (Anchor's `Sysvar<SlotHashes>` cannot load it either). |
347
347
  | `StakeHistorySysvar` | `interface StakeHistorySysvar` | The StakeHistory sysvar (`SysvarStakeHistory…`), read as an account: the cluster's stake per recent epoch (up to 512, newest first), as the Stake program uses it for warmup and cooldown. |
348
348
  | `stackHeight` | `function stackHeight(): u64` | How deep in cross-program calls this program runs: 1 when the transaction calls it directly, more when another program invoked it. |
349
+ | `processedSiblingInstructionCount` | `function processedSiblingInstructionCount(): u64` | How many instructions the caller of this program has already invoked at this program's stack height (its processed siblings), or, when the transaction calls this program directly, how many top-level instructions ran before this one (Rust's `get_processed_sibling_instruction(i)` until it returns None). |
350
+ | `processedSiblingInstruction` | `function processedSiblingInstruction(index: u64): TransactionInstruction` | Processed sibling instruction `index` (0 the latest), as Rust's `get_processed_sibling_instruction(index)` reads it with the `sol_get_processed_sibling_instruction` syscall: its program id, accounts and data, as a TransactionInstruction. 5104 when there is none at that index. |
349
351
 
350
352
  ## Hashes, signatures and introspection
351
353
 
@@ -401,11 +403,13 @@ Explained in [Porting a native program (advanced)](language-native.md).
401
403
  | `RbEntry` | `interface RbEntry<K, V>` | A node of a RedBlackTree: its key (read-only), its value (in place) and its index in the tree's node array (1-based). |
402
404
  | `closeRaw` | `function closeRaw(account: RemainingAccount \| Mut<AccountInfo>, receiver: RemainingAccount \| Mut<AccountInfo>): void` | Close an account of this program as a native program does it by hand (Phoenix's Tombstone), in this order: `receiver.lamports += account.lamports`, `account.lamports = 0`, the owner set to the System Program, the data length set to 0 (`realloc(0, false)`: the bytes are not zeroed, the runtime drops them with the length). |
403
405
  | `assignOwner` | `function assignOwner(account: RemainingAccount \| Mut<AccountInfo>, owner: Pubkey): void` | Set an account's owner in place (Rust's `AccountInfo::assign`). |
406
+ | `zeroData` | `function zeroData(account: RemainingAccount \| Mut<AccountInfo>, offset: u64, length: u64): void` | Zero `length` bytes of an account's data from `offset`, as a native program's `for b in data[offset..offset + length].iter_mut() { *b = 0; }` (a memset): the memset syscall, about constant compute units whatever the length. |
404
407
  | `setReturnData` | `function setReturnData(bytes: IndexedList<u8>): void` | Set this instruction's return data to `bytes` as they are (Rust's `set_return_data(&bytes)`): a list of u8 such as a local `FixedVec<u8, N>`, a Vec or FixedVec in account data, or the instruction data or a slice of it. |
405
408
  | `panic` | `function panic(message?: string \| null, location?: string): never` | Stop the program as a Rust `panic!` / `unwrap()` on `None` / `unreachable!()` does: the message is logged and the instruction fails with ProgramFailedToComplete (no error code). |
406
409
  | `panicsAt` | `function panicsAt<T>(location: string, value: T): T` | `value`, with its checked arithmetic panicking as Rust's overflow checks do at `location` ("file:line:column", where the original's expression is): `panicsAt("src/quantities.rs:233:1", a + b)` logs "attempt to add with overflow" there (also "attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder with a divisor of zero", "attempt to negate with overflow", "attempt to divide with overflow", "attempt to shift left / right with overflow" for a shift amount past the width), as `panic` logs (see `PANIC_STYLE`), instead of failing with 5100 / 5101. |
407
410
  | `abort` | `function abort(): never` | Stop the program as Rust's `abort` does on SBF (the allocator's out-of-memory error, `std::process::abort`): the runtime's `abort` syscall, which fails the instruction with ProgramFailedToComplete and logs "SBF program panicked" (no location, nothing else). |
408
411
  | `logBase64` | `function logBase64(prefix: string, value: object): void` | Log `prefix` followed by the base64 (standard, padded) of a struct value's bytes, as a native program's `msg!("ray_log: {}", base64(bincode(log)))` does. |
409
412
  | `logComputeUnits` | `function logComputeUnits(): void` | Log the compute units left (Rust's `sol_log_compute_units()`): the runtime writes "Program consumption: <N> units remaining", as the original's line, at the same place. |
413
+ | `log64` | `function log64(a: u64, b: u64, c: u64, d: u64, e: u64): void` | Log five u64 values as Rust's `sol_log_64(a, b, c, d, e)` does: the runtime writes "Program log: 0x<a>, 0x<b>, 0x<c>, 0x<d>, 0x<e>" (lowercase hex, no padding). |
410
414
 
411
415
  **Next:** [Glossary](glossary.md): the Solana and TypeSOL terms the guide uses.
@@ -81,7 +81,14 @@ export function commit(c: Mut<Commit>, owner: Pubkey, text: string, n: u64): voi
81
81
  themselves. Unlike a check such as `HasOne`, nothing happens when the answer is false: wrap them in
82
82
  `require(…, error)`. The compiler refuses a call used as a statement, one that is the
83
83
  condition of an `if` with an empty body and no `else` or an empty one, and one whose result is kept in a local the function never
84
- reads. It does not catch a helper that returns the result and is itself called as a statement.
84
+ reads. The same goes for a call of a helper that returns such a result: one with a `return` that gives the result of
85
+ one of the three or of another such helper, directly, combined with `&&`, `||`, `!` or `?:`, or through a local of
86
+ the helper that nothing but its returns reads (`the result of checkProof is discarded, so nothing is checked: it
87
+ returns the result of merkleVerify; write require(checkProof(…), error)`). A helper that acts on the result itself
88
+ (requires it, reads it outside a `return`) is not one. Not caught: a result stored in an account field, a struct or an
89
+ Option, compared (`=== true`) or passed to another function that ignores it, a helper that branches on the result and
90
+ returns literals (`if (!ok) { return false; } return true;`), and a helper that returns what a function passed to it
91
+ returns (a function parameter is not followed).
85
92
 
86
93
  ```ts
87
94
  import { type Account, type Hash, type Init, type InstructionsSysvar, type Mut, type Pubkey, type Signer, type SystemProgram, type u8, type u64, type Vec, keccak256, merkleVerify, require, verifyEd25519, verifySecp256k1 } from "typesol";
@@ -130,6 +137,11 @@ export function approved(drop: Account<Drop>, ixs: InstructionsSysvar, who: Pubk
130
137
  `is(program, "name")` (that program's instruction by its default Anchor discriminator, sha256("global:<name>"); an
131
138
  instruction with its own `@discriminator` is matched with `programId` and `readU64(0)` instead).
132
139
  - Every read is bounds-checked (5104).
140
+ - `processedSiblingInstructionCount()` and `processedSiblingInstruction(i)` (a `TransactionInstruction`, 5104 past
141
+ the last) read the instructions already processed at this program's stack height, with the
142
+ `sol_get_processed_sibling_instruction` syscall as Rust's `get_processed_sibling_instruction` reads it: under a
143
+ caller, the instructions that caller already invoked (index 0 the latest); at the top level, the transaction's
144
+ earlier instructions. With `stackHeight()`, a program can refuse to run twice under one caller.
133
145
  - It is the transaction author's data: require things of the transaction with it (a repay instruction after a flash
134
146
  loan), never treat it as proof.
135
147
 
@@ -54,6 +54,7 @@ Pass signer seeds (with the bump) as the last argument when the authority is a P
54
54
  | Methods | Notes |
55
55
  | --- | --- |
56
56
  | `transfer`, `transferChecked(from, mint, to, authority, amount)` | Token-2022 mints with fees or hooks require `transferChecked` |
57
+ | `transferCheckedWithHook(from, mint, to, authority, amount, hookAccounts)` | `transferChecked` for a mint with a transfer hook: [the hook's extra accounts](#calling-a-transfer-hook-mint) resolved among `hookAccounts` |
57
58
  | `mintTo`, `mintToChecked(mint, to, authority, amount)` | the mint may be one this instruction just created |
58
59
  | `burn`, `burnChecked(from, mint, authority, amount)` | |
59
60
  | `approve(source, delegate, owner, amount)`, `approveChecked(source, mint, delegate, owner, amount)`, `revoke` | the checked forms take the decimals from the mint |
@@ -467,4 +468,29 @@ ExtraAccountMetaList).
467
468
  - Inside the hook, `isTransferring(source)` says whether Token-2022 is transferring from it.
468
469
  - See [`test/fixtures/hook.ts`](https://github.com/typesol-lang/typesol/blob/main/test/fixtures/hook.ts) and the transfer-hook ports.
469
470
 
471
+ ### Calling a transfer hook mint
472
+
473
+ A program that moves a hooked mint's tokens by CPI must pass Token-2022 the hook's extra accounts, the validation
474
+ account and the hook program after the four of TransferChecked. `tokenProgram.transferCheckedWithHook(from, mint, to,
475
+ authority, amount, hookAccounts, signerSeeds?)` builds that call as Rust's
476
+ `spl_transfer_hook_interface::onchain::add_extra_accounts_for_execute_cpi` does: `hookAccounts` (`remainingAccounts()`
477
+ or `rest.slice(a, b)`) must hold the hook program and, when the transfer needs it, the validation account and every
478
+ extra account, in any order. Each extra account is resolved from the list (a fixed address, a PDA of the hook or of
479
+ another program from literal, instruction-data, account-key and account-data seeds, or a key read from an account's
480
+ data), against the execute instruction's accounts (source, mint, destination, authority, the validation account, then
481
+ the extra accounts already resolved), made read-only where every earlier mention of it is, and never a signer. The
482
+ refusals are the Rust crates' and their codes: the hook program missing (TransferHookError::IncorrectAccount,
483
+ 2110272652), an extra account missing (AccountResolutionError::IncorrectAccount, 2724315840; the other
484
+ AccountResolutionError codes for bad seeds), no list in the validation account (TlvError::TypeNotFound, 1202666432), a
485
+ malformed one (InvalidAccountData, InvalidArgument, or 1 for a list shorter than its count). Without the validation
486
+ account among `hookAccounts` only the hook program is added; a mint without a hook gets a plain `transferChecked`.
487
+
488
+ ```ts
489
+ import { type Mint, type Mut, type Signer, type TokenAccount, type TokenInterface, type u64, remainingAccounts } from "typesol";
490
+
491
+ export function pay(from: Mut<TokenAccount>, mint: Mint, to: Mut<TokenAccount>, owner: Signer, tokenProgram: TokenInterface, amount: u64): void {
492
+ tokenProgram.transferCheckedWithHook(from, mint, to, owner, amount, remainingAccounts());
493
+ }
494
+ ```
495
+
470
496
  **Next:** [Sysvars, hashes, signatures and oracles](language-chain.md).
@@ -69,7 +69,7 @@ it); a zero code fails with 5100.
69
69
  - `require(cond, "message")` errors come after the highest code.
70
70
 
71
71
  When the program fails, the logs show the error and the source line, `Error 6000 NotOwner (vault.ts:21)`, and
72
- TypeSOL's own failures say what failed, `TypeSOL: arithmetic overflow (vault.ts:42)`. Native ports can change or drop
72
+ TypeSOL's own failures say what failed, `TypeSOL: arithmetic overflow (vault.ts:44)`. Native ports can change or drop
73
73
  that line ([log lines](language-native.md#log-lines-as-the-original-writes-them)).
74
74
 
75
75
  ## log
@@ -124,6 +124,9 @@ export function deposit(owner: Signer, pool: Mut<Pool>, amount: u64, tags: Vec<u
124
124
  when empty.
125
125
  - An event is at most 1024 bytes (5107).
126
126
 
127
+ In a test, `t.events(res)` gives a transaction's events decoded, `emitCpi`'s too
128
+ ([asserting events](test-your-program.md#events)).
129
+
127
130
  ### Events through CPI
128
131
 
129
132
  ```ts
@@ -148,6 +151,18 @@ instruction) instead of the logs. The instruction takes `eventAuthority:
148
151
  EventAuthority` (Anchor's `["__event_authority"]` PDA) and `self: SelfProgram` parameters, and the program accepts
149
152
  Anchor's event instruction (2002 when the event authority did not sign it, 2006 when it is not that PDA).
150
153
 
154
+ By default the two accounts are checked when the instruction's accounts load: the event authority by its seeds (2006)
155
+ and `self` against this program's address (3008). Anchor 1.x's `#[event_cpi]` checks them differently, and
156
+ `export const EVENT_AUTHORITY_CHECK = "address"` does as it does, for ports of Anchor 1.x programs:
157
+
158
+ - the event authority is compared with the PDA's address among the constraints, in account order after the accounts
159
+ load and the `create`s run (ConstraintAddress, 2012);
160
+ - the `self` account is not checked: the self-CPI names this program's id whatever account was passed there. An
161
+ instruction that emits nothing then accepts any account in that slot; one that emits fails in the runtime
162
+ (MissingAccount) when this program is not among its accounts, as Anchor's `emit_cpi!` does.
163
+
164
+ Programs without the constant build as before.
165
+
151
166
  ## Return values
152
167
 
153
168
  ```ts
@@ -314,7 +314,7 @@ direct mapping), one that was only read (or written with the bytes it held) is f
314
314
  `AccountInfo`s over one buffer.
315
315
 
316
316
  - **By default** `loadRawMut` and `storeBorsh` check writability up front (3006), `loadRawMut` claims the account once
317
- and `storeBorsh` refuses an account passed more than once (2040, as a write to a remaining account's lamports). So a
317
+ and `storeBorsh` refuses an account passed more than once (2040, as a write to a remaining account's lamports does without the flag). So a
318
318
  port fails where the original succeeds (a read-only validator list that is only read; the list passed again as a
319
319
  stake account, which the original skips by its address checks).
320
320
  - **With the flag**, `loadRawMut`, `storeBorsh` and the BigVec writes through a `loadRawMut` view skip both, and both
@@ -328,8 +328,14 @@ direct mapping), one that was only read (or written with the bytes it held) is f
328
328
  `loadRaw` of an account also loaded with `loadRawMut` (or written with `storeBorsh`) reads what was written, BigVec
329
329
  pushes included. The flag only lifts the up-front checks (a second `loadRawMut` of one account, at the same position
330
330
  or another, is 2040 without it).
331
- - `.lamports` on remaining accounts, `loadAccountMut`, CPI account metas and the checks of `Mut<…>` parameters stay as
332
- they are, and programs without the flag compile exactly as before.
331
+ - A write to a remaining account's `.lamports` (`a.lamports = v`, `+=`, `-=`) is `**a.lamports.borrow_mut() = v`
332
+ under the flag: no writability check (3006) and no refusal of an account passed more than once (2040). An account
333
+ passed twice is one record, as Rust's two `AccountInfo`s share one `RefCell`, so a write through either position is
334
+ read through the other; the runtime refuses a read-only account's change, or lamports created or destroyed, when the
335
+ instruction ends (`ReadonlyLamportChange`, `UnbalancedInstruction`). Percolator's CloseSlab moves the slab's
336
+ lamports to the admin this way while the admin (or the slab) is also named in an unused position.
337
+ - `loadAccountMut`, CPI account metas and the checks of `Mut<…>` parameters stay as they are, and programs without the
338
+ flag compile exactly as before.
333
339
 
334
340
  ### Inout places that may be one account
335
341
 
@@ -355,6 +361,13 @@ On remaining accounts and `AccountInfo` parameters:
355
361
  lamports in the receiver; [`test/language/native-close.test.ts`](https://github.com/typesol-lang/typesol/blob/main/test/language/native-close.test.ts) compares it with Phoenix's own Tombstone).
356
362
  - `assignOwner(account, owner)` is `AccountInfo::assign` (the runtime accepts it for a writable account of this program
357
363
  whose data is empty or zeroed).
364
+ - `zeroData(account, offset, length)` zeroes that range of the data, as a native program's `for b in
365
+ data.iter_mut() { *b = 0; }`, which compiles to a memset: the memset syscall, about constant compute units whatever
366
+ the length (Percolator clears its 1.5 MB slab this way at InitMarket and CloseSlab). Past the end of the data fails
367
+ with 3003 and writes nothing; without `NATIVE_ACCOUNT_WRITES` the account must be writable (3006). It does not check
368
+ the account's owner: check that it is this program's first (the runtime would fail the instruction after it returns,
369
+ having changed another program's account). The length does not change, so views made before stay valid and read the
370
+ zeros.
358
371
  - `resizeAccount(account, size)` also takes a remaining account (`realloc(size, true)`: new bytes zeroed, at most
359
372
  10 KiB past the size it had when the instruction started, 3016). That size is the one the entrypoint records in the
360
373
  account's record, as solana_program 1.14's does, only in programs that resize a remaining account.
@@ -405,6 +418,11 @@ export function entry(): void {
405
418
  location)` log `panicked at '<message>', <location>` and then abort, so the runtime's last line is "SBF program
406
419
  panicked" with no location, as that panic handler leaves it. `panic(null, …)` is refused there (the handler always
407
420
  logs); without a location the TypeScript line and column are used. `PANIC_ON_OVERFLOW`'s panics abort too.
421
+ - **Panics as solana-program 1.18 writes them.** `export const PANIC_STYLE = "solana-1.18"` (a program built with
422
+ solana-program 1.18, whose rustc formats a panic as it has since 1.73: Percolator v12.20) makes `panic(message,
423
+ location)` log one line, `panicked at <location>:` and the message after a newline, and then abort ("SBF program
424
+ panicked"), as that panic handler does: `panicked at src/wide_math.rs:1554:30:\nmul_div_floor_u128: a*b overflow`.
425
+ As under "solana-1.14", a message is required and `PANIC_ON_OVERFLOW`'s panics abort.
408
426
  - **Overflow panics with Rust's message and location.** `panicsAt("src/quantities.rs:233:1", a + b)` is `a + b` whose
409
427
  checked arithmetic panics as Rust's overflow checks do at that location ("attempt to add with overflow"; also
410
428
  "attempt to subtract / multiply with overflow", "attempt to divide by zero", "attempt to calculate the remainder with
@@ -435,6 +453,8 @@ export function entry(): void {
435
453
  - `createProgramAddress(seeds, program)` is `Pubkey::create_program_address` (null for no address).
436
454
  - `logComputeUnits()` is `sol_log_compute_units()`: the runtime writes "Program consumption: N units remaining" at that
437
455
  point, as for the original (Phoenix's cancel and withdraw paths log it).
456
+ - `log64(a, b, c, d, e)` is `sol_log_64(a, b, c, d, e)`: the runtime writes the five u64s as lowercase hex,
457
+ `Program log: 0x174778, 0x3e8, 0x0, 0x0, 0x0` (Percolator logs the slab length it wants and the one it got this way).
438
458
 
439
459
  ## Byte strings built by hand
440
460
 
@@ -236,7 +236,7 @@ members`). A `switch` on a string is refused (`switch works on integers and enum
236
236
  ## Destructuring
237
237
 
238
238
  ```ts
239
- import { type Account, type Mut, type Pubkey, type u64 } from "typesol";
239
+ import { type Account, type Mut, type Pubkey, type Signer, type u64, require } from "typesol";
240
240
 
241
241
  export interface Point {
242
242
  x: u64;
@@ -249,7 +249,8 @@ export interface Player {
249
249
  score: u64;
250
250
  }
251
251
 
252
- export function read(player: Account<Player>, out: Mut<Player>): void {
252
+ export function read(signer: Signer, player: Account<Player>, out: Mut<Player>): void {
253
+ require(out.owner === signer.key, "only the owner of out can overwrite it");
253
254
  const { owner, pos: p } = player;
254
255
  let { score } = player;
255
256
  score += p.x;
@@ -614,6 +615,7 @@ may gain a hint line.
614
615
  | an unused proof or signature check | `merkleVerify(leaf, proof, root);` | the result of merkleVerify is discarded, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
615
616
  | a proof check in an empty `if` | `if (merkleVerify(leaf, proof, root)) {}` | the result of merkleVerify is not acted on: the if around it has an empty body, so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
616
617
  | a proof check kept in a local never read | `const ok = merkleVerify(leaf, proof, root);` (`ok` unused) | the result of merkleVerify is never read (ok is not used), so nothing is checked: it returns whether the proof holds; write require(merkleVerify(…), error) |
618
+ | an unused helper that returns a check | `checkProof(leaf, proof, root);` (`checkProof` returns `merkleVerify(…)`) | the result of checkProof is discarded, so nothing is checked: it returns the result of merkleVerify; write require(checkProof(…), error) |
617
619
  | a `@code` tag outside a doc comment | `export enum E { A = "a", /* @code 6100 */ B = "b" }` | this @code tag is not read: only a doc comment (/** … */) is, not a /* … */ comment; write /** @code … */ above B |
618
620
  | a `@code` tag after other code on its line | `export enum E { A = "a", /** @code 6100 */ B = "b" }` | this @code tag is not read: other code comes before it on its line; put /** @code … */ on its own line above B |
619
621
 
package/docs/language.md CHANGED
@@ -59,9 +59,9 @@ The error codes are in [errors.md](errors.md); what a compiled program checks fo
59
59
  - `?.` and `!` on anything but optional accounts, Options and a `find` on struct elements.
60
60
  - Functions stored in a struct, chosen from a list by index, or returned from an instruction.
61
61
  - A fused `map` to strings: store it, annotated.
62
- - Floating point (by design).
63
62
 
64
- They are rejected at compile time rather than half-supported.
63
+ They are rejected at compile time rather than half-supported. Floating-point arithmetic is not planned at all, by
64
+ design: an `f64` is carried only as its bits, in accounts and events ([f64](language-types.md#f64)).
65
65
 
66
66
  ## Index of the former sections
67
67
 
package/docs/mainnet.md CHANGED
@@ -16,7 +16,7 @@ You need Node.js 22.12 or later and the Agave CLI with platform-tools (see the R
16
16
  toolchain is part of what you trust. Deploy with the one TypeSOL is tested with (Agave 3.1.10, platform-tools v1.52;
17
17
  `typesol doctor` says whether yours is, and `typesol deploy --toolchain-strict` refuses another). The host does not
18
18
  matter from 0.45.0 on: with the same TypeSOL and toolchain a program builds to the same bytes on macOS arm64, Linux
19
- 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
19
+ arm64 and Linux x86_64 (measured with 0.45.0 over the 76 programs then in the sources for SBPF v0 and 14 for v1 and v2; up to 0.44.1 a program with
20
20
  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
21
21
  it with `--docker` (step 2) all the same: a pinned linux/amd64 container that anyone can rebuild, so the whole
22
22
  environment is one recipe. Keep
package/docs/runtime.md CHANGED
@@ -4,6 +4,13 @@
4
4
  entry point's input parser, account checks, checked arithmetic, Borsh helpers, CPIs, sysvars, strings and the heap.
5
5
  This page is for people changing it; programs never call it directly.
6
6
 
7
+ Since 0.45.0 the runtime is no longer header-only: `runtime/typesol_builtins.c` holds the functions clang calls for
8
+ 128-bit multiplication, division and shifts and for signed 64-bit division (`__multi3`, `__udivti3`, `__divti3`,
9
+ `__divdi3`, …). It is compiled with every program by the same clang and linked after it, in place of platform-tools'
10
+ `compiler-builtins` library, whose layout differed by host package
11
+ ([stability.md](stability.md#what-builds-the-same-bytes-where)); `test/language/builtins.test.ts` checks it against
12
+ BigInt and its compute units against compiler-builtins'.
13
+
7
14
  ## Conventions
8
15
 
9
16
  - **Header-only, `static inline`.** Each program compiles the header with its own code, and `--gc-sections` drops
@@ -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. 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) |
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 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): measured with 0.45.0 over the 76 programs then in the sources 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) |
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
@@ -82,7 +82,10 @@ Each holds for every instruction of every program the compiler accepts. A break
82
82
  transaction did not pass that way and any signer the program's seeds do not cover. Only programs that store
83
83
  instructions to run (a multisig, a DAO) need it; review who can write those values.
84
84
  Return data is read only from the program named, at the expected size (5106).
85
- 13. **Events.** `emitCpi` is accepted only from this program's event-authority PDA, signed (2002).
85
+ 13. **Events.** `emitCpi` is accepted only from this program's event-authority PDA, signed (2002). Under
86
+ `EVENT_AUTHORITY_CHECK = "address"` (0.48.0) the event authority is checked by address among the constraints
87
+ (2012) instead, and the self-program account is not checked at all: an instruction that emits fails in the runtime
88
+ (MissingAccount) when this program is not among its accounts, as Anchor 1.x's does.
86
89
 
87
90
  ### When it ends
88
91
 
@@ -177,5 +180,9 @@ exposed to them.
177
180
  The compiler and runtime have had internal security reviews, the latest of 0.44.0 (above); its findings are fixed in
178
181
  0.44.1. It was an internal review, not an independent audit; it covered the token, Token-2022, Metaplex and Stake
179
182
  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).
183
+ wrappers for unusual argument shapes beyond reading them, the large ports on SBPF v1/v2, or Windows. 0.45.0 to 0.49.0
184
+ have had no security review. They add, among others, `runtime/typesol_builtins.c` (the
185
+ compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`, `EVENT_AUTHORITY_CHECK` and the reads of
186
+ processed sibling instructions (0.48.0), and `zeroData`, `log64`,
187
+ `PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
188
+ `NATIVE_ACCOUNT_WRITES` (0.49.0). There has been no external audit: see [audit.md](audit.md).