CellScript 0.31: Smaller Contracts, Less Repeated Work
CellScript 0.31.0 was released on October 1. The native compiler, standalone artifact checker, VS Code extension, website, Playground, and Registry services have been updated together.
I also owe this thread a short recap of 0.30. It was released on September 23, but I never posted the usual release update here. I wrote CellScript 0.30: Abstractions, Bytes, and the Cost instead, followed by a closer look at constant encoding. That discussion explains where much of the 0.31 work came from: the abstractions were doing useful work, but some of the generated code was unnecessarily expensive.
A short catch-up on 0.30
0.30 brought together the work after 0.25, including the changes previously developed under 0.26 and 0.26b. There was no separate stable 0.26 release in between.
The main additions were about describing more of a transaction in the language and giving those descriptions concrete checks:
- Bounded batches of inputs and outputs. A contract can consume a bounded set of inputs belonging to its Type Script group, or check a bounded output plan against the proposed outputs. Count, order, identities, and the handling of each resource are part of the checks. These are the bounded forms completed in #7 and #8.
- Several Scripts participating in one transaction. ProtocolBundle combines independently compiled artifacts and checks their input/output roles, witness requirements, and deployment identities for compatibility. The Scripts keep their own executables. The closed-role work shipped through #9 and #10.
- Typed transaction data and authenticated values. This includes bounded views of Cells, Scripts, witnesses, and header dependencies, typed time constraints, and fixed-width commitment openings that must be authenticated before the program can use the value inside. Relevant issues include #12, #13, and #24.
- More predictable package builds. The package work covered dependency ordering, one resolved instance per package coordinate, compiler requirements, chain identity, deterministic build plans, and explicit upgrade planning.
Cell.lockv5 records these choices; ordinary builds use the lock rather than silently choosing new versions. This was the work across #15–#20.
0.30 also added executable business cases and cost budgets, so there was a practical way to see what these features cost. The 0.30 release notes have the full scope. Edition 2026 remained the default; the newer Edition 2027 authoring forms were opt-in.
The decision on public generics
My last reply in this thread left the public generic interface open for discussion. That decision was settled in 0.30 through #23: public value generics remain available across packages.
For the common fixed-layout case, the declaration can use fixed_value:
public struct Pair<T: fixed_value> {
left: T,
right: T,
}
That is shorthand for copy + drop + store + fixed + serializable + non_linear. It saves repeating the same constraints on ordinary values whose size and serialization must be known. The expanded spelling is still accepted, and both forms describe the same public interface.
These templates are specialized for concrete types before the compiler generates code. This covers ordinary value structs, fixed-width payload enums, and pure functions. It does not make Cells, resources, action entries, or Lock entries generic. The stricter public layout requirements belong to Edition 2027; Edition 2026 keeps its earlier declaration compatibility. The generic contract spells out those boundaries.
What changed in 0.31
There is no new language syntax in this release. Most of the work is below the source code: how constants are loaded, how action arguments are decoded, how much stack space is reserved, and how execution costs are measured.
The five main issues were #31, #32, #33, #34, and #35. All five are resolved for this release.
Large constants take fewer instructions — #31
The constant-encoding follow-up used 2^56 as an example. The old general fallback assembled a large value one byte at a time, which could take 15 instructions. For that particular value, loading 1 and shifting it left by 56 places produces the same result in two instructions.
0.31 applies that idea more generally. The assembler plans a sequence using pieces that fit the available instructions and combines shifts where possible. It checks the reconstructed value and keeps the old expansion as a fallback when the new plan would not help.
The saving depends on the constants in a contract. An arbitrary 64-bit value will not necessarily collapse to two instructions, but simple bit patterns no longer pay for every byte of the old construction. This uses the existing instruction set.
Actions can share argument decoding — #32
A persistent Type policy may have several actions using the same argument layout. Previously, each action could carry another copy of substantially the same decoding code. As the number of actions grew, those copies became a noticeable part of the executable.
0.31 shares a decoder when the complete callable layouts agree. Matching the total byte length alone is not enough: the types, sources, and bindings also have to match. Each action still has its own explicit route into its implementation.
This is particularly useful for policies with many similar actions. Dispatch still uses the existing linear tag checks, and the order of common checks is preserved. The release does not introduce a jump table or a different action-selection format.
Small arguments no longer need oversized private buffers — #33
Some entry adapters reserved enough stack space for a much larger payload than the action could actually accept. For fixed layouts, the compiler now calculates the required private space from the known argument shape.
In the 32-byte policy-argument fixture, the private adapter frame falls from 5,376 bytes to 64 bytes. The outer witness-loading frame still exists, so that is not a claim that the whole call chain uses only 64 bytes. Across the corresponding policy fixtures, the static call-chain stack bound falls from 11,472 to 6,160 bytes.
The 4,096-byte outer witness-loading limit is unchanged. Arguments still get their private copy, and layouts the compiler cannot prove small enough retain the conservative fallback. This change does not add zero-copy witness borrowing.
Temporary scalar values can reuse stack slots — #34
A temporary result only needs storage while something can still read it. Previously, many scalar temporaries kept separate stack slots even after their last use.
The compiler now follows their lifetimes through branches, loops, and calls, then reuses compatible eight-byte slots when the values cannot be live at the same time. This reduces the space needed by eligible scalar code and can also shorten the instructions used to address that space.
The analysis is deliberately conservative. Resources, pointers, wide values, external calls, and operations outside the supported analysis can cause the function to keep its original allocation. Named mutable locals and buffers have separate storage rules. This is stack-slot reuse; it is not a general register allocator, and a smaller frame alone does not prove fewer executed loads and stores.
Rejected transactions get meaningful cost measurements — #35
The old reporting path could record zero cycles for failed execution. That made a rejected input look free, even when the Script had done considerable work before rejecting it.
Normal nonzero Script-group exits now retain their measured cycles, including child execution. When a measurement is unavailable—for example because execution trapped or exhausted its cycle limit—the report says so. It does not turn that absence into a zero that passes a budget check.
The expanded corpus includes malformed inputs, every action in the fixed policy matrix, scalar and nested-call cases, and transactions involving several Script groups. It also keeps transaction totals separate from individual Script-group costs, and single-frame sizes separate from static call-chain bounds. Actual observed stack peaks remain outside this release.
The measured difference
These are selected comparisons against the reproduced 0.30 backend, using the same fixtures. The cycle column is the maximum successful transaction cost measured for that fixture.
| Fixture | ELF bytes, 0.30 → 0.31 | Maximum successful transaction cycles, 0.30 → 0.31 |
|---|---|---|
| 8 actions, 32-byte argument | 11,680 → 8,048 | 14,158 → 13,189 |
| 64 actions, 32-byte argument | 73,440 → 43,592 | 29,822 → 22,299 |
| 260 overlapping scalar values | 16,384 → 10,024 | 12,441 → 9,259 |
The 64-action fixture ends up about 41% smaller and uses about 25% fewer cycles on its worst measured successful case. That is a useful reduction in the overhead of putting many actions under one policy.
There is an important difference from the numbers in the earlier constant-encoding reply. That reply isolated the immediate planner: the 64-action executable went from 73,440 to 61,008 bytes. The table above includes the completed 0.31 changes together, bringing it down further to 43,592 bytes. They are different comparisons, not revised measurements of the same configuration.
These results describe specific workloads. They are not a promise that every contract shrinks by the same percentage, and this table is not a comparison against Rust. The implementation report and reproduction package contain the broader measurements and comparison setup.
Other fixes
Three additional fixes are included:
- Loop fusion preserves required setup. If the original loop prefix defines an offset or pointer needed by the proposed replacement, the optimizer keeps the original loop when it cannot safely preserve that dependency.
- Immediate-planner errors become assembler diagnostics. An encoding error is reported through the normal diagnostic path instead of reaching an internal panic.
- The Registry checks its configured proxy chain. Caller-supplied IP and ASN headers are no longer accepted as authoritative client identities. Self-hosted operators need to configure the trusted proxy hop count for their actual deployment.
Updating an existing project
The source editions and witness formats are unchanged from 0.30. Recompiling can still change the executable bytes, which matters for deployment identities.
Use the 0.31 compiler and matching standalone checker, and rebuild the complete artifact bundle together:
contract.elf
contract.elf.meta.json
contract.elf.lowering.json
contract.elf.sourcemap.json
The lowering record is now v9. Do not pair a newly generated ELF with old sidecars or relabel a previously checked bundle as a 0.31 build. Builders and deployment records should follow the regenerated artifacts.
Installing a new compiler does not upgrade code already deployed on CKB. If you deploy a rebuilt artifact, account for its new code identity and update the corresponding transaction configuration. Existing deployments retain their original identities.
The GitHub release has native archives for macOS and Linux, on both x86-64 and ARM64. Each native archive includes cellc and cellscript-artifact-checker. The WASM bundle, VS Code VSIX, installer, and checksums are there as well.
To install this specific release:
curl -fsSL https://github.com/CellScript-Labs/CellScript/releases/download/v0.31.0/install.sh | CELLSCRIPT_VERSION=0.31.0 sh
cellc --version
The website, Playground, and testnet Registry have also been updated. The browser compiler remains a metadata-only tool; native ELF generation and CKB execution use the native tooling.
Testing and remaining limits
The implementation candidate passed the local dev, ci, and backend gates. Local CKB acceptance covered 43 actions, 17 Lock matrices, and 26 stateful scenarios. The version-aligned cost comparison checked 6,782 comparable metrics against the existing budgets. GitHub CI on the published source and the release workflow also completed successfully.
I published 0.31 with an explicit exception for the outstanding independent review and release-evidence requirements. The full release gate did not pass, and this release does not claim new public-testnet deployments. The release notes record that distinction.
I would particularly like to see small examples where generated code is still unexpectedly large or expensive: several actions sharing an argument layout, a chain of scalar calculations, or an invalid input that takes too long to reject. A .cell file and the transaction shape are enough to start a useful discussion. Those are the cases I want the next round of measurements to reflect.