@typesol/cli 0.48.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.
- package/CHANGELOG.md +556 -1
- package/NOTICE +17 -1
- package/README.md +122 -43
- package/SECURITY.md +6 -0
- package/dist/compiler/analyze.d.ts +2 -0
- package/dist/compiler/analyze.js +7 -1
- package/dist/compiler/emit/base.d.ts +7 -4
- package/dist/compiler/emit/base.js +17 -5
- package/dist/compiler/emit/borsh.js +8 -8
- package/dist/compiler/emit/calls.d.ts +6 -0
- package/dist/compiler/emit/calls.js +110 -11
- package/dist/compiler/emit/cpi-core.js +3 -3
- package/dist/compiler/emit/cpi.js +2 -2
- package/dist/compiler/emit/expressions.d.ts +1 -0
- package/dist/compiler/emit/expressions.js +15 -1
- package/dist/compiler/emit/function.js +12 -8
- package/dist/compiler/emit/program.js +10 -4
- package/dist/compiler/emit/rbtree.js +1 -1
- package/dist/compiler/emit/shared.d.ts +12 -2
- package/dist/compiler/emit/shared.js +26 -6
- package/dist/compiler/emit/statements.d.ts +8 -1
- package/dist/compiler/emit/statements.js +53 -5
- package/dist/compiler/emit/storage.js +20 -13
- package/dist/compiler/emit/views.js +1 -1
- package/dist/compiler/hints.js +3 -0
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +50 -9
- package/dist/keys.d.ts +12 -1
- package/dist/keys.js +57 -7
- package/dist/workspace.d.ts +8 -0
- package/dist/workspace.js +90 -15
- package/docker/deps/0.49.0.lock.json +1206 -0
- package/docker/deps/0.50.0.lock.json +1206 -0
- package/docs/architecture.md +3 -3
- package/docs/audit.md +33 -16
- package/docs/case-study-escrow.md +7 -5
- package/docs/case-study-jito-mev.md +14 -14
- package/docs/case-study-marginfi.md +142 -129
- package/docs/case-study-multisig.md +18 -5
- package/docs/case-study-raydium-amm.md +2 -1
- package/docs/case-study-raydium-clmm.md +44 -28
- package/docs/case-study-raydium-cp-swap.md +18 -18
- package/docs/case-study-spl-stake-pool.md +4 -3
- package/docs/cli.md +4 -3
- package/docs/language-accounts.md +21 -16
- package/docs/language-basics.md +4 -1
- package/docs/language-builtins.md +6 -2
- package/docs/language-cpi.md +34 -0
- package/docs/language-errors-events.md +1 -1
- package/docs/language-native.md +73 -7
- package/docs/language-statements.md +5 -3
- package/docs/language-types.md +13 -3
- package/docs/language.md +2 -2
- package/docs/mainnet.md +1 -1
- package/docs/runtime.md +25 -1
- package/docs/security-model.md +12 -4
- package/docs/stability.md +10 -4
- package/docs/testing.md +22 -6
- package/docs/troubleshooting.md +1 -1
- package/lib/typesol.d.ts +43 -3
- package/llms-full.txt +190 -51
- package/llms.txt +2 -1
- package/package.json +3 -3
- package/releases/0.48.0.json +847 -0
- package/releases/0.49.0.json +857 -0
- package/runtime/typesol_builtins.c +47 -2
- package/runtime/typesol_rt.h +131 -4
package/docs/language-types.md
CHANGED
|
@@ -50,7 +50,9 @@ export function record(stats: Mut<Stats>, by: u64, change: i64): void {
|
|
|
50
50
|
u8; convert with u64(...) etc.` Comparisons (`<`, `<=`, `===`, …) need equal types too.
|
|
51
51
|
- **Every operation is checked.** `+ - * / % **` and their assignments (`+=` … `**=`) fail the instruction on
|
|
52
52
|
overflow (5100) or division by zero (5101); `**` with a negative exponent fails as well (JavaScript throws there).
|
|
53
|
-
Unlike JavaScript there are no silent wraps and no `Infinity`.
|
|
53
|
+
Unlike JavaScript there are no silent wraps and no `Infinity`. A signed type's minimum divided by -1 overflows, and
|
|
54
|
+
so does its remainder by -1 (`x % -1n` with an `i8` holding -128 fails with 5100, as Rust's checked `%` does, where
|
|
55
|
+
JavaScript gives 0); a typed constant computing it is a compile error ([constants](language-basics.md#constants)).
|
|
54
56
|
- **Bitwise operators.** `& | ^` work on equal types; `~` flips the bits within the type's width (`~1n` as a `u8` is
|
|
55
57
|
254). Both shifts fail (5100) when the amount is negative or not below the width (`x >> 64n` on a `u64`), and `<<`
|
|
56
58
|
also when bits would be lost; `>>` is arithmetic on signed types. Unlike JavaScript, where a bigint shift never
|
|
@@ -300,8 +302,16 @@ export function step(player: Mut<Player>, dx: u64): void {
|
|
|
300
302
|
order, back to back, with no padding.
|
|
301
303
|
- A struct literal names every field (`{ x, y: 2n }`); a missing or unknown field is an error. An object literal needs
|
|
302
304
|
a known struct type: a typed local (`const p: Point = { … }`), a field, a helper parameter, `emit<T>(…)`.
|
|
303
|
-
- `a.home = b.home` copies the whole struct, as Rust and Anchor do; how `const` binds one is in
|
|
304
|
-
|
|
305
|
+
- `a.home = b.home` copies the whole struct, as Rust and Anchor do; how `const` binds one is in [copies and
|
|
306
|
+
references](language-statements.md#copies-and-references). A copy between places reached through pointers (account
|
|
307
|
+
data, a view, a helper's struct parameter) of 80 bytes or more is the memmove syscall (16 compute units up to 2,749
|
|
308
|
+
bytes, one more per 250 bytes past that), as Rust's memcpy is; below, 8-byte loads and stores (26 units for 80
|
|
309
|
+
bytes, 54 for 192). A copy into or out of a local of the function (a local copy, a helper's result, a struct literal
|
|
310
|
+
built in a temporary) takes the syscall from 400 bytes, where clang stops unrolling the loads and stores (and about
|
|
311
|
+
1 unit a byte is the loop's cost): below that the optimizer drops what nothing reads, which a call would prevent.
|
|
312
|
+
The same holds wherever TypeSOL copies a whole value itself (Borsh fields, instruction arguments, a helper's copy of
|
|
313
|
+
a struct argument, events), and a value it zeroes whole (`x.o = null` on an `Option<struct>`, a data-enum literal)
|
|
314
|
+
takes the memset syscall from 192 bytes in account data and 600 in a local.
|
|
305
315
|
- A struct cannot contain itself.
|
|
306
316
|
|
|
307
317
|
### File-local structs
|
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,19 @@
|
|
|
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'. Multiplication and shifts are assembly written for the 128-bit
|
|
13
|
+
libcall convention of clang 20 (platform-tools v1.52) and earlier: the result's address in r1, the operands after it.
|
|
14
|
+
clang 22 (platform-tools v1.57) passes the operands from r1 and returns the result in registers, so for a clang above
|
|
15
|
+
20 the file compiles C definitions of the same four functions instead (`TS_ASM_LIBCALLS`), which take whatever
|
|
16
|
+
convention that clang gives their C signatures; with the assembly, a program built by clang 22 stored its first
|
|
17
|
+
128-bit product through the operand's low half ("Access violation writing 8 bytes at address …"). The test runs the C
|
|
18
|
+
definitions too, compiled by the tested clang as a clang above 20 would select them.
|
|
19
|
+
|
|
7
20
|
## Conventions
|
|
8
21
|
|
|
9
22
|
- **Header-only, `static inline`.** Each program compiles the header with its own code, and `--gc-sections` drops
|
|
@@ -29,6 +42,17 @@ This page is for people changing it; programs never call it directly.
|
|
|
29
42
|
- **No byte loops from the SDK.** The SDK's `sol_memcpy`, `sol_memcmp` and `SolPubkey_same` move one byte per
|
|
30
43
|
iteration. The runtime uses `ts_ld64` / `ts_st64` (unaligned 8-byte loads and stores, which SBF allows) in
|
|
31
44
|
`ts_memcpy`, `ts_memzero`, `ts_mem_eq`, `ts_key_eq` and `ts_memmove`.
|
|
45
|
+
- **The memory syscalls where they cost less.** `sol_memmove_` and `sol_memset_` cost about 16 and 14 compute units
|
|
46
|
+
whatever the length up to 2,749 bytes. Whole values of a size known when compiling are copied by `TS_COPY` from 80
|
|
47
|
+
bytes and zeroed by `TS_ZERO` from 192 between places reached through pointers (account data, views, a helper's
|
|
48
|
+
pointer parameters), where the unrolled loads and stores cost at least 10 units more. Where a side is a local of the
|
|
49
|
+
function, `TS_COPY_LOCAL` / `TS_MEMCPY` take the syscall from 400 bytes and `TS_ZERO_LOCAL` from 600, where clang
|
|
50
|
+
stops unrolling: below that the optimizer drops the stores and loads nothing reads (a struct literal built in place, a
|
|
51
|
+
helper's result read field by field), which a call would prevent. The size folds when compiling, so smaller copies
|
|
52
|
+
compile to exactly the code they were. Run-time lengths, always loops, take the syscall from 64 bytes: the bytes an
|
|
53
|
+
account grows by (`ts_memzero_run`, one unit more below 64) and an account's data at `close` (`TS_CLOSE`, decided from
|
|
54
|
+
the type's smallest size). The measured table is above these macros in `typesol_rt.h`. Copies always use memmove:
|
|
55
|
+
`sol_memcpy_` fails the transaction on overlapping ranges, which two views of one account can give.
|
|
32
56
|
- **Same results as the reference.** Fast paths must give bit-identical results to what they replace: `ts_add_overflow_u64`
|
|
33
57
|
matches `__builtin_add_overflow`, the rent fast path and `ts_rent_slow` match the double computation, PDA search
|
|
34
58
|
matches `sol_try_find_program_address`. A change here needs a test against the reference, not only against itself.
|
|
@@ -40,7 +64,7 @@ In file order:
|
|
|
40
64
|
| Section | What it provides |
|
|
41
65
|
| --- | --- |
|
|
42
66
|
| Error codes, `TS_FAIL`, `TS_TRY` | The codes above and the two macros |
|
|
43
|
-
| Word-wise memory helpers | `ts_ld64`, `ts_st64`, `ts_memcpy`, `ts_memmove`, `ts_memzero`, `ts_mem_eq`; checked u64 add/subtract/multiply |
|
|
67
|
+
| Word-wise memory helpers | `ts_ld64`, `ts_st64`, `ts_memcpy`, `ts_memmove`, `ts_memzero`, `ts_mem_eq`; the memory syscalls past their thresholds (`TS_COPY`, `TS_MEMCPY`, `TS_ZERO`, `ts_memzero_run`); checked u64 add/subtract/multiply |
|
|
44
68
|
| Well-known program ids | System, Token, Token-2022, ATA, Metaplex and the other programs the language names |
|
|
45
69
|
| Strings | `TS_Str` views (pointer, length), UTF-8 validation, comparison, `FixedString<N>` storage |
|
|
46
70
|
| Entry point input | `TsAccount` (the loader's serialized account, read in place), `TsParams`, `ts_deserialize` |
|
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,10 @@ 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.50.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), `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), and `copyData`, `getReturnData()`, `PANIC_STYLE = "pinocchio"` and whole values
|
|
189
|
+
copied and zeroed by the memory syscalls (0.50.0). There has been no external audit: see [audit.md](audit.md).
|
package/docs/stability.md
CHANGED
|
@@ -61,14 +61,18 @@ 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 three of them that
|
|
72
|
+
divide 128-bit and wider integers, the Meteora DBC port (0.48.0; u128 and u256 division), the Percolator port
|
|
73
|
+
(0.49.0; U256 and U512) and the Percolator v16 port (0.50.0; u256), are not in `test/golden/binaries.json`, so CI's
|
|
74
|
+
cross-host check does not build them yet (adding them needs the file regenerated in the `--docker` reference
|
|
75
|
+
environment).
|
|
72
76
|
|
|
73
77
|
| What | Same on the three hosts? |
|
|
74
78
|
| --- | --- |
|
|
@@ -126,6 +130,8 @@ Useful today, but may still change before 1.0 (each change listed in the CHANGEL
|
|
|
126
130
|
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
131
|
- `panic(null, location)` (no log line) and `abort()` (Rust's abort, "SBF program panicked") (0.42.0).
|
|
128
132
|
- Failures without a log line (0.43.0): `ERROR_LOG_PREFIX = null` / `PROGRAM_ERROR_LOG_PREFIX = null`.
|
|
133
|
+
- `EVENT_AUTHORITY_CHECK = "address"` (0.48.0): `emitCpi`'s event authority checked by address, as Anchor 1.x's
|
|
134
|
+
`#[event_cpi]` does, and the self-program account not checked (docs/security-model.md, guarantee 13).
|
|
129
135
|
- `findProgramAddressWithBump` (0.43.0), with `const [address, bump] = …` its only array destructuring.
|
|
130
136
|
- Plain type aliases (0.43.0): `type Price = u64`, replaced by the type they name.
|
|
131
137
|
- 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,9 +57,14 @@ 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
|
|
53
|
-
-
|
|
54
|
-
-
|
|
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`);
|
|
62
|
+
- the sha256 of the reference binaries the differential tests run against (`test/programs/`); the script refuses to
|
|
63
|
+
make a release manifest when `test/programs/SOURCES.md` lists a binary the tree lacks (with
|
|
64
|
+
`--allow-missing-references` it lists them under `referencesMissing` instead);
|
|
65
|
+
- a hash of the test corpus: every file under `test/` and `showcase/test/` (the directories the tests run from, the
|
|
66
|
+
mainnet ports' differential tests, helpers and fixtures included) but the reference binaries, with the directories
|
|
67
|
+
it covers (`corpus.roots`). Manifests before this change hashed `test/` alone.
|
|
55
68
|
|
|
56
69
|
It also carries `typesol-<version>-binary-diff.txt` (older releases: `binary-diff.txt`): the previous release's sources built by the previous package and by this one,
|
|
57
70
|
compared program by program. That is the check behind a changelog line such as "programs that use none of these compile to the
|
|
@@ -72,7 +85,7 @@ the same binary and IDL with both packages.
|
|
|
72
85
|
### Across hosts
|
|
73
86
|
|
|
74
87
|
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,
|
|
88
|
+
([stability.md](stability.md#what-builds-the-same-bytes-where) has the measurement with 0.45.0 over 76 programs on macOS arm64,
|
|
76
89
|
Linux arm64 and Linux x86_64, and why 0.44.1 and earlier differed for programs with 128-bit or signed division). The
|
|
77
90
|
reference environment is the `--docker` build container (linux/amd64). `test/golden/binaries.json` holds what 14
|
|
78
91
|
programs build to there with the checkout's compiler: counter, vault, escrow, multisig, and the 10 that call 128-bit or
|
|
@@ -110,7 +123,10 @@ From 0.43.0 on, `releases/<version>.json` in the repository describes the packag
|
|
|
110
123
|
tarball's size, sha1 shasum and sha512 integrity (the registry's `dist.shasum` and `dist.integrity`), and the sha256
|
|
111
124
|
of every file in it. `scripts/release-check.ts` writes it from a clean export of the tag (`git archive`: install with
|
|
112
125
|
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)).
|
|
126
|
+
tarball it produced, by hand ([CONTRIBUTING.md](https://github.com/typesol-lang/typesol/blob/main/CONTRIBUTING.md#releasing)). Its `"tests"`
|
|
127
|
+
field says whether `release-check.ts` also ran the test suite on that export (`--tests`); it is `false` in the records
|
|
128
|
+
so far because the documented release steps run `pnpm test` before tagging and the check does not repeat it.
|
|
129
|
+
To check a release yourself:
|
|
114
130
|
|
|
115
131
|
```sh
|
|
116
132
|
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
|
|
package/lib/typesol.d.ts
CHANGED
|
@@ -240,6 +240,8 @@ export interface RemainingAccount {
|
|
|
240
240
|
readonly dataLen: u64;
|
|
241
241
|
readonly isSigner: boolean;
|
|
242
242
|
readonly isWritable: boolean;
|
|
243
|
+
/** Whether the account is an executable program (AccountInfo::executable). */
|
|
244
|
+
readonly executable: boolean;
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
/**
|
|
@@ -1004,12 +1006,13 @@ export declare const AuthorityType: {
|
|
|
1004
1006
|
* Resize an account of this program (Anchor `realloc`, struct accounts only): growing charges `payer` the extra rent
|
|
1005
1007
|
* (never the account's own lamports, which may be deposits); shrinking keeps every lamport in the account — move
|
|
1006
1008
|
* freed rent out yourself if your program allows it. At most 10 KiB of growth per instruction (3016); never below
|
|
1007
|
-
* the struct size
|
|
1009
|
+
* the struct size (3016; for a `@layout borsh` struct its smallest Borsh form, and the value written back must fit,
|
|
1010
|
+
* 3004). Accounts ending in a Vec size themselves through push/pop/clear.
|
|
1008
1011
|
*/
|
|
1009
1012
|
export declare function realloc(account: AccountMeta, newSize: u64, payer: Mut<Signer>): void;
|
|
1010
1013
|
/**
|
|
1011
1014
|
* Resize a `Mut<AccountInfo>` or a remaining account of this program to `newSize` bytes (Rust's `AccountInfo::resize` /
|
|
1012
|
-
* `realloc(newSize, true)`): the data length only, the new bytes zeroed. No rent moves: fund the account first
|
|
1015
|
+
* `realloc(newSize, true)`): the data length only, the new bytes zeroed (64 or more by the memset syscall). No rent moves: fund the account first
|
|
1013
1016
|
* (`rentExempt(newSize)`), the runtime refuses an account left short. At most 10 KiB past its size when the
|
|
1014
1017
|
* instruction started (3016). A remaining account must be writable (3006) unless the program declares
|
|
1015
1018
|
* `NATIVE_ACCOUNT_WRITES`, which also lets an `AccountInfo` parameter be resized without `Mut<…>`. A view of the
|
|
@@ -2488,7 +2491,10 @@ export declare enum ProgramError {
|
|
|
2488
2491
|
* own: `panic(null, "src/lib.rs:105:19")` leaves only the runtime's "SBF program Panicked in src/lib.rs at 105:19".
|
|
2489
2492
|
* Under `export const PANIC_STYLE = "solana-1.14"` (a program built with solana-program 1.14 to 1.17) it logs
|
|
2490
2493
|
* `panicked at '<message>', <location>` and aborts, so the runtime reports "SBF program panicked", as that panic
|
|
2491
|
-
* handler does;
|
|
2494
|
+
* handler does; under `"solana-1.18"` (rustc 1.73 and later) it logs `panicked at <location>:` with the message on the
|
|
2495
|
+
* next line, in one log line, and aborts. A message is then required. Under `"pinocchio"` (pinocchio's
|
|
2496
|
+
* `entrypoint!` panic hook) it logs the location's file alone, then `** PANICKED **`, and aborts: the message is not
|
|
2497
|
+
* logged (it may be null), and `location` may be the file alone (`"src/v16.rs"`).
|
|
2492
2498
|
*/
|
|
2493
2499
|
export declare function panic(message?: string | null, location?: string): never;
|
|
2494
2500
|
/**
|
|
@@ -2567,6 +2573,16 @@ export declare function emit<T>(event: T): void;
|
|
|
2567
2573
|
*/
|
|
2568
2574
|
export declare function returnData<T extends bigint | boolean | Pubkey | Hash | object>(program: AccountMeta): T;
|
|
2569
2575
|
|
|
2576
|
+
/**
|
|
2577
|
+
* The return data as the runtime holds it, of any length and from any program (Rust's `get_return_data()`), for a
|
|
2578
|
+
* port that checks it itself: `const [program, data] = getReturnData()`. `program` is the program that set it and
|
|
2579
|
+
* `data` its bytes (up to 1,024, the runtime's maximum), read with the methods of instruction data
|
|
2580
|
+
* (`data.length`, `data.readU64(8n)`, `data.slice(a, b)`). Rust's `None` is `data.length === 0n` (the runtime keeps
|
|
2581
|
+
* no empty return data), `program` then all zeros. Nothing is checked: compare `program` and the length yourself,
|
|
2582
|
+
* failing with your own errors. The bytes take 1 KiB of the calling function's stack frame.
|
|
2583
|
+
*/
|
|
2584
|
+
export declare function getReturnData(): [program: Pubkey, data: InstructionBytes];
|
|
2585
|
+
|
|
2570
2586
|
/**
|
|
2571
2587
|
* Set this instruction's return data to `bytes` as they are (Rust's `set_return_data(&bytes)`): a list of u8 such as a
|
|
2572
2588
|
* local `FixedVec<u8, N>`, a Vec or FixedVec in account data, or the instruction data or a slice of it. For a native
|
|
@@ -2584,6 +2600,30 @@ export declare function setReturnData(bytes: IndexedList<u8>): void;
|
|
|
2584
2600
|
*/
|
|
2585
2601
|
export declare function logComputeUnits(): void;
|
|
2586
2602
|
|
|
2603
|
+
/**
|
|
2604
|
+
* Log five u64 values as Rust's `sol_log_64(a, b, c, d, e)` does: the runtime writes
|
|
2605
|
+
* "Program log: 0x<a>, 0x<b>, 0x<c>, 0x<d>, 0x<e>" (lowercase hex, no padding). For native ports whose original logs
|
|
2606
|
+
* numbers this way.
|
|
2607
|
+
*/
|
|
2608
|
+
export declare function log64(a: u64, b: u64, c: u64, d: u64, e: u64): void;
|
|
2609
|
+
|
|
2610
|
+
/**
|
|
2611
|
+
* Zero `length` bytes of an account's data from `offset`, as a native program's
|
|
2612
|
+
* `for b in data[offset..offset + length].iter_mut() { *b = 0; }` (a memset): the memset syscall, about constant compute
|
|
2613
|
+
* units whatever the length. A remaining account (or a `Mut<AccountInfo>` parameter); past the end of the data fails
|
|
2614
|
+
* with 3003 and writes nothing. Only this program's accounts can change: check the owner first.
|
|
2615
|
+
*/
|
|
2616
|
+
export declare function zeroData(account: RemainingAccount | Mut<AccountInfo>, offset: u64, length: u64): void;
|
|
2617
|
+
|
|
2618
|
+
/**
|
|
2619
|
+
* Copy `length` bytes of an account's data from offset `from` to offset `to`, as a native program's
|
|
2620
|
+
* `data.copy_within(from..from + length, to)` (or a struct copied out of the account and written back at another
|
|
2621
|
+
* offset): the memmove syscall, about constant compute units whatever the length; the ranges may overlap. A remaining
|
|
2622
|
+
* account (or a `Mut<AccountInfo>` parameter); a range past the end of the data fails with 3003 and copies nothing.
|
|
2623
|
+
* Only this program's accounts can change: check the owner first.
|
|
2624
|
+
*/
|
|
2625
|
+
export declare function copyData(account: RemainingAccount | Mut<AccountInfo>, from: u64, to: u64, length: u64): void;
|
|
2626
|
+
|
|
2587
2627
|
/**
|
|
2588
2628
|
* Verify `account.key` is the PDA for `seeds` + `bump` under this program. Any bump that gives a PDA passes (Anchor's
|
|
2589
2629
|
* `bump = expr`): use a stored bump, not one from the arguments, or the caller picks among up to 256 addresses.
|