@typesol/cli 0.48.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.
- package/CHANGELOG.md +159 -1
- package/NOTICE +8 -1
- package/README.md +103 -41
- package/SECURITY.md +5 -0
- package/dist/compiler/emit/base.d.ts +6 -4
- package/dist/compiler/emit/base.js +11 -5
- package/dist/compiler/emit/calls.js +41 -1
- package/dist/compiler/emit/expressions.js +3 -1
- package/dist/compiler/emit/program.js +4 -4
- package/dist/compiler/emit/storage.js +8 -3
- package/dist/compiler/hints.js +3 -0
- package/docker/deps/0.49.0.lock.json +1206 -0
- package/docs/architecture.md +2 -2
- package/docs/audit.md +30 -14
- package/docs/case-study-escrow.md +7 -5
- package/docs/case-study-marginfi.md +15 -2
- package/docs/case-study-multisig.md +2 -1
- package/docs/case-study-raydium-amm.md +2 -1
- package/docs/case-study-spl-stake-pool.md +4 -3
- package/docs/language-accounts.md +5 -6
- package/docs/language-builtins.md +3 -1
- package/docs/language-errors-events.md +1 -1
- package/docs/language-native.md +23 -3
- package/docs/language-statements.md +3 -2
- package/docs/language.md +2 -2
- package/docs/mainnet.md +1 -1
- package/docs/runtime.md +7 -0
- package/docs/security-model.md +11 -4
- package/docs/stability.md +9 -4
- package/docs/testing.md +16 -4
- package/docs/troubleshooting.md +1 -1
- package/lib/typesol.d.ts +19 -1
- package/llms-full.txt +62 -28
- package/llms.txt +2 -1
- package/package.json +3 -3
- package/releases/0.48.0.json +847 -0
- package/runtime/typesol_rt.h +2 -1
package/docs/architecture.md
CHANGED
|
@@ -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.
|
|
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` | 3,
|
|
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 |
|
|
15
16
|
| 1 | Instruction prologue and constraints | `src/compiler/emit/function.ts` | 886 | 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` | 4,
|
|
17
|
-
| 1 | Calls and CPIs | `src/compiler/emit/calls.ts`, `cpi-core.ts`, `cpi.ts`, `create.ts`, `token.ts` | 5,
|
|
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,
|
|
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,
|
|
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
|
|
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**:
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 #
|
|
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 (
|
|
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,
|
|
199
|
-
| take_offer | **7,
|
|
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.
|
|
202
|
+
| Binary | 32.1 KB | 244.5 KB | 120.4 KB | **25.1 KB** |
|
|
202
203
|
|
|
203
|
-
|
|
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,
|
|
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,
|
|
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
|
|
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`).
|
|
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
|
|
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
|
|
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(
|
|
192
|
-
realloc(log, size,
|
|
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:
|
|
205
|
-
|
|
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`).
|
|
@@ -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 (
|
|
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.
|
|
@@ -403,11 +403,13 @@ Explained in [Porting a native program (advanced)](language-native.md).
|
|
|
403
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). |
|
|
404
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). |
|
|
405
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. |
|
|
406
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. |
|
|
407
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). |
|
|
408
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. |
|
|
409
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). |
|
|
410
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. |
|
|
411
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). |
|
|
412
414
|
|
|
413
415
|
**Next:** [Glossary](glossary.md): the Solana and TypeSOL terms the guide uses.
|
|
@@ -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:
|
|
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
|
package/docs/language-native.md
CHANGED
|
@@ -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
|
-
-
|
|
332
|
-
|
|
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;
|
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
|
package/docs/security-model.md
CHANGED
|
@@ -10,7 +10,7 @@ auditors, [SECURITY.md](../SECURITY.md) how to report a problem.
|
|
|
10
10
|
| --- | --- |
|
|
11
11
|
| The program's author | the program's logic: what it allows, to whom, for how much |
|
|
12
12
|
| TypeSOL (this repository) | that the binary does what the source and these guarantees say, and nothing an attacker can steer beyond it |
|
|
13
|
-
| The toolchain | the TypeScript compiler API (parsing, types), Agave platform-tools (clang, lld), Node.js. 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.
|
|
181
|
-
|
|
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).
|
package/docs/stability.md
CHANGED
|
@@ -61,14 +61,17 @@ Meant to stay as they are; a change before 1.0 would be a breaking change listed
|
|
|
61
61
|
|
|
62
62
|
## What builds the same bytes where
|
|
63
63
|
|
|
64
|
-
From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with
|
|
64
|
+
From 0.45.0 on, the programs measured build to the same bytes on each host measured. Measured with 0.45.0's
|
|
65
65
|
compiler and platform-tools v1.52 on macOS arm64 (the platform-tools `osx-aarch64` package, native), Linux arm64 and
|
|
66
66
|
Linux x86_64 (the `linux-aarch64` and `linux-x86_64` packages, in containers; x86_64 is the `--docker` image; Linux
|
|
67
67
|
arm64 has no Agave CLI, so there the package is set up by hand with `TYPESOL_SBF_SDK`, as in
|
|
68
68
|
[troubleshooting.md](troubleshooting.md#linux-arm64-the-agave-installer-fails-with-a-404)): for
|
|
69
|
-
SBPF v0 (the default), the 76 programs
|
|
70
|
-
and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault,
|
|
71
|
-
and the 10 below).
|
|
69
|
+
SBPF v0 (the default), the 76 programs then in the sources (`scripts/release-manifest.ts`, every program under
|
|
70
|
+
`examples/` and `showcase/`); for SBPF v1 and v2, the 14 programs of `test/golden/binaries.json` (counter, vault,
|
|
71
|
+
escrow, multisig and the 10 below). Programs added since were not measured on the three hosts, and two of them that
|
|
72
|
+
divide 128-bit and wider integers, the Meteora DBC port (0.48.0; u128 and u256 division) and the Percolator port
|
|
73
|
+
(0.49.0; U256 and U512), are not in `test/golden/binaries.json`, so CI's cross-host check does not build them yet
|
|
74
|
+
(adding them needs the file regenerated in the `--docker` reference environment).
|
|
72
75
|
|
|
73
76
|
| What | Same on the three hosts? |
|
|
74
77
|
| --- | --- |
|
|
@@ -126,6 +129,8 @@ Useful today, but may still change before 1.0 (each change listed in the CHANGEL
|
|
|
126
129
|
its panics in solana-program 1.14–1.17's format, `removeAt(index)` (what it gives for a node in no tree may change).
|
|
127
130
|
- `panic(null, location)` (no log line) and `abort()` (Rust's abort, "SBF program panicked") (0.42.0).
|
|
128
131
|
- Failures without a log line (0.43.0): `ERROR_LOG_PREFIX = null` / `PROGRAM_ERROR_LOG_PREFIX = null`.
|
|
132
|
+
- `EVENT_AUTHORITY_CHECK = "address"` (0.48.0): `emitCpi`'s event authority checked by address, as Anchor 1.x's
|
|
133
|
+
`#[event_cpi]` does, and the self-program account not checked (docs/security-model.md, guarantee 13).
|
|
129
134
|
- `findProgramAddressWithBump` (0.43.0), with `const [address, bump] = …` its only array destructuring.
|
|
130
135
|
- Plain type aliases (0.43.0): `type Price = u64`, replaced by the type they name.
|
|
131
136
|
- File-local structs (0.43.0): `interface Pair { … }` without `export`, for helpers and locals, out of the IDL.
|
package/docs/testing.md
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
# How TypeSOL is tested
|
|
2
2
|
|
|
3
3
|
Besides unit tests, these checks run the compiled programs (LiteSVM) against an independent oracle. Every randomized
|
|
4
|
-
run prints its seed; reproduce with `FUZZ_SEED=<n>`, widen with `FUZZ_RUNS` / `FUZZ_STEPS` (`pnpm
|
|
4
|
+
run prints its seed or runs fixed ones; reproduce with `FUZZ_SEED=<n>`, widen with `FUZZ_RUNS` / `FUZZ_STEPS` (`pnpm
|
|
5
|
+
fuzz` runs them wide). Most take a new seed from the clock on every run, CI's included; the Phoenix, Percolator and
|
|
6
|
+
Raydium AMM v4 walks run fixed seeds unless `FUZZ_SEED` (or the Percolator variables) names another, so CI walks the
|
|
7
|
+
same ones every time.
|
|
5
8
|
|
|
6
9
|
| Check | Oracle | What must hold |
|
|
7
10
|
| --- | --- | --- |
|
|
@@ -13,8 +16,13 @@ run prints its seed; reproduce with `FUZZ_SEED=<n>`, widen with `FUZZ_RUNS` / `F
|
|
|
13
16
|
| `showcase/test/fuzz-jito.test.ts` | Jito's tip payment, tip distribution and priority fee distribution as deployed on mainnet | random sequences of tips, receiver and builder changes, accounts opened over epochs, roots uploaded, Merkle claims (wrong amounts, proofs and signers among them), closes and config changes, with at most one injected fault per transaction: the same outcome, account bytes, events and log lines as the original after every step; keys, amounts and choices all come from the seed |
|
|
14
17
|
| `showcase/test/fuzz-marginfi.test.ts` | Marginfi v2 as deployed on mainnet | random sequences of bank creation (random weights, curves and fees, most valid, some broken one way), configuration (operational states, curves, liquidation fees, the circuit breaker's switch and settings, frozen banks), accruals over balances written into both at every scale and clock jumps up to a year, limits, pauses, wrong signers: the same outcome, account bytes and events as the original after every step; inputs the original panics on (a negative fee rate) must fail in the port too |
|
|
15
18
|
| the `fuzz:` case of `showcase/test/raydium-clmm.test.ts` | Raydium CLMM as deployed on mainnet | random swaps (both ways, exact in and out, price limits, thresholds), positions opened at random ranges, and liquidity added and taken out (over the position's own, under slippage limits): the same outcome, account bytes and events as the original after every step; choices and amounts come from the seed (`CLMM_FUZZ_STEPS` lengthens it), keys are fresh each run; each transaction may use 1.4M compute units, so a swap the original needs more than 200,000 for still runs to its end |
|
|
19
|
+
| the `fuzz:` case of `showcase/test/raydium-cp-swap.test.ts` | Raydium CP-Swap as deployed on mainnet | random swaps both ways, deposits, withdrawals and fee collections over time, in an SPL Token pool and a pool of Token-2022 fee mints, each with the creator fee on in a random mode: the same outcome, account bytes and events as the original after every step; choices and amounts come from the seed, a new one each run (`CP_FUZZ_STEPS` lengthens it, 120 by default), keys are fresh each run |
|
|
20
|
+
| the last case of `showcase/test/raydium-amm.test.ts` | Raydium AMM v4 as deployed on mainnet | random swaps, deposits and withdrawals on one pool: the same outcome, log lines and account bytes as the original after every step; seed 7 unless `FUZZ_SEED` names another, 60 steps (`FUZZ_STEPS`) |
|
|
21
|
+
| `showcase/test/meteora-dbc-fuzz.test.ts`, `showcase/test/meteora-dbc-migration-fuzz.test.ts` | Meteora DBC 0.2.2 as deployed on mainnet (and DAMM v2, the locker, DAMM v1 and the dynamic vault for the migrations) | random configs drawn around their valid values and edges (200 by default), and random graduations (10 pools by default: a random config, swaps to the threshold, the locker, the surplus and fee withdrawals and the migration into DAMM v2 or DAMM v1 in a random order): the same outcome, account bytes, inner instructions and events as the original; a new seed each run (`FUZZ_RUNS` lengthens them) |
|
|
16
22
|
| `showcase/test/spl-stake-pool-fuzz.test.ts` | SPL Stake Pool as deployed on mainnet | a random walk over many epochs: validators added and removed, deposits, withdrawals, stake increased and decreased, rewards and tips at each epoch boundary, some steps wrong on purpose; every step gives the same outcome, logs and account bytes as the original, and every account the walk knows is compared after each epoch and every 25 steps; choices and amounts come from the seed (`STAKE_POOL_FUZZ_STEPS` lengthens it, `STAKE_POOL_FUZZ_SWEEP=1` compares every account after each step), keys are fresh each run |
|
|
17
23
|
| `showcase/test/phoenix-fuzz.test.ts` | Phoenix v1 as deployed on mainnet, and a balance model | a random walk over two order books (512/128 and 4096/8321, each started nearly full): every kind of order, reductions and cancels, seats, evictions, fee collection, status changes, a moving clock and invalid packets; every step gives the same outcome, logs, inner instructions, return data and account bytes as the original, and after each step every trader's locked and free lots plus the uncollected fees equal what the vaults hold; choices and every key come from the seed, CI walks seeds 1, 2 and 3 (300 steps on each market) and requires minimum counts of fills, evictions, expiries and fees (`PHOENIX_FUZZ_STEPS` changes the length) |
|
|
24
|
+
| `showcase/test/percolator-fuzz.test.ts` | Percolator v12.20 as deployed on mainnet | three random walks (accounts; oracle and market shapes; leveraged trades with crashes, liquidations and side resets) over markets of random shape (Pyth or Hyperp, fees, margins, warm-up, caps): opens, deposits, withdrawals, trades (TradeNoCpi, and TradeCpi through a matcher run under both), price crashes and spikes, liquidations, cranks with random hints, catch-ups, conversions, config changes, clock moves past the accrual envelope; then each market's end: bounded insurance withdrawals, resolution by the admin or by anyone after the hard timeout, every account closed out in random order by the three resolved closes, WithdrawInsurance and CloseSlab. Every step gives the same outcome, logs, inner instructions, return data and account bytes as the original, the vault and every token account are compared again at the end, and the port must use fewer compute units than the original on every successful transaction; choices and every key come from the seed; fixed seeds by default (1 to 6 for the account walk and the walk of leveraged trades and liquidations, two per oracle shape), the same in CI (`PERCOLATOR_FUZZ_RUNS`, `PERCOLATOR_FUZZ_STEPS`, `PERCOLATOR_ORACLE_RUNS`, `PERCOLATOR_ORACLE_STEPS`, `PERCOLATOR_ADL_RUNS`, `PERCOLATOR_ADL_STEPS`) |
|
|
25
|
+
| `showcase/test/percolator-mutate-*.test.ts` | Percolator v12.20 as deployed on mainnet | mutation fuzzers over a valid transaction of each of the 27 instructions in eleven market states (empty, funded, open positions, a reset-pending side, resolved with accounts, resolved with insurance only, resolved and bare, matured-stale, Hyperp, Chainlink, inverted): the account list (accounts replaced by every other account of the test world, duplicated, dropped, appended, swapped, signer and writable flags flipped; every position replaced by the slab and by the fee payer and duplicated into every other), the instruction data (every truncation, appended bytes, each field at its boundaries and around the limits the program checks, random bytes, all 256 tags, KeeperCrank candidate lists), the environment (several instructions per transaction, a relay calling at stack height 2, compute-unit limits below the original's, Clock extremes and the Clock moved backwards, Pyth and Chainlink accounts at every extreme) and the slab (every header, config, engine, account, free-list, bitmap, risk-buffer and generation field at its boundary values, random bytes, an inconsistent free list), each transaction compared with `both()`; choices and keys from `PERCOLATOR_MUTATE_SEED` (fixed), sizes from `PERCOLATOR_MUTATE_SCALE`; a tally of outcomes per category printed |
|
|
18
26
|
| `test/verification/rbtree-trace.test.ts` | lib-sokoban 0.3.0 itself (`test/verification/rbtree/oracle`, a Rust program that records traces) | the built-in RedBlackTree replays 21,650 recorded operations (capacities 1 to 4096; u64 keys, Phoenix's order ids with their comparator, Pubkey keys), one a transaction: after each the tree's bytes (root, allocator, every node, freed ones included) hash as the crate's did and the operation returns what the crate's returned; a second pass replays every `remove(key)` as `removeAt(addrOf(key))`; `RBTREE_TRACES=<file>` replays another set |
|
|
19
27
|
| `test/verification/differential.test.ts` | Anchor twins in `test/anchor-twins` | identical transactions to TypeSOL and Anchor programs: same outcomes, same account contents, same wallet and token balances after every step |
|
|
20
28
|
| `showcase/test/porting/ports-*.test.ts` | the Anchor programs of solana-developers/program-examples and their tests | TypeSOL rewrites under `showcase/program-examples/` run the originals' flows and failure paths with the same outcomes, error codes and balances ([showcase/program-examples/README.md](https://github.com/typesol-lang/typesol/blob/main/showcase/program-examples/README.md)) |
|
|
@@ -49,7 +57,8 @@ or later):
|
|
|
49
57
|
|
|
50
58
|
- the compiler and toolchain versions (clang, platform-tools, Node, TypeScript, the sha256 of the runtime header and,
|
|
51
59
|
from 0.45.0 on, of the runtime's compiler builtins);
|
|
52
|
-
- the sha256 of the SBF binary, IDL and C that every program under `examples
|
|
60
|
+
- the sha256 of the SBF binary, IDL and C that every program under `examples/`, `showcase/mainnet/` and
|
|
61
|
+
`showcase/program-examples/` builds to (`scripts/release-manifest.ts`);
|
|
53
62
|
- the sha256 of the reference binaries the differential tests run against (`test/programs/`);
|
|
54
63
|
- a hash of the test corpus.
|
|
55
64
|
|
|
@@ -72,7 +81,7 @@ the same binary and IDL with both packages.
|
|
|
72
81
|
### Across hosts
|
|
73
82
|
|
|
74
83
|
From 0.45.0 on the C, IDL and linked binary TypeSOL's builds produce are the same on the hosts measured
|
|
75
|
-
([stability.md](stability.md#what-builds-the-same-bytes-where) has the measurement over 76 programs on macOS arm64,
|
|
84
|
+
([stability.md](stability.md#what-builds-the-same-bytes-where) has the measurement with 0.45.0 over 76 programs on macOS arm64,
|
|
76
85
|
Linux arm64 and Linux x86_64, and why 0.44.1 and earlier differed for programs with 128-bit or signed division). The
|
|
77
86
|
reference environment is the `--docker` build container (linux/amd64). `test/golden/binaries.json` holds what 14
|
|
78
87
|
programs build to there with the checkout's compiler: counter, vault, escrow, multisig, and the 10 that call 128-bit or
|
|
@@ -110,7 +119,10 @@ From 0.43.0 on, `releases/<version>.json` in the repository describes the packag
|
|
|
110
119
|
tarball's size, sha1 shasum and sha512 integrity (the registry's `dist.shasum` and `dist.integrity`), and the sha256
|
|
111
120
|
of every file in it. `scripts/release-check.ts` writes it from a clean export of the tag (`git archive`: install with
|
|
112
121
|
the lockfile, build, lint, check the version and the CHANGELOG section, `npm pack`), and the maintainer publishes the
|
|
113
|
-
tarball it produced, by hand ([CONTRIBUTING.md](https://github.com/typesol-lang/typesol/blob/main/CONTRIBUTING.md#releasing)).
|
|
122
|
+
tarball it produced, by hand ([CONTRIBUTING.md](https://github.com/typesol-lang/typesol/blob/main/CONTRIBUTING.md#releasing)). Its `"tests"`
|
|
123
|
+
field says whether `release-check.ts` also ran the test suite on that export (`--tests`); it is `false` in the records
|
|
124
|
+
so far because the documented release steps run `pnpm test` before tagging and the check does not repeat it.
|
|
125
|
+
To check a release yourself:
|
|
114
126
|
|
|
115
127
|
```sh
|
|
116
128
|
node scripts/release-check.ts 0.43.0 # pack the tag again: git diff releases/ shows what moved
|
package/docs/troubleshooting.md
CHANGED
|
@@ -93,7 +93,7 @@ an account you change is a `Mut<T>` parameter; the time is `now()`, not `Date.no
|
|
|
93
93
|
### A transaction fails with a custom error
|
|
94
94
|
|
|
95
95
|
See [errors.md](errors.md). Failures raised by the compiler's checks log their TypeScript location, e.g. `TypeSOL:
|
|
96
|
-
arithmetic overflow (vault.ts:
|
|
96
|
+
arithmetic overflow (vault.ts:44)`.
|
|
97
97
|
|
|
98
98
|
### "exceeded CUs meter" / "Computational budget exceeded"
|
|
99
99
|
|