ckb-cycle-tools 0.0.0-stage → 1.1.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 ADDED
@@ -0,0 +1,180 @@
1
+ # Changelog
2
+
3
+ This project follows [semantic versioning](https://semver.org/).
4
+
5
+ ## 1.1.0 (2026-10-30)
6
+
7
+ Cycle reports from ckb-testtool tests, and a check across ckb-debugger releases.
8
+
9
+ ### Security
10
+ - Every mock transaction is checked before it is written for ckb-debugger
11
+ (native and WebAssembly; plain replay, `--file`, `report`, `flame`, `scan`
12
+ scenarios, mocks built from a node): a string containing `{{` anywhere in it,
13
+ or a field that should be hex and is not, is refused with an error that names
14
+ the field. ckb-debugger expands `{{ data <path> }}`, `{{ hash <path> }}`,
15
+ `{{ def_type … }}` and `{{ ref_type … }}` in a tx file, so a pull request's
16
+ mock could embed any file on the runner, past `--root`.
17
+ `checkMockTransaction` is exported from `.` and `./replay`.
18
+ - `report --root` ignores the config's `"rpc"` and says so in a warning: a pull
19
+ request's cycles.json no longer chooses the host the runner sends requests to.
20
+ `--rpc` still applies; otherwise the public node is asked.
21
+ - Names from a cycles.json, a build or a node (scenario, script, binary and
22
+ function names, warnings) are printed to the terminal and the CI log on one
23
+ line, without control or bidi characters, and never with `::` at the start
24
+ of a line (errors keep their lines, each cleaned the same way), so a name
25
+ cannot forge a GitHub Actions workflow command or drive the terminal:
26
+ `report`, `diff`, `flame`, `scan` and plain replay.
27
+ - GitHub Action: the PR's `build` runs in the same job as the sticky-comment
28
+ step, which gets `github-token`, and could take that token by writing its own
29
+ `gh` to `$GITHUB_PATH`, or BASH_ENV, PATH and the like to `$GITHUB_ENV`. `gh`
30
+ is now located before the build runs; the comment step runs `/bin/bash -p`
31
+ (not the `bash` on PATH; no BASH_ENV, ENV or exported functions), sets PATH
32
+ itself, blanks LD_PRELOAD and the like, and runs `gh` with only the variables
33
+ it needs (the proxies and CA settings as they were before the build) and an
34
+ empty config directory. The comment file is read from the runner's temp
35
+ directory, never from a step output, and must be a regular file. This does
36
+ not stop a build that leaves a process running or replaces files on the
37
+ runner; the Action's README says so and shows a two-job setup for PRs you do
38
+ not trust with the token.
39
+ - GitHub Action: `action/comment`, the sticky-comment step on its own, for that
40
+ second job: it posts a markdown file downloaded from the first job, with a
41
+ token the PR's build never shares a runner with. The first job runs the
42
+ Action with `comment: false` and a read-only token.
43
+ - GitHub Action: the comment's markdown is written only when the diff ran, so a
44
+ second job never posts a failed diff's output; the base commit is fetched only
45
+ when the checkout does not have it (a private repository checked out with
46
+ `persist-credentials: false` and `fetch-depth: 0` then needs no credentials).
47
+ - The README examples and this repository's cycle-report workflow check out
48
+ with `persist-credentials: false`, so no token is left in `.git/config` for
49
+ the PR's build, and the Action's README no longer says the build cannot get a
50
+ write token. GitHub-owned actions in this repository's workflows and the
51
+ README examples are pinned to commit SHAs, with the release as a comment.
52
+ - Web inspector: every page is served with `Content-Security-Policy:
53
+ frame-ancestors 'none'`, `X-Frame-Options: DENY`, `X-Content-Type-Options:
54
+ nosniff` and `Referrer-Policy: strict-origin-when-cross-origin`, and without
55
+ `X-Powered-By`, so no other site can frame it.
56
+
57
+ ### Fixed (audit, 31 Oct)
58
+ Each of these could give a gated check the wrong verdict.
59
+ - A binary missing from `--binaries-from` (a contract the PR adds) made every
60
+ scenario offered it a base error with no groups, so nothing in those
61
+ scenarios was compared, the other binaries' groups included. The scenario now
62
+ runs with the binaries that exist, the missing one left as the mock has it;
63
+ only the groups whose code it is are not compared (`missingBinary` on the
64
+ group, `missingBinaries` on the scenario), and a gated diff fails on them
65
+ unless `--allow-removed`.
66
+ - A binary offered to a scenario that matches none of its cell deps (a mock
67
+ dumped from an older build) was measured as the mock's old code on both
68
+ sides and shown unchanged, with nothing said. It is now a warning on that
69
+ scenario, listed in the comment. A binary that matches no cell dep in any
70
+ scenario was a report error that only reached the log: `report` now writes
71
+ its errors into the JSON (`"errors"`), and a gated diff fails when either
72
+ report has any, so the Action's `|| true` no longer hides them.
73
+ - A group the VM stopped (past the cycle limit) was recorded with 0 cycles and
74
+ read as a -100% saving, passing `--fail-above`. The cycles of a stopped run
75
+ are never used now; with `--fail-above` such a group is over the threshold,
76
+ and a result change for `--fail-on-result-change`. A result names the VM
77
+ error's kind (`error: invalid instruction`, `error: cycles error: max cycles
78
+ exceeded`), so one VM error turning into another is a result change.
79
+ - GitHub Action: the base report ran the PR's cycles.json, so a scenario the PR
80
+ deleted was never measured or listed. The base is now measured with the base
81
+ commit's own cycles.json, mocks and binaries (an empty report when the base
82
+ has none); the head still runs the PR's.
83
+ - A base group with nothing in the head to compare against (a scenario or group
84
+ removed, renamed, or moved to another selector) passed both gates. A gated
85
+ diff now fails on it unless `--allow-removed` (Action input `allow-removed`,
86
+ default false). The summary counts such groups and new groups.
87
+ - Two reports from different ckb-debugger versions were compared without a
88
+ word: the summary now names both versions.
89
+
90
+ ### CLI: `ckb-cycles`
91
+ - `scan <mocks-dir>`: writes a cycles.json from the mock transactions a test
92
+ suite wrote, one scenario per file, with each freshly built binary in
93
+ `--binaries` (default `build/release`) mapped by its data hash and
94
+ `<name>.debug` as its symbols build; `--functions` records each group's
95
+ costliest functions.
96
+ - Functions the profiler could not name from line info (`func_0x<address>`:
97
+ ckb-std's `_start`, rustc's allocator shims) are named from the symbols
98
+ build's ELF symbol table, so they no longer show in a diff as one address
99
+ removed and another added when code moves.
100
+ - ELF names skip absolute symbols, labels outside executable sections and
101
+ linker section markers (`__text_start`, `_etext`), so a marker at `_start`'s
102
+ address no longer renames the root frame.
103
+ - Legacy Rust symbol names are demangled in full (`$RF$`, `$LP$`, `$u7b$` and
104
+ the other escapes), so they read as `rustc-demangle` prints them.
105
+
106
+ ### ckb-testtool integration
107
+ - `integrations/ckb-testtool`: a Rust crate whose `verify_tx` writes each
108
+ ckb-testtool transaction as a mock when `CKB_CYCLES_MOCKS` is set, for
109
+ ckb-script-templates projects; with `scan`, `make cycles` reports every
110
+ test's script groups. Checked in CI on a project generated from
111
+ ckb-script-templates, two contracts, a change, a diff.
112
+ - README: the Makefile target uses `npx -p ckb-cycle-tools ckb-cycles` (a bare
113
+ `npx ckb-cycles` names a package that does not exist) and `cargo test -p tests`.
114
+ Every other `npx` line in the READMEs and the demo page now names the package
115
+ the same way.
116
+
117
+ ### Library
118
+ - `scanTestMocks`, `configFromMocks` and `formatScan` (and their types) from `.`.
119
+ - `flameTransaction` reads and parses each symbols build once, not once per
120
+ script group that runs it.
121
+ - `flameTransaction` takes `readBinary` beside `readFile`, so a caller whose
122
+ debugger sees another file system gets frame names from the builds there
123
+ too; it defaults to node:fs, as before.
124
+
125
+ ### GitHub Action
126
+ - When the sticky comment exists but updating it fails, the step retries the
127
+ update (three tries) and then warns; it no longer posts a second report
128
+ comment beside the first.
129
+ - When the pull request's comments cannot be listed, the step warns and posts
130
+ nothing (the report is in the job summary), since it cannot tell whether its
131
+ comment already exists.
132
+
133
+ ### Compatibility across ckb-debugger releases
134
+ - `npm run compat` (repository only): replays 35 frozen scenarios under every
135
+ ckb-debugger release from 0.121.0 to 1.1.1, native and WebAssembly, compares
136
+ each script group with 1.1.1, and writes compat/RESULTS.md; a weekly Linux CI
137
+ job runs it. A scenario the reference debugger could not run counts as a
138
+ mismatch, and two scenario ids that slug alike no longer replay the same
139
+ transaction.
140
+
141
+ ## 1.0.0 (2026-10-27)
142
+
143
+ First stable release.
144
+
145
+ ### CLI: `ckb-cycles`
146
+ - Replays a transaction per script group in ckb-debugger; the sum matches the node's
147
+ total. Resolves the real ckb-debugger past the Windows `.cmd` shim.
148
+ - Failure-path profiling: `--file` profiles a transaction that is not on chain.
149
+ - Right VM version per script, from the node's hardfork epochs; input headers are
150
+ replayed, so header-reading scripts (Nervos DAO) match.
151
+ - Only complete ckb-debugger result lines are trusted, cross-checked with its exit code.
152
+ - `report`, `diff` and `mock` subcommands; swap a cell dep's binary for a fresh build
153
+ before replaying; name your own scripts with `--name`.
154
+ - `flame`: per-group flamegraphs from ckb-debugger's profiler (SVG + folded
155
+ stacks, costliest functions printed); `--bin` swaps in an unstripped build and
156
+ checks its cycles against the deployed binary's.
157
+ - Exit codes: 0 every script accepts and the sum matches the node; 1 a script
158
+ rejects or the sum differs; 2 a usage or environment error.
159
+
160
+ ### Library
161
+ - `.` (analysis), `./analyze`, `./replay` and `./flame` (pure, work in the browser), `./wasm`
162
+ (ckb-debugger's WebAssembly build, in memory, same numbers as native).
163
+
164
+ ### GitHub Action
165
+ - `action/`: posts one sticky cycle report on a pull request, group by group against
166
+ the base branch; checksums the ckb-debugger it installs; fails on a broken base.
167
+ - Function-level costs in the report: a binary's `symbols` build and `"functions": true`
168
+ in cycles.json record each group's costliest functions (checked against the binary's
169
+ cycles), and the comment folds in which functions changed.
170
+ - Hardened for untrusted pull requests: `report --root` keeps the files a PR's
171
+ cycles.json names inside the checkout; names in the comment cannot mention,
172
+ link or break the table; the comment always fits GitHub's size limit.
173
+
174
+ ### Web inspector
175
+ - ckb-cycle-tools.vercel.app: paste a transaction hash, see its scripts and the
176
+ per-group cycles computed in the page.
177
+
178
+ ### Benchmark
179
+ - The session lock in Rust vs ckb-js-vm, rebuilt and rerun in CI: the current lock
180
+ (ckb-session-kit 49227cd, plain CKB and token sessions, codes 10-20), 58 scenarios.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Luong Thanh Tung
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.