@typesol/cli 0.49.0 → 0.50.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 (56) hide show
  1. package/CHANGELOG.md +397 -0
  2. package/NOTICE +9 -0
  3. package/README.md +25 -8
  4. package/SECURITY.md +4 -3
  5. package/dist/compiler/analyze.d.ts +2 -0
  6. package/dist/compiler/analyze.js +7 -1
  7. package/dist/compiler/emit/base.d.ts +4 -3
  8. package/dist/compiler/emit/base.js +9 -3
  9. package/dist/compiler/emit/borsh.js +8 -8
  10. package/dist/compiler/emit/calls.d.ts +6 -0
  11. package/dist/compiler/emit/calls.js +71 -12
  12. package/dist/compiler/emit/cpi-core.js +3 -3
  13. package/dist/compiler/emit/cpi.js +2 -2
  14. package/dist/compiler/emit/expressions.d.ts +1 -0
  15. package/dist/compiler/emit/expressions.js +12 -0
  16. package/dist/compiler/emit/function.js +12 -8
  17. package/dist/compiler/emit/program.js +8 -2
  18. package/dist/compiler/emit/rbtree.js +1 -1
  19. package/dist/compiler/emit/shared.d.ts +12 -2
  20. package/dist/compiler/emit/shared.js +26 -6
  21. package/dist/compiler/emit/statements.d.ts +8 -1
  22. package/dist/compiler/emit/statements.js +53 -5
  23. package/dist/compiler/emit/storage.js +12 -10
  24. package/dist/compiler/emit/views.js +1 -1
  25. package/dist/compiler/index.d.ts +15 -1
  26. package/dist/compiler/index.js +50 -9
  27. package/dist/keys.d.ts +12 -1
  28. package/dist/keys.js +57 -7
  29. package/dist/workspace.d.ts +8 -0
  30. package/dist/workspace.js +90 -15
  31. package/docker/deps/0.50.0.lock.json +1206 -0
  32. package/docs/architecture.md +1 -1
  33. package/docs/audit.md +13 -12
  34. package/docs/case-study-jito-mev.md +14 -14
  35. package/docs/case-study-marginfi.md +127 -127
  36. package/docs/case-study-multisig.md +16 -4
  37. package/docs/case-study-raydium-clmm.md +44 -28
  38. package/docs/case-study-raydium-cp-swap.md +18 -18
  39. package/docs/cli.md +4 -3
  40. package/docs/language-accounts.md +16 -10
  41. package/docs/language-basics.md +4 -1
  42. package/docs/language-builtins.md +4 -2
  43. package/docs/language-cpi.md +34 -0
  44. package/docs/language-native.md +50 -4
  45. package/docs/language-statements.md +2 -1
  46. package/docs/language-types.md +13 -3
  47. package/docs/runtime.md +19 -2
  48. package/docs/security-model.md +4 -3
  49. package/docs/stability.md +5 -4
  50. package/docs/testing.md +6 -2
  51. package/lib/typesol.d.ts +25 -3
  52. package/llms-full.txt +136 -31
  53. package/package.json +1 -1
  54. package/releases/0.49.0.json +857 -0
  55. package/runtime/typesol_builtins.c +47 -2
  56. package/runtime/typesol_rt.h +129 -3
package/CHANGELOG.md CHANGED
@@ -6,6 +6,403 @@ codes, and says so here.
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## 0.50.0 — 2026-11-26
10
+
11
+ A minor release: it adds a port of Percolator v16 (all 50 instructions of aeyakovenko/percolator-prog at 7b110913,
12
+ compared with a reference built from the author's source, as no v16 build is deployed) and the built-ins it needed
13
+ (`copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"`), copies and zeroes whole values and account data with the
14
+ memory syscalls where the word loops cost more, and fixes overlapping struct copies between views of one account, other
15
+ programs' `@layout borsh` accounts with a discriminator shorter than 8 bytes, `realloc` of `@layout borsh` accounts, the
16
+ folding of a signed minimum modulo -1, the order in which `log64` and `require` read their arguments, `**` inside
17
+ `panicsAt` and builds with a clang above 20. Build manifests now bind a binary to the sources that built it, first
18
+ builds that run at once keep every program's address, and `init` and `new` refuse to write through a symbolic link.
19
+ Programs that compiled with 0.49.0 and still compile build to the same bytes, except 15 of the 80 programs both releases
20
+ build: examples/escrow, ledgerbook and profiles, Jito's two programs, Marginfi, Meteora DBC, Percolator v12.20 and its
21
+ matcher, Raydium CLMM and CP-Swap, SPL Stake Pool and the program-examples realloc, token escrow and token fundraiser,
22
+ for the memory syscalls and the fix of overlapping copies (Raydium CLMM also because its source no longer writes four
23
+ kinds of `msg!` line); their tests pass.
24
+
25
+ - Build manifests (`<name>.build.json`) now bind the binary to the exact sources that built it. A source's sha256 was
26
+ computed after the build, by reading the file again, so a file saved while the build ran (an editor saving mid-build)
27
+ could be recorded beside a binary made from its previous text, and a test reusing that build (`testProgram`,
28
+ `buildForTest`) would take it as current. The build now hashes the bytes the compiler parsed (read once and checked
29
+ against the text TypeScript holds) and the runtime files before clang reads them, hashes every input again once the
30
+ binary is linked, and fails with no manifest when one changed; a previous build's manifest is removed before anything
31
+ is written (docs/cli.md; test/cli/toolchain.test.ts). Binaries are unchanged.
32
+ - First builds that run at once no longer lose a program's address. Two first builds of different programs (each holds
33
+ only its own program's lock) could read `typesol.json`, each add its address and write it back, the later write
34
+ dropping the earlier address (or a reader seeing a partly written file); and a keypair file was created by an
35
+ existence check and an ordinary write, so two first users of one could each make a key and the later replace the
36
+ earlier. `typesol.json` is now changed one process at a time (`typesol.json.lock`) and replaced whole by a rename,
37
+ also by `typesol new`; a keypair is written to a temporary file and linked into place, which fails if it exists, and
38
+ the process that loses reads the winner's key (docs/cli.md; test/cli/workspace.test.ts).
39
+ - `typesol init` and `typesol new` refuse to write through a symbolic link inside the project: a linked `programs/`,
40
+ `tests/` or `.cursor/`, or a link (even a dangling one) where a new file goes, used to receive the file wherever it
41
+ pointed. Files are now also created exclusively, so one created in the meantime is never overwritten. The project
42
+ directory itself may still be a link (docs/cli.md; test/cli/workspace.test.ts).
43
+ - Release manifests (`scripts/release-manifest.ts`): the test corpus hash now covers `showcase/test/` as well as
44
+ `test/` (the mainnet ports' differential tests, helpers and fixtures were left out, so a weakened comparison left the
45
+ hash unchanged) and records the directories it covers (`corpus.roots`). The script also refuses to make a release
46
+ manifest when `test/programs/SOURCES.md` lists a reference binary the tree lacks (`--allow-missing-references`
47
+ records them as `referencesMissing` instead) (docs/testing.md; test/cli/release-manifest.test.ts).
48
+ - Raydium CLMM and multisig ports: their tests now compare what the repository overview claims. For every transaction,
49
+ the bytes of every account an instruction names (not only a chosen list), the inner instructions, the return data
50
+ and the log lines are compared too, with the exceptions each test declares (Anchor's `Instruction:` line and its
51
+ error-message text; for Raydium CLMM also the Associated Token program's Create, called with `[0]` by the original
52
+ and with empty data by the port, pinned in the test). Where the original CLMM panics, the test now requires its
53
+ `ProgramFailedToComplete` and a numbered error from the port. The stronger comparison found that the Raydium CLMM
54
+ port logged four kinds of `msg!` line (from seven places) the deployed program does not: its source writes them only
55
+ with the `enable-log` feature, and the deployed binary holds none of their text. The port no longer writes them,
56
+ which also makes its swaps cheaper (docs/case-study-raydium-clmm.md has the new figures; its binary is 546,080
57
+ bytes, was 551,440); the golden reference (test/golden/binaries.json) is regenerated in the build container with
58
+ it and with the Marginfi and SPL Stake Pool binaries the runtime's changes give. 308 Raydium CLMM
59
+ transactions (not 302 as listed) and 55 multisig ones are compared.
60
+ - Percolator v16 tests: `World.restore` now removes an account its snapshot recorded as missing (one a transaction
61
+ created since survived the restore); no result of the v16 files that restore a world changed.
62
+
63
+ - Fixed (wrong account data, since 0.42.0): a whole struct or array assigned between two views of one account whose
64
+ bytes overlap, the destination after the source by less than the value's size, did not end with the source's value:
65
+ the copy went forward 8 bytes at a time and re-read bytes it had already written (copying a two-word value one word
66
+ to the right in `[1, 2, 3]` gave `[1, 1, 1]`, not `[1, 1, 2]`). Every byte is now loaded before any is stored, at
67
+ any size below 80 bytes (from 80 the memmove syscall copies them, as in the entry below), so the destination ends
68
+ with the source's old bytes in either direction, as Rust's `copy_within` leaves them. Only views of one account at
69
+ run-time byte offsets can overlap that way: `loadRawAt` / `loadRawMutAt` (0.43.0 on), or two views of an account
70
+ passed twice under `NATIVE_ACCOUNT_WRITES` (0.42.0 on). A program is affected if it assigns `d.v = s.v` (or a whole
71
+ view) between such views of one account and the destination's offset can be ahead of the source's by less than the
72
+ value's size; copies between different accounts, distinct fields, elements of one array, through a local, or by
73
+ `copyData` were right. The copy costs the same or less than before. Five of the 81 programs in the release manifest
74
+ build to other binaries for it (examples/profiles, Marginfi, Percolator v12.20 and its matcher, SPL Stake Pool); none of them relied on an overlapping copy (theirs are between distinct places or
75
+ elements of one array), their tests pass, and Marginfi's instructions cost 5 to 49 CU less
76
+ (docs/language-native.md; test/language/bulk-copies.test.ts, which no longer pins the old result).
77
+ - Fixed (wrong account data, since 0.39.0): another program's `@layout borsh` account (`Owner<Account<T>, "…">`)
78
+ whose struct declares a discriminator shorter than 8 bytes (`/** @discriminator 0x07 */`) was decoded from byte 8
79
+ instead of right after its discriminator: its fields were read from the wrong bytes (the valid account `[7, 42]`
80
+ of a struct holding one `u8` did not read 42), and an account shorter than 8 bytes made the decoder's length wrap and
81
+ read past the account's data. Its size was checked against the struct's in-memory size, not its smallest Borsh
82
+ form. The decoder now starts after the declared discriminator and the size check uses the Borsh form. A program is affected only if a struct is both `@layout borsh`
83
+ and `@discriminator` of 1 to 7 bytes and taken as `Owner<Account<T>, "…">`; fixed-layout structs with a shorter
84
+ discriminator were read right. The length check of a growable `Vec` in such a fixed-layout struct counted 8 bytes
85
+ of discriminator and refused accounts of the right size (3003); it now counts the declared length. `initAccount<T>`
86
+ of a struct with a shorter discriminator is now refused when compiling (it writes this program's 8 bytes)
87
+ (docs/language-accounts.md; test/language/foreign-account.test.ts).
88
+ - Fixed (since 0.17.0): `realloc` of a `@layout borsh` account refused sizes below its discriminator and the struct's
89
+ in-memory size (3016), which reserves the full capacity of every `FixedString` and `FixedVec`: an account whose
90
+ only field is an empty `FixedString<64>` could not shrink to the 12 bytes of its Borsh form, although its load
91
+ accepts 12. The smallest size is now the discriminator and the smallest Borsh form, the size the load checks; the
92
+ value written back when the instruction returns must still fit (3004 otherwise, as before). A program is affected
93
+ if it calls `realloc` on a `@layout borsh` account with a size that can fall below that bound: such transactions
94
+ failed with 3016 and now succeed (docs/language-accounts.md; test/language/realloc.test.ts).
95
+ - Fixed: a signed type's minimum reduced modulo -1 in a typed constant (`const X: i8 = -128n % -1n`) folded to 0,
96
+ while the same remainder at run time fails with 5100, as Rust's checked `%` does. It is now a compile error, as the
97
+ quotient `-128n / -1n` already was, at every signed width; an untyped constant stays a bigint without a width
98
+ (docs/language-basics.md, docs/language-types.md; test/language/signed-remainder.test.ts).
99
+ - Fixed: `log64(a, b, c, d, e)` lowered all five arguments before reading any, so an argument that runs code
100
+ changing an earlier one's value (`log64(a.count, bump(a), …)`) logged the changed value; each argument is now read
101
+ before the next is evaluated. `require(condition, code)` with an error code computed at run time likewise tested its
102
+ condition after computing the code; the condition is now read first. The other built-ins taking several values
103
+ already read them in order. Of the programs in the release manifest only Percolator v12.20's C changes (its
104
+ `log64` call reads a temporary one line earlier), and it builds to the same binary for this
105
+ (docs/language-statements.md; test/language/argument-order.test.ts).
106
+ - Fixed: inside `panicsAt(location, …)`, `**` took the panic for its multiplications ("attempt to multiply with
107
+ overflow" at the location) instead of failing with 5100 as its declaration says; it now fails with 5100, and an
108
+ operator written in its operands still panics at the location (docs/language-native.md; test/language/pow.test.ts).
109
+ - Fixed: a program built with a clang above 20 (platform-tools v1.57's clang 22, an untested toolchain, which TypeSOL
110
+ warns about but builds with) faulted at its first 128-bit multiplication or variable 128-bit shift ("Access
111
+ violation writing 8 bytes at address …"): the runtime's assembly `__multi3`, `__ashlti3`, `__lshrti3` and
112
+ `__ashrti3` take the result's address in r1, as clang 20 calls them, while clang 22 passes the first operand there
113
+ and takes the result in registers. The assembly is now compiled only for clang 20 and earlier; any later clang gets
114
+ C definitions of the four, which follow its own convention (test/language/builtins.test.ts runs them on every case
115
+ of every function for SBPF v0, v1 and v2; docs/runtime.md). With the tested toolchain nothing changes: every program
116
+ in the golden manifest builds to the same bytes.
117
+ - Added: `PANIC_STYLE = "pinocchio"`: a Rust panic as pinocchio's `entrypoint!` panic hook reports it under std, the
118
+ location's file verbatim (`src/v16.rs`, or a toolchain path such as
119
+ `/home/runner/work/platform-tools/platform-tools/out/rust/library/alloc/src/raw_vec/mod.rs`), then
120
+ `** PANICKED **`, then abort ("SBF program panicked"). `panic(message, location)` and `panicsAt` take the file
121
+ alone or `file:line:column` (only the file is logged; the message may be null); `PANIC_ON_OVERFLOW` is refused
122
+ beside it. Every panic site calls one shared helper. Checked line for line against a binary built with pinocchio
123
+ 0.11.1's entrypoint (test/language/pinocchio-panics.test.ts; docs/language-native.md).
124
+ - Added: `getReturnData()`: Rust's `get_return_data()`, `const [program, data] = getReturnData()`, the return data of
125
+ any length (up to 1,024 bytes) and the program that set it, unchecked, read with instruction data's methods; Rust's
126
+ `None` is `data.length === 0n`. `returnData<T>(program)` is unchanged (test/language/get-return-data.test.ts;
127
+ docs/language-cpi.md).
128
+ - Tests: a native program at `MAX_ACCOUNTS = 255n` takes a fixed prefix and a tail of 39 and 255 accounts with
129
+ repeats, reads and writes through them and forwards the tail whole in a CPI (test/language/many-accounts.test.ts).
130
+ - Showcase, Percolator v16 (work in progress, 0 of 50 instructions ported, not listed among the ports): the entry
131
+ of the port (the tag dispatch, every tag refused), compared with the Rust build of the pinned commits on empty data
132
+ and all 206 unknown tags; the reference's entrypoint recorded at its limits: 255 accounts (256 refused by the
133
+ runtime), its heap, RefCell conflicts on repeated accounts and its panic lines, partly through a probe built with
134
+ the same entrypoint (`scripts/percolator-v16-reference/probe.sh`; showcase/mainnet/percolator-v16/TESTING.md).
135
+ Every program in the golden manifest builds to the same bytes.
136
+ - Showcase, Percolator v16 (still 0 of 50 instructions ported): the persisted layouts as packed views tied field by
137
+ field to the offsets rustc prints for the pinned sources, the engine's wire conversions, `PercolatorError` and the
138
+ engine-error mapping, and `Instruction::decode` for all 50 tags, compared with the reference on every decode refusal
139
+ (field cuts, trailing bytes, vector counts, random bodies) and on where decoding ends; a decoded instruction ends in a
140
+ placeholder error until its handler is ported (showcase/mainnet/percolator-v16/README.md).
141
+ - Added: `copyData(account, from, to, length)`: a copy within one account's data, as a native program's
142
+ `data.copy_within(from..from + length, to)` (or a struct copied out and written back at another offset), with the
143
+ memmove syscall from 32 bytes (about constant compute units whatever the length, where a whole-struct assignment
144
+ moved words one by one until the change below); overlapping ranges allowed, 3003 past the end with nothing copied, 3006 on a read-only
145
+ account without `NATIVE_ACCOUNT_WRITES` (test/language/native-copy-data.test.ts; docs/language-native.md). Every
146
+ program in the golden manifest builds to the same bytes.
147
+ - Showcase, Percolator v16 (24 of 50 instructions ported, not listed among the ports): InitMarket, InitPortfolio,
148
+ Deposit, ClosePortfolio, UpdateAuthority, UpdateAssetAuthority, the four market-authority policies,
149
+ UpdateBackingFeePolicy, UpdateTradeFeePolicy, ConfigurePermissionlessResolve, UpdateBaseUnitMints, the two ledger
150
+ syncs, ConfigureEwmaMark, PushEwmaMark, ConfigureAuthMark, PushAuthMark, SetMatcherConfig, UpdateAssetLifecycle
151
+ (activation with the market grown by one slot, drain-only, retirement, shutdown into recovery; a permissionless
152
+ activation's insurance deposit and a lapsed backing bucket's expiry end in the port's placeholder),
153
+ RestartAssetOracle and CanonicalizeSpentBackingHistory, with the engine code they reach (the configuration's exact
154
+ solvency envelope, the market's shape, a portfolio's validation against the market, deposits, portfolio
155
+ registration, the raw oracle target, asset accrual and committed funding, slot activation, retirement, recovery and
156
+ restart). Compared whole with the Rust build of the pinned commits on their success paths and refusals, every
157
+ account position, a random walk that keeps the market live, a mutation fuzzer over the market, portfolios and both
158
+ ledgers, and seeded fuzzes of mark pushes and funding accruals (22,027 transactions, 5,944 successes); the port uses
159
+ 31% to 69% of the reference's compute units on average per instruction, fewer on every success. With
160
+ ConfigureAuthMark and SetMatcherConfig ported the author's own suite gets through its set-up
161
+ (showcase/mainnet/percolator-v16/README.md and TESTING.md). `scripts/percolator-v16-reference/author-suite.sh` takes
162
+ `TEST_FILTER` to run a subset of the author's tests.
163
+ - Changed (generated code of existing programs): whole values and account data are copied and zeroed by the memory
164
+ syscalls where the word loops cost more (measured table in runtime/typesol_rt.h; docs/runtime.md). A struct or
165
+ array copied whole between places reached through pointers (account data, views, a helper's struct parameter) is
166
+ the memmove syscall from 80 bytes (16 CU up to 2,749 bytes, where the unrolled loads and stores cost 26 at 80 bytes
167
+ and the loop about 1 CU a byte from 400), and zeroed whole there (`x.o = null` on an `Option<struct>`) the memset
168
+ syscall from 192. A copy into or out of a local of the function (a struct literal built in a temporary, a helper's
169
+ result, a local copy, Borsh fields, instruction arguments, events) takes the syscall only from 400 bytes, a local
170
+ zeroed whole from 600, where clang stops unrolling: below that it drops the stores and loads nothing reads, which an
171
+ opaque call prevents (measured with 80 and 192 there: SPL Stake Pool up to 2,825 CU more, Phoenix 7 to 98 more).
172
+ The bytes `resizeAccount`, `realloc` and a growable Vec's growth add are zeroed by the memset syscall from 64, and
173
+ an account's data at `close` when its type takes 64 bytes or more (9,563 bytes: about 45 CU instead of 4,800).
174
+ Below each threshold the code is what it was. 14 of the 81 programs in the release manifest build to other binaries
175
+ (examples/escrow and ledgerbook, Jito's two programs, Marginfi, Meteora DBC, Percolator v12.20 and its matcher,
176
+ Percolator v16, Raydium CLMM and CP-Swap, and the program-examples realloc, token escrow and token fundraiser); all
177
+ their tests pass, and each of the 161,578 transactions those tests send was run against the binary from before and
178
+ after: 18,451 cost less, 4 more. Two Percolator v16 InitPortfolio transactions cost one CU more (the account grows
179
+ by 8 and 16 bytes: the length is tested at run time), and two refusals of Meteora DBC's
180
+ initialize_virtual_pool_with_token2022_transfer_hook 2 more (its successes 3,079 less). Savings (mean per
181
+ successful transaction): Percolator v12.20 InitMarket 232,685 to 105,768, TradeCpi 3,414 less, PushHyperpMark
182
+ 1,297; Percolator v16 InitPortfolio from an empty account 4,750, Deposit and ClosePortfolio 2,069; Meteora DBC swaps
183
+ 2,056, create_config 3,976; Marginfi 106 to 1,940 on 30 instructions; an account's close 26 to 1,145 (examples/escrow
184
+ take and refund 74). A struct copied between two views of one account that overlap, the destination after the
185
+ source, ends with the source's old bytes from 80 bytes on (memmove); below 80 bytes, see the fix of overlapping
186
+ struct copies above (docs/language-native.md; test/language/bulk-copies.test.ts, which also pins a 1 KiB copy at
187
+ no more than 30 CU and an 8 KiB resize zero-fill at no more than 60).
188
+ - Showcase, Percolator v16 (25 of 50 instructions ported, not listed among the ports): ConfigureHybridOracle and the
189
+ external oracle readers of `mod oracle_v16` (Pyth PriceUpdateV2, Switchboard On-Demand under its mainnet and devnet
190
+ owners, Chainlink OCR2, composites of up to three legs with inversion and unit scale, the legs' coherence and commit,
191
+ the hybrid soft-stale predicate), and a permissionless activation's fee into market 0's insurance domains with its
192
+ SPL Token Transfer (UpdateAssetLifecycle's placeholder path for it removed). Compared whole with the Rust build of the
193
+ pinned commits: each source and composite on its success space, every refusal of the instruction and of each reader
194
+ field by field, a seeded fuzz of 400 configurations, the random walk and mutation fuzzer with a keeper that keeps the
195
+ external prices fresh, 34 permissionless appends (the fee doubled from asset 32) and a reuse; the reader's branches
196
+ that only the crank reaches compared on 1,500 vectors with the original's functions compiled for the host
197
+ (`scripts/percolator-v16-reference/oracle-vectors.ts`). All v16 tests: 23,211 transactions, 6,098 successes, each
198
+ cheaper in the port (ConfigureHybridOracle 52% of the reference's compute units on average); binary 289,728 bytes.
199
+ Every failure of the author's suite subsets rerun against the port reaches an instruction not ported yet
200
+ (showcase/mainnet/percolator-v16/README.md and TESTING.md).
201
+ - Showcase, Percolator v16 (27 of 50 instructions ported, not listed among the ports): SyncMaintenanceFee and Withdraw,
202
+ with the engine's maintenance fee (the fee anchor, the U256 fee saturated to u128, the loss settled from principal,
203
+ the fee charged into the insurance, the cranker's share credited from the insurance, the rest into asset 0's domain
204
+ budgets with the alternating carry, a portfolio its fee empties closed into the market, the deregistration's
205
+ LockActive swallowed as the original does) and `withdraw_not_atomic` (the close ledger, the equity after, the vault
206
+ PDA's signed SPL Token Transfer, the secondary collateral mint). The settlement of a portfolio's open legs against
207
+ the assets' K, F and B indices is not ported: both instructions stop there in the port's placeholder on a Live market
208
+ once the fee anchor has moved. Compared whole with the Rust build of the pinned commits on their success paths and
209
+ refusals, and on 400 generated states (a new reusable generator writes markets and portfolios with open legs, PnL up
210
+ to ±(2^127 − 1), fee debt and extreme totals that the original's validators accept, 91% of the Live ones); the walk
211
+ and mutation fuzzer run both instructions and start a fifth of the mutations from generated states. All v16 tests:
212
+ 24,454 transactions, 6,541 successes, each cheaper in the port (Withdraw 54%, SyncMaintenanceFee 62% of the
213
+ reference's compute units on average); binary 324,432 bytes. Every failure of the author's suite subsets rerun
214
+ against the port reaches an instruction not ported yet (showcase/mainnet/percolator-v16/README.md and TESTING.md).
215
+ - Showcase, Percolator v16 (still 27 of 50 instructions ported, not listed among the ports): the map of the settlement
216
+ of a portfolio's open legs, `settle_account_side_effects_not_atomic`, which SyncMaintenanceFee and Withdraw stop at:
217
+ 275 engine functions and 6,397 lines found by following the calls in the pinned source, layered in the source's own
218
+ order (leaf arithmetic, backing and lien primitives, impaired-lien reconciliation, source-claim burns and PnL
219
+ setters, K/F entries, B chunks, the driver), with what is ported (`scripts/percolator-v16-reference/settlement-map.py`,
220
+ NOTES.md section 10). Most of its leaf layer is ported (`kernels.ts`, 45 functions, 1,134 of the original's lines: the
221
+ source-lien arithmetic, the bucket and lien deltas, the K/F and B targets and deltas of a leg, the F snapshot after
222
+ settlement, the B chunk, the backing utilization fee, v16's wide_math helpers with their panic locations; its 33
223
+ market-view accessors remain), not yet
224
+ wired into an instruction. A new function-level harness compares each with the original's own function compiled
225
+ for the host in Docker (a child module added to a copy of the engine's `v16` module reaches the private functions
226
+ without changing any visibility): 90,000 seeded vectors equal, outputs, changed bytes, errors and panic locations;
227
+ interim evidence until the settlement can be compared with the reference binary (showcase/mainnet/percolator-v16/
228
+ README.md and TESTING.md).
229
+ - Showcase, Percolator v16 (still 27 of 50 instructions ported, not listed among the ports): the next three layers of
230
+ the settlement of open legs from the bottom: the rest of the leaf layer (the market-view and portfolio-view
231
+ accessors), the backing and lien primitives (source-credit setters and the domain recompute, the counterparty and
232
+ insurance liens' create, consume and release, fresh and loser-paid counterparty backing, a Fresh bucket's expiry,
233
+ the post-snapshot residual, the backing utilization fee's collection) and the impaired-lien reconciliation
234
+ (`primitives.ts`, `impairment.ts`, 80 functions, 1,440 of the original's lines; 35 functions, 1,939 lines, remain).
235
+ The function-level harness now takes whole markets and portfolios (the original's views built over the same bytes
236
+ as the program builds them, every byte of both accounts compared) on generated states, about 40% of them accepted by
237
+ the original's own validators and the rest deliberately invalid: 22,800 vectors equal; interim evidence, not the
238
+ reference binary. UpdateAssetLifecycle's retirement now expires a lapsed Fresh backing bucket instead of ending in
239
+ the port's placeholder, compared with the reference binary on 300 buckets written into the market (139 successes,
240
+ each cheaper in the port); binary 354,080 bytes.
241
+ - Showcase, Percolator v16 (still 27 of 50 instructions ported, not listed among the ports): the rest of the settlement
242
+ of a portfolio's open legs, `settle_account_side_effects_not_atomic`: the source-claim burns and PnL setters
243
+ (`claims.ts`), the K/F settlement entries with the par netting of a loss, the haircut-bounded close loss, the
244
+ loss-support booking and the capital-backed loss reservation (`kfsettle.ts`), the B chunks and the driver
245
+ (`settlement.ts`): 35 functions, 1,939 of the original's lines; all 275 functions of the map are now ported. It is
246
+ wired into SyncMaintenanceFee and Withdraw, whose placeholders are gone, and compared with the reference binary on
247
+ generated states with open legs (claims and liens on the market's domains, K/F/B indices, stale cohorts): 3,000 such
248
+ states and 2,000 ordinary ones, 5,000 mutations, every transaction alike, 328 successes that settled legs, the port
249
+ cheaper on every success (SyncMaintenanceFee 39% of the reference's compute units on the mean of those states).
250
+ Each function is also compared alone with the original's compiled for the host (33,000 vectors equal), on a
251
+ generator whose states the original's validators accept 58% of the time (40% before). Branch probes
252
+ (`scripts/percolator-v16-reference/coverage.ts`) show which branches of the port's functions each comparison runs:
253
+ 766 of 836, the rest unreachable from accepted states but for seven (TESTING.md). Binary 588,856 bytes.
254
+
255
+ - Showcase, Percolator v16 (still 27 of 50 instructions ported, not listed among the ports): every key the v16 tests
256
+ make comes from a seed drawn per run and printed with every failure (`PERCOLATOR_V16_SEED` replays it); the port and
257
+ its test programs are refused unless built by the tested toolchain throughout (a fault of one walk run at InitMarket
258
+ was a build by platform-tools v1.57's clang 22, whose link another process switched during the build, meeting the
259
+ runtime's assembly builtins: fixed above; showcase/mainnet/percolator-v16/TESTING.md section 5); the coverage copy is
260
+ one per process; set-ups over tens of thousands of key sets, capacities, PDA bumps and heap frames compared with the
261
+ reference (`percolator-v16-setup-stress.test.ts`); the map extended to margin and health certificates,
262
+ ConvertReleasedPnl and Withdraw (NOTES.md section 11: 33 functions, 764 lines not ported; no ported instruction
263
+ computes a certificate, and no state lets a portfolio with open legs withdraw).
264
+ - Showcase, Percolator v16 (29 of 50 instructions ported, not listed among the ports): TradeNoCpi and
265
+ ConvertReleasedPnl. TradeNoCpi's map (NOTES.md section 12, `settlement-map.py --trade`): 127 processor functions and
266
+ 127 engine functions new to the port (3,645 lines), all ported but six only the crank's refresh and the batch reach:
267
+ the margin and health certificates (`health.ts`), the engine's trade with its position routes, gates, fees, close
268
+ ledger, source liens and residue resets (`trade.ts`), and the processor's zero-move funding accrual, dynamic fee
269
+ quote, trade-driven mark, backing-domain fees and lien bounds (`trading.ts`); ConvertReleasedPnl in `convert.ts`.
270
+ Compared with the reference binary on dedicated tests (routes, 14 legs, bounds, fees, the initial margin to the unit,
271
+ every account pair) and on real state: a random walk in which trades open and close legs on three assets of four
272
+ portfolios while funding accrues, so that the settlement, the refresh and the certificates run on state the
273
+ instructions made (2 × 2,500 steps: 5,266 transactions, 2,058 trades and 22 conversions succeeding in both, 1,851 legs settled by a later instruction, 692 funding accruals with open interest, 4,076 certificates written), and a mutation fuzzer from such a snapshot; every transaction alike, every success
274
+ cheaper in the port (the worst trade: 595,297 CU in the reference, 238,926 in the port; TradeNoCpi 43% of the reference on the mean). Binary 846,712 bytes.
275
+ - Showcase, Percolator v16 (31 of 50 instructions ported, not listed among the ports): PermissionlessCrank on a Live
276
+ market and FinalizeResetSide. The crank's map (NOTES.md section 13, `settlement-map.py --crank`): 94 processor
277
+ functions and 133 engine functions new to the port (4,436 lines); ported, what a Live market reaches (89 engine
278
+ functions, 2,919 lines: the observation of each hinted asset with the hybrid's fall-back to its mark and its
279
+ liveness, accrual at moving prices, the engine's classifier and plan, the refresh with B chunks and lapsed backing,
280
+ liquidation partial and full with its fee and the cranker's reward, the insurance draw, the bankruptcy residual
281
+ booked into the other side's B index, ADL and the side modes, the close-progress ledger, AdvanceClose, the
282
+ declaration of Recovery, the flat account's source-lien release, a Recovery asset's committed-state refresh); a
283
+ market in Recovery, the forfeit of a Recovery asset's released obligation and a Resolved market's close end in the
284
+ port's placeholder where the original calls them (44 engine functions). The engine's NonProgress the processor
285
+ swallows after an accrual, the `clear_leg` Stale the engine swallows and a declared Recovery that liquidation's
286
+ caller turns into success are values in the port, leaving exactly the original's partial writes. Compared with the
287
+ reference binary on dedicated tests (hint shapes, oracle accounts stale, ahead, malformed or repeated, long gaps,
288
+ every account pair, liquidations, bankruptcies, a 14-leg portfolio) and on a real-state walk in which cranks keep
289
+ three assets current while marks and oracle prices move and steered portfolios are liquidated (3 × 8,000 steps:
290
+ 24,772 transactions, 7,604 crank successes, 476 liquidations (366 partial, 110 full), 116 cranker rewards, every one alike), and a mutation
291
+ fuzzer from snapshots with positions under water; every crank success cheaper in the port (40% of the reference on
292
+ the mean; the worst 1,376,639 CU in the reference, 505,213 in the port). Where a 14-leg crank runs the reference past
293
+ 1,400,000 CU, the port succeeds (recorded). Binary 1,005,456 bytes.
294
+ - Showcase, Percolator v16: the placeholder that ends a decoded instruction of an unported tag is now
295
+ Custom(0xc0de0000 + tag), no longer Custom(0x16dec000 + tag), whose log text `custom program error: 0x16dec0..`
296
+ the author's tests took for NonProgress (`custom program error: 0x16`) by its prefix.
297
+
298
+ - Showcase, Percolator v16 (37 of 50 instructions ported, not listed among the ports): PermissionlessCrank on a market
299
+ in Recovery (the forfeit of a released obligation, the market's resolution) and on a Resolved market (the account's
300
+ close-out: the source domains' preparation and realization, the resolved bankruptcy, the solvent legs' detachment,
301
+ the payout ledger and receipt, the payout's signed SPL Token Transfer), which removes the crank's four placeholders;
302
+ and ForfeitRecoveryLeg, RebalanceReduce, CureAndCancelClose, ResolveMarket, ResolveStalePermissionless and
303
+ CloseResolved. Compared whole with the Rust build of the pinned commits: six markets taken out of Live with open legs
304
+ (a declared Recovery with the owners' forfeits, ResolveMarket, ResolveStalePermissionless) and closed out portfolio by
305
+ portfolio with payouts, the conservation the original's tests assert checked in both VMs and never failing, account
306
+ and data sweeps of each instruction, RebalanceReduce on real state, CureAndCancelClose on generated close ledgers; the
307
+ crank walk now resolves and closes out markets, and its mutation fuzzer starts from markets in Recovery and Resolved.
308
+ All v16 tests: 42,222 transactions, 16,223 successes, each cheaper in the port (CloseResolved 35%, ForfeitRecoveryLeg
309
+ 37%, RebalanceReduce 37%, CureAndCancelClose 36% of the reference's compute units on average); binary 1,139,536 bytes
310
+ (showcase/mainnet/percolator-v16/README.md, NOTES.md sections 13 and 14, TESTING.md). No compiler change.
311
+ - Showcase, Percolator v16 (47 of 50 instructions ported, not listed among the ports): the insurance and backing-bucket
312
+ instructions (TopUpInsurance, TopUpInsuranceDomain, TopUpBackingBucket, WithdrawBackingBucket,
313
+ WithdrawBackingBucketEarnings, WithdrawInsuranceAsset, with the engine's fresh-backing deposit and withdrawal, the
314
+ resolved backing surplus, the earnings and domain-insurance withdrawals and the terminal claim-free recredit) and the
315
+ terminal ones (CloseSlab with its terminal scan, the retirement and burn of the vault, the vaults closed and the
316
+ tombstone; ClaimResolvedPayoutTopup; SwapSecondaryForPrimary; ForceCloseAbandonedAsset on the trade engine). Left:
317
+ TradeCpi, BatchTradeNoCpi, BatchTradeCpi. Compared whole with the Rust build of the pinned commits: top-ups and
318
+ withdrawals among trades and cranks, markets resolved and closed by CloseSlab, a second mint swapped and closed, a
319
+ shut-down asset force-closed and drained, payout top-ups after a lapse of backing, account and data sweeps of each;
320
+ the walks now move reserves, shut assets down and close their markets, and the conservation check is asserted
321
+ wherever it is collected. All v16 tests: 68,632 transactions, 24,657 successes, each cheaper in the port (ForceCloseAbandonedAsset 36%,
322
+ CloseSlab 36%, TopUpBackingBucket 33%, WithdrawInsuranceAsset 40% of the reference's compute units on average);
323
+ binary 1,258,064 bytes. The author's suite: one failure in a ported path, `inv_078`, which expects a force-close to
324
+ exceed the compute-unit limit that the port's stays within (showcase/mainnet/percolator-v16/README.md, NOTES.md section 15,
325
+ TESTING.md). No compiler change.
326
+ - Showcase, Percolator v16 tests (no compiler change): a run that compared nothing can no longer pass for one. CI
327
+ gains a `percolator-v16` job that builds the five v16 binaries from the pinned sources in Docker, checks each against
328
+ the sha256 test/programs/SOURCES.md records and runs every v16 test file under `CI_REQUIRE_ALL=built`; there a
329
+ missing binary, a missing port source or a test file that compared no transaction fails (each file prints its count;
330
+ locally, without the binaries, the files still skip and print 0). The showcase job no longer runs them. Where the
331
+ reference is rerun under a raised compute budget, that run now starts from the exact pre-transaction state of every
332
+ covered account (one that did not exist is removed, not left as an earlier replay had it), the port is compared with
333
+ that run's accounts, and an account the run closes is removed from the reference afterwards; the harness test checks
334
+ both cases. The path tests assert the evidence of the paths they name (liens, the backing-domain fee, TradeCpi's cap
335
+ refusal, the lien releases; the gap test's uncovered losses and closes; the haircut test's receipts and top-up), and
336
+ the gap test no longer claims the paths it was written for but does not reach. The log comparison drops the port's
337
+ `0xc0de` probe lines only in coverage runs and matches the runtime's compute-unit line whole. The README, NOTES and
338
+ TESTING now say what CI compares, why two omitted token-value proofs cannot change an outcome (NOTES.md section 17),
339
+ where the port does allocate (section 18), and the refusal and transaction counts as measured.
340
+ - Showcase, Percolator v16 at commit 7b110913 (engine 5e3af07), complete: all 50 instructions ported, now listed among
341
+ the ports (its reference is a binary built here from the author's pinned source, not a deployed program). The last
342
+ three: BatchTradeNoCpi (the engine's batch: one refresh, the position maps kept across up to 14 legs, one end-state
343
+ margin check, the collected fees allocated to the legs) and the matcher ABI v3 with TradeCpi and BatchTradeCpi (the
344
+ LP's matcher config and delegate PDA, the tail check, the accrual and currentness before the call, the call signed by
345
+ the delegate, the answers validated, the slippage and fee caps). The placeholder for unported tags is gone. Compared
346
+ whole through the author's auth and hostile matchers, percolator-match and a rogue matcher of the tests' own (failing,
347
+ changing accounts, calling back, return data too long, short or unasked, resized contexts, prices out of range); batch
348
+ and matcher trades now in both walks. Where the reference runs out of compute units and the port does not, the
349
+ reference is run again under a raised compute budget and the port must equal that run (9 cases, all equal). New
350
+ real-state paths: a trade's counterparty-backed source lien with its backing-domain fee, the provider's earnings
351
+ withdrawn, ReleaseSourceLiens, a lien released at the resolved close. All v16 tests (2026-11-20): 70,881
352
+ transactions compared with the port, 70,678 of them with a Percolator instruction, 25,995 successes, each cheaper in
353
+ the port, and of the 44,683 refusals 44,673 cheaper and 10 at 0 in both; binary 1,362,760 bytes (reference 1,375,936). The author's whole suite
354
+ found one difference, fixed (a matcher's price above MAX_ORACLE_PRICE must be OracleInvalid); its full run on both
355
+ binaries is the next entry. No compiler change.
356
+ - Percolator v16: the author's whole suite (2,071 tests, all six targets unfiltered) ran on the reference and on the
357
+ port's current binary with every transaction recorded and compared (results, errors, return data, logs and every
358
+ account of the transaction's key list, by hash). The reference passes 2,062 and the port 2,060; the 9 failures of
359
+ the reference are its own and the port fails them at the same assertion; the port's 2 others assert the reference's
360
+ compute units (a peak of 554,832; a one-shot force-close expected to exceed the limit, which the port completes).
361
+ Of 2,324,991 transactions compared, 2,324,990 are identical, the other that force-close. None of the 2,127,486
362
+ identical successes costs the port more compute units: port 67,489,438,873, reference 128,297,605,017. The
363
+ first full run, on the port's previous binary, had found 282 that did, at the author's largest shapes
364
+ (ResolveMarket, CloseSlab, InitMarket); they were fixed (next entry) and the full run repeated. The author-suite and
365
+ trace scripts now fail on a target that does not compile, times out or runs nothing, on an empty trace, and on any
366
+ failure, difference or compute-unit excess not listed with its reason in
367
+ `scripts/percolator-v16-reference/author-suite-expected.tsv` (or a listed one no longer seen); the trace writer
368
+ writes each line at once and stops a test it cannot record (showcase/mainnet/percolator-v16/README.md, TESTING.md
369
+ section 3).
370
+ - Percolator v16: the three excesses the author's suite found are removed (no compiler change). ResolveMarket and
371
+ ResolveStalePermissionless (the committed-accrual scan of every configured slot), CloseSlab (the terminal scan of up
372
+ to 256 assets a call) and InitMarket (asset 0's profile copied into every slot) made a view per slot, each with its
373
+ own owner and bounds check and an offset computed with overflow checks, where the original indexes a slice whose
374
+ bounds the market view checked once; they now read the slots through one view of the slot array, and CloseSlab makes
375
+ the two backing expiries effective only for an asset whose step reads them. On a 10 MiB market (5,682 slots):
376
+ ResolveMarket: port 64,034, reference 65,546 (the port was 166,304); InitMarket: port 146,361, reference 211,905 (the
377
+ port was 214,540); a CloseSlab scan of 256 assets with fresh backing: port 17,682, reference 41,318 (was port
378
+ 42,314, reference 38,318). The ResolveMarket
379
+ scan now costs 11 instructions a slot as the reference's does; the port's lead there is its smaller fixed part.
380
+ `percolator-v16-shapes.test.ts` compares the three on markets of 1,000 and 5,682 slots (each success must cost the
381
+ port less; the previous binary fails all three tests). All 31 v16 files (2026-11-21): 226 tests, 70,928
382
+ transactions compared with the port, 26,035 successes, each cheaper in the port. The 20 author's tests whose transactions showed the excesses ran again on the new binary: all pass, their 144,407
383
+ transactions are identical to the reference's recorded ones, and none of their 143,473 identical successes costs the
384
+ port more (the 10 MiB ResolveMarket: port 64,080, reference 65,584); `author-suite-expected.tsv` lists no compute-unit excess
385
+ any more. The whole suite then ran again on the new binary (2026-11-21 to 2026-11-23): no excess anywhere (previous
386
+ entry). Binary 1,362,872 bytes
387
+ (was 1,362,760), sha256 `01c33233…` (showcase/mainnet/percolator-v16/README.md "Where the port costs more",
388
+ TESTING.md).
389
+ - Percolator v16: UpdateAssetLifecycle's permissionless activation now refuses an overflowing doubled fee exactly as
390
+ the original does (EngineArithmeticOverflow whenever a doubling overflows u128, a stored base fee of u128::MAX at an
391
+ asset index of 32 or more included; the port used u128::MAX as its overflow marker and let that base through to the
392
+ maximum-fee check). No instruction stores a base fee above u64::MAX (UpdateMarketInitFeePolicy refuses it), so the
393
+ lifecycle test writes such fees into the market (u128::MAX, u128::MAX/2 + 1, u128::MAX/2) and compares the appending
394
+ and reuse routes at indices 7, 33 and 35; the previous binary fails it. `percolator-v16-shapes.test.ts` now also drives
395
+ CloseSlab's Expire step, a nonzero recredit, the last batch refused while a domain budget remains and ReadyToClose on
396
+ the 5,682-slot market, and asserts the LockActive its wait case gives. The author-suite trace writer leaves out only
397
+ the runtime's whole compute-unit line (and the port's probe lines only when probes are on); the trace comparison
398
+ classes every differing transaction of a test (each kind must be listed for that test) and judges `main.trace`'s
399
+ groups of equal lines whose compute units vary against their cheapest reference line. All 31 v16 files (2026-11-23):
400
+ 227 tests, 70,975 transactions compared with the port, 26,077 successes, each cheaper in the port; of 44,695
401
+ refusals 44,685 cheaper and 10 at 0 in both. Binary 1,362,912 bytes (was 1,362,872), sha256 `c6dc6b24…`. The author's
402
+ whole suite ran again on this binary (2026-11-23 to 2026-11-24) and on the reference (2026-11-25 to 2026-11-26),
403
+ both with these scripts: the same passes and failures, the `inv_078` force-close the one difference, and no
404
+ identical success costing the port more (port 67,489,438,873 units, was 67,489,010,058; the figures above are this
405
+ run's). No compiler change.
9
406
  ## 0.49.0 — 2026-11-16
10
407
 
11
408
  A minor release: it adds a port of Percolator v12.20 (all 27 instructions, compared with the immutable mainnet build)
package/NOTICE CHANGED
@@ -97,5 +97,14 @@ Third-party material in this repository only (not in the published package)
97
97
  audited, not for use with real funds. Its mainnet binary is not kept here: scripts/fetch-programs.sh downloads it
98
98
  (test/programs/SOURCES.md). showcase/mainnet/percolator/matcher/ is a TypeSOL port of the matcher TradeCpi calls,
99
99
  aeyakovenko/percolator-match (commit 199b139), Copyright Anatoly Yakovenko, Apache-2.0, kept as a test fixture.
100
+ - showcase/mainnet/percolator-v16/: a TypeSOL port of Percolator v16, all 50 instructions, the program
101
+ aeyakovenko/percolator-prog (commit 7b11091) with its risk engine aeyakovenko/percolator (commit 5e3af07), Copyright
102
+ Anatoly Yakovenko, Apache-2.0 (the licence text is test/programs/LICENSE-Apache-2.0.txt), with its tests
103
+ showcase/test/percolator-v16*.ts, whose layout table (percolator-v16-layout.ts) transcribes the original's account
104
+ structs. Changes: rewritten in TypeSOL. The original's own warning stands for the port: an educational research
105
+ project, not audited, not for use with real funds. No v16 build is deployed to compare with:
106
+ scripts/percolator-v16-reference/ builds the reference binary from those commits, and the matchers its tests load
107
+ (aeyakovenko/percolator-match commit 60aac3a and two test matchers of percolator-prog, Apache-2.0), in Docker; none
108
+ of the binaries is kept here (test/programs/SOURCES.md).
100
109
  - showcase/program-examples/: ports of solana-developers/program-examples (MIT, Copyright Solana Foundation; the
101
110
  licence text is in showcase/program-examples/README.md).
package/README.md CHANGED
@@ -74,8 +74,8 @@ the port and to the binary deployed on mainnet, both in LiteSVM, and require the
74
74
  bytes in every account the transaction names, and the same error code and log lines, with the exceptions each case
75
75
  study lists. Of those, the kinds that recur:
76
76
 
77
- - **Error-message text.** The Anchor ports log their errors in TypeSOL's words, with Anchor's codes; Jito's also leaves
78
- out Anchor's `Instruction: …` lines.
77
+ - **Error-message text.** The Anchor ports log their errors in TypeSOL's words, with Anchor's codes; Jito's, Raydium
78
+ CLMM's and the multisig's also leave out Anchor's `Instruction: …` lines.
79
79
  - **Panics.** Where the original panics, Marginfi, Raydium CLMM, Raydium CP-Swap and Jito MEV fail with a numbered
80
80
  error, and Marginfi also answers a few runtime errors that carry no code (`AccountBorrowFailed`, `BorshIoError`)
81
81
  with numbered ones; the tests require that both fail.
@@ -93,14 +93,26 @@ each (for Percolator, the port's README) says what was compared and what was not
93
93
  | [Marginfi v2](docs/case-study-marginfi.md) | Anchor, lending | 124 | 2,321 |
94
94
  | [Phoenix v1](docs/case-study-phoenix.md) | native, limit order book | 28 | 3,575 |
95
95
  | [SPL Stake Pool](docs/case-study-spl-stake-pool.md) | native, liquid staking | 27 | 2,107 |
96
- | [Raydium CLMM](docs/case-study-raydium-clmm.md) | Anchor, concentrated liquidity | 37 | 302 |
96
+ | [Raydium CLMM](docs/case-study-raydium-clmm.md) | Anchor, concentrated liquidity | 37 | 308 |
97
97
  | [Raydium CP-Swap](docs/case-study-raydium-cp-swap.md) | Anchor, constant product | 21 | 136 |
98
98
  | [Raydium AMM v4](docs/case-study-raydium-amm.md) | native, constant product | all | 144 (60 random steps) |
99
99
  | [Jito MEV](docs/case-study-jito-mev.md) | Anchor, three programs | 24 | 150 |
100
100
  | [Percolator v12.20](showcase/mainnet/percolator) | native, perpetuals risk engine | 27 | 139,185 (132,031 random or mutated: 3,711 in random walks on fixed seeds, 128,320 from the mutation fuzzers) |
101
+ | [Percolator v16 at commit 7b110913 (engine 5e3af07)](showcase/mainnet/percolator-v16) | native, multi-asset perpetuals risk engine; compared with a binary built here from the author's pinned source, not a deployed program | 50 | 70,975 |
101
102
  | [coral-xyz/multisig](docs/case-study-multisig.md) | Anchor | all | 55 |
102
103
 
103
- A tenth port is held to a narrower comparison and is not counted above:
104
+ No Percolator v16 build is deployed, so its row is the one port above not compared with a mainnet binary: its
105
+ reference is the Rust build of the pinned commits (reproducible, its recipe matching the author's recorded hash at an
106
+ older commit). Not compared there: a deployed program, matchers other than the three the author's tests load and one
107
+ of the tests' own, and a few paths no instruction sequence reached (its README lists them); where the reference runs
108
+ out of compute units the port is compared with the reference run under a raised budget. The author's own suite ran on
109
+ both binaries, with every transaction compared (2,324,990 of 2,324,991 identical, the other a force-close that exceeds
110
+ the reference's compute budget); none of the 2,127,486 identical successes costs the port more (port 67,489,438,873
111
+ units, reference 128,297,605,017). A first run, on an earlier binary of the port, had found
112
+ 282 such successes at the author's largest market shapes (ResolveMarket, CloseSlab, InitMarket); the cause was fixed
113
+ and the full run repeated (its README has the figures).
114
+
115
+ A further port is held to a narrower comparison and is not counted above:
104
116
  [Meteora Dynamic Bonding Curve 0.2.2](showcase/mainnet/meteora-dbc) (Anchor, launchpad, all 35 instructions, with its
105
117
  migrations into DAMM v1 and DAMM v2). Outcomes, error codes, account bytes, inner instructions (its events are
106
118
  self-CPIs) and return data are compared as for the ports above, with the exceptions its README lists; of the log only
@@ -108,7 +120,10 @@ the events' `Program data:` lines are compared, not the rest of its text, and co
108
120
  port, its tests (`showcase/test/meteora-dbc*.ts`) and their fixtures (`showcase/test/fixtures/meteora-dbc/`) are under
109
121
  Meteora's Non-commercial Licence, not this repository's (see [NOTICE](NOTICE)).
110
122
 
111
- Each count is what a default test run compares, with the fetch-only binaries present (`pnpm fetch:programs`). Random
123
+ Each count is what a default test run compares, with the fetch-only binaries present (`pnpm fetch:programs`); the
124
+ Percolator v16 count needs its reference binaries built as well (`scripts/percolator-v16-reference/build.sh` and
125
+ `probe.sh`, Docker), as CI's `percolator-v16` job does, and is the sum of the `percolator-v16 compared: …` line each of
126
+ its test files prints (without the binaries those files skip and print 0). Random
112
127
  walks, with fixed or printed seeds, run on top of the other ports' counts ([docs/testing.md](docs/testing.md)); the
113
128
  multisig port has none. The
114
129
  sources are in [`showcase/mainnet`](showcase/mainnet), and where each original binary comes from is recorded in
@@ -497,6 +512,7 @@ Case studies: [Marginfi v2](docs/case-study-marginfi.md), [Phoenix v1](docs/case
497
512
  | [`raydium-amm/`](showcase/mainnet/raydium-amm) | Raydium AMM v4, the original constant-product AMM and a native (non-Anchor) program, in full: pool creation, deposits and withdrawals, the v1 and v2 swaps, P&L and administration, down to its log records and panics |
498
513
  | [`meteora-dbc/`](showcase/mainnet/meteora-dbc) | Meteora Dynamic Bonding Curve 0.2.2 in full, all 35 instructions: configs, pool creation on SPL Token and Token-2022 (transfer fees and hooks), the three swap modes, fee schedulers and the rate limiter, fee claims, the locker, and the migrations into DAMM v1 and DAMM v2. Under Meteora's Non-commercial Licence (its own `LICENSE.md`); log text and compute units are not compared |
499
514
  | [`percolator/`](showcase/mainnet/percolator) | Percolator v12.20, Anatoly Yakovenko's perpetuals risk engine and its native program, in full, all 27 instructions, against the immutable mainnet build: one 1.5 MB slab of 4,096 accounts, U256 and U512 arithmetic, trades through matcher programs, funding, liquidation, the keeper crank with pro-rata loss socialisation and side resets, resolution and teardown. The author's own suite gives the same outcome on every test under both binaries (660 passed). Upstream is educational and not audited |
515
+ | [`percolator-v16/`](showcase/mainnet/percolator-v16) | Percolator v16 at commit 7b110913 (engine 5e3af07), Anatoly Yakovenko's multi-asset perpetuals risk engine and its native program, all 50 instructions: portfolios of up to 14 legs, trades direct, batched and through matcher programs, the crank with liquidation, bankrupt closes, Recovery and resolution, insurance and backing buckets with source liens, terminal close-out. Compared with a binary built from the author's pinned source (not a deployed program). Upstream is educational and not audited |
500
516
  | [`multisig.ts`](showcase/mainnet/multisig/multisig.ts) | coral-xyz/multisig: stored instructions run with `invokeInstruction`, a PDA signing, Anchor's Borsh accounts |
501
517
 
502
518
  ## Status
@@ -508,11 +524,12 @@ change.
508
524
  The two latest, of 0.43.0 and 0.44.0 in November 2026, found defects that made a program that compiled behave
509
525
  differently from its source; each is fixed with a test, and [docs/audit.md](docs/audit.md) lists them, what the
510
526
  reviews covered and what they did not. Programs built before 0.44.1 should be rebuilt.
511
- - 0.45.0 to 0.49.0 have had no security review. They add, among others,
527
+ - 0.45.0 to 0.50.0 have had no security review. They add, among others,
512
528
  `runtime/typesol_builtins.c` (the compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`,
513
- `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), and `zeroData`, `log64`,
529
+ `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), `zeroData`, `log64`,
514
530
  `PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
515
- `NATIVE_ACCOUNT_WRITES` (0.49.0).
531
+ `NATIVE_ACCOUNT_WRITES` (0.49.0), and `copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"` and whole values
532
+ copied and zeroed by the memory syscalls (0.50.0).
516
533
  - From 0.44.0 on, a release that only fixes defects is a patch with no new language surface and a binary diff in its
517
534
  notes ([SECURITY.md](SECURITY.md#fix-releases)), and the npm tarball is the one packed from the tag and recorded
518
535
  in [releases/](releases).
package/SECURITY.md CHANGED
@@ -8,11 +8,12 @@ TypeSOL generates programs that hold funds. Treat it accordingly.
8
8
  0.44.0 on 2026-11-11, found defects in the compiler (wrong token-wrapper instruction data, and a reference that could
9
9
  outlive a resize and reach another record) and a latent one in the runtime; they are fixed in 0.44.1. The one
10
10
  before it, of 0.43.0, found defects fixed in 0.44.0 (one of them could break an authorization check in a helper).
11
- 0.45.0 to 0.49.0 have had no security review. They add, among others,
11
+ 0.45.0 to 0.50.0 have had no security review. They add, among others,
12
12
  `runtime/typesol_builtins.c` (the compiler builtins as TypeSOL's own C, 0.45.0), `transferCheckedWithHook`,
13
- `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), and `zeroData`, `log64`,
13
+ `EVENT_AUTHORITY_CHECK` and the reads of processed sibling instructions (0.48.0), `zeroData`, `log64`,
14
14
  `PANIC_STYLE = "solana-1.18"`, `executable` on remaining accounts and lamport writes on remaining accounts under
15
- `NATIVE_ACCOUNT_WRITES` (0.49.0).
15
+ `NATIVE_ACCOUNT_WRITES` (0.49.0), and `copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"` and whole values
16
+ copied and zeroed by the memory syscalls (0.50.0).
16
17
  **Rebuild and redeploy programs built before 0.44.1**;
17
18
  [docs/security-model.md](docs/security-model.md#status) gives the status, its sections on each review say how to
18
19
  tell whether a program was exposed, and [docs/audit.md](docs/audit.md#earlier-reviews) what each review did and did
@@ -22,6 +22,8 @@ export interface Analysis {
22
22
  sourceFile: ts.SourceFile;
23
23
  /** Every TypeSOL file of the program, entry last. */
24
24
  files: string[];
25
+ /** Each of those files' text as the compiler parsed it (a build checks the bytes it records against it). */
26
+ texts: Map<string, string>;
25
27
  /** Local identifier -> `typesol` export name, for imports. */
26
28
  imports: Map<string, string>;
27
29
  reporter: Reporter;
@@ -1049,6 +1049,7 @@ export function analyze(entry, files) {
1049
1049
  },
1050
1050
  sourceFile,
1051
1051
  files: programFiles(program, entryPath).map((f) => f.fileName),
1052
+ texts: new Map(programFiles(program, entryPath).map((f) => [f.fileName, f.text])),
1052
1053
  imports: entryImports,
1053
1054
  reporter,
1054
1055
  checker,
@@ -1084,7 +1085,8 @@ const CONST_OPS = new Set([
1084
1085
  * declared before it (in this file or an imported one). JS's bigint results (division truncates, `%` keeps the
1085
1086
  * dividend's sign, `>>` rounds down, as Rust's integers do). With `width` (a typed constant, `const X: u64 = …`), every
1086
1087
  * step must fit in that type, as Rust computes a typed const; without one the result is a literal, checked where it is
1087
- * used. Division by zero, a negative exponent or shift, and a value past 256 bits are compile errors.
1088
+ * used. Division by zero, a typed constant's signed minimum divided by or reduced modulo -1, a negative exponent or
1089
+ * shift, and a value past 256 bits are compile errors.
1088
1090
  */
1089
1091
  function foldConstant(e, constants, reporter, width) {
1090
1092
  const fit = (v, at) => {
@@ -1136,6 +1138,10 @@ function foldConstant(e, constants, reporter, width) {
1136
1138
  case ts.SyntaxKind.PercentToken:
1137
1139
  if (r === 0n)
1138
1140
  reporter.fail(b, `${b.getText()} divides by zero`);
1141
+ // A signed type's minimum by -1: its quotient does not fit, and its remainder fails with it, as at run time
1142
+ // (5100) and in Rust (`i8::MIN % -1` overflows), though JS's bigint gives 0.
1143
+ if (width && INT_INFO[width].signed && l === INT_INFO[width].min && r === -1n)
1144
+ reporter.fail(b, `${b.getText()} overflows ${width}: ${width}'s minimum divided by -1 does not fit, and its remainder fails with it`);
1139
1145
  return fit(b.operatorToken.kind === ts.SyntaxKind.SlashToken ? l / r : l % r, b);
1140
1146
  case ts.SyntaxKind.AsteriskAsteriskToken:
1141
1147
  if (r < 0n)
@@ -137,10 +137,11 @@ export declare abstract class EmitterBase {
137
137
  * `const PANIC_STYLE = "solana-1.14"` / `"solana-1.18"`: a Rust panic logs what that solana-program's panic handler
138
138
  * logs and then aborts, so the runtime reports "SBF program panicked". rustc before 1.73 (solana-program 1.14 to
139
139
  * 1.17) formats a panic as `panicked at '<message>', <file>:<line>:<col>`; from 1.73 (solana-program 1.18's toolchain)
140
- * as `panicked at <file>:<line>:<col>:\n<message>`, one log line holding the newline. By default it logs the message
141
- * and calls sol_panic_ with the location.
140
+ * as `panicked at <file>:<line>:<col>:\n<message>`, one log line holding the newline. `"pinocchio"`: pinocchio's
141
+ * `default_panic_handler!` hook logs the location's file alone, then "** PANICKED **", and std aborts. By default it
142
+ * logs the message and calls sol_panic_ with the location.
142
143
  */
143
- protected panicStyle(): "solana-1.14" | "solana-1.18" | undefined;
144
+ protected panicStyle(): "solana-1.14" | "solana-1.18" | "pinocchio" | undefined;
144
145
  /** The C statements of a Rust panic with `message` (undefined: nothing logged) at `location` ("file:line:col"). */
145
146
  protected panicC(message: string | undefined, location: string): string[];
146
147
  /** `file.ts:line:column` of a node (1-based, as Rust reports a location). */