Skip to content

Latest commit

 

History

History
129 lines (109 loc) · 7.7 KB

CELLSCRIPT_ZK_PROFILE.md

File metadata and controls

129 lines (109 loc) · 7.7 KB

Exact ZK transition profile for 0.32

Status: accepted implementation scope for #22, under the maintainer's October 3 review waiver and October 4 instruction to complete its acceptance work. This is a development profile, not a release or public deployment receipt.

Ownership and first application

CellScript constructs and binds a statement, authenticates an exact external verifier and VK, transports bounded bytes and enforces its result. Proving and circuit execution stay off chain. The cryptographic implementation is a separate RISC-V executable, using upstream groth16-ckb revision d64c769ffe2d2edb5eb308dc59058efda77c2f83 (MIT OR Apache-2.0) and locked Arkworks 0.5 dependencies. The compiler and independent checker do not prove circuit soundness, zero knowledge, setup erasure or cryptographic correctness.

The first application is private authorization counter: knowledge of a 32-byte owner secret, unchanged owner commitment, exactly one increment and no u64 overflow. State and owner commitment remain public. The R1CS binds every public-input limb and computes owner/state hashes itself. The lifecycle wrapper checks unique zero initialization, preserves Lock and capacity, rejects burning, and EXECs the generated parent. At u64::MAX the instance cannot advance. No lifecycle authority is granted by a ZK proof.

Source, package and deployment contract

The fixed nominal types are ZkTransitionProof (128 bytes), VerificationKeyCommitment (32 bytes) and the existing ExactScriptHandle. zk::require_valid(policy, proof, dependency, verifier, handle_hash, vk_hash, domain, action) returns Unit. One unconditional call is allowed in an action's entry block; Lock entries, conditional calls, helpers and loops are rejected. The proof must be a direct witness parameter. No ignorable boolean or escaping verification token exists. Existing parser/formatter call syntax is reused.

Packages declare [[deploy.ckb.zk_verifiers]] with policy, dependency, verification_key_hash and a nested receipt using the existing #11 ExactScriptHandleReceipt schema. dependency names exactly one entry in [[deploy.ckb.cell_deps]]; ordered entries determine the explicit source index. Before code generation, the compiler checks the name, unique mapping, source index, code data hash, deployment outpoint, receipt role/profile/ABI, complete handle commitment and VK commitment. Duplicate names, missing policies, substituted identities and DepGroups reject. This first named resolver supports only direct CellDeps, so raw and resolved indexes agree. The runtime still checks the actual dependency bytes: a manifest or Registry name is not authority.

zk_package::resolve provides the same resolution and encoded handle to native builders. compile_with_zk_deploy uses the same checks for source generated by an application. The counter export writes parent.cell, named-deployment.json, ELF, metadata and handle. The JSON is the serialized CkbDeployConfig accepted by that API; Cell.toml loading is tested separately. Standalone in-memory compilation remains the explicit literal-handle API; it makes no package resolution claim. The named CellDep RFC is superseded for this exact ZK subset, not for arbitrary named data sources.

Network identity and deployment outpoint enter the exact receipt. A different child deployment requires a new handle and parent. Upgrades are exact-artifact only; interface compatibility and Type ID do not approve replacements. A builder must resolve live input/dependency Cells externally and validate chain identity. Export is not a deployment receipt. Registry runtime_verifier / ckb_executable / tcb remains the applicable artifact role; there is no open verifier registry or new consensus discovery mechanism.

Statement and wire format

The v2 profile's SHA-256 identity is defined by PROFILE_PREIMAGE in crates/cellscript-artifact-checker/src/zk.rs; the same allocation-free codec is compiled into the verifier. The Molecule schema has a strict six-field table, fixed offsets and exactly 464 request bytes. Envelope version is 1; the embedded profile is v2. Unknown versions, flags, profiles, offsets, widths and trailing data reject.

The statement is exactly 228 bytes, in this order:

Field Width Binding source
domain, action 32 bytes each Explicit compile-time arguments
current Script hash 32 CKB syscall
old, new data hashes 32 each Exactly one GroupInput and GroupOutput
input transaction hash 32 GroupInput previous outpoint
input output index 4, little endian GroupInput previous outpoint
full raw transaction hash 32 CKB syscall

Each hash becomes two little-endian u128 limbs, zero-extended to canonical 32-byte BN254 scalars. The index becomes one u32 scalar: 15 inputs in total. No modular reduction or hash truncation is permitted. Domain and action are not inferred from names. Authority is enforced by the application relation and committed owner; no epoch/nullifier is required for this single-successor UTXO relation. The outpoint plus complete raw transaction supplies replay binding. Changing any raw field requires a fresh proof after finalization; proof/signature witnesses are installed afterwards. Source origins retain the owning call span and explicit syscall/argument mapping for every field.

Proof encoding is Arkworks compressed Groth16/BN254, 128 bytes. The separate VK CellDep is exactly 744 bytes and must match the compile-time data hash; the child rejects duplicate keys, malformed vector lengths and more than 64 resolved dependencies. Witness placement is entry WitnessArgs.input_type; shared witness ownership follows the existing entry encoder. Caller-supplied public inputs are never used by the parent. Rust adapter and generated TypeScript codecs consume shared vectors; the builder compares prover public inputs before constructing the envelope.

Runtime, evidence and trust

One child and one inherited read descriptor are allowed per call. The parent writes exactly 58 eight-byte words, closes the writer and waits for that PID; only exit 0 permits continuation. Syscall errors, short transfers and child failure reject. Errors 74–79 cover context/transport/Wait, 84 the cycle bound; child errors 80–83 cover transport/envelope/key/proof. The per-call budget is 250,000,000 cycles, not a CKB consensus limit. Child allocator budgets are 4 KiB small plus 516 KiB large. Allocation limits, observed stack peaks and whole-transaction cycles are reported separately.

ProofPlan's cryptographic-verifier-call records and the independent checker bind identities, source operands, canonical request words, stack locations, context loads, rejecting branches and result enforcement to emitted machine code. Missing executable coverage cannot be promoted to checked-runtime. Metadata-only browser compilation retains the contract but does not claim ELF checking. Mutations rehash sidecars before testing rejection.

The candidate setup uses OS randomness on a trusted local operator/host. No MPC ceremony or independent erasure proof is claimed. PK/VK, lock hash, matrix digest and setup provenance are in the package manifest. Admission checks the exact circuit, VK, scheduler/node reports and reproduced artifacts; it requires explicit --trust-local-setup. Human independent review is waived, not passed. The standalone checker and executable gates are still mandatory.

The acceptance map is here. Deployment custody, public-chain receipts, multi-Script composition and additional proof profiles are separate work; none is silently implied by the first profile's acceptance.