Skip to content

[Candidate][Consensus runtime] Implement executable bounded Cell-group consumption #7

Description

@a19q3

Summary

Implement the positive runtime semantics for BoundedCellSet<T, N>::consume_each on the CKB target.

The frontend already preserves the bounded operation and its predicate, but production builds correctly reject it because the emitted verifier does not yet select, authenticate, decode, count, and discharge the lifecycle of every matching input Cell. This issue is complete only when the selected shape executes in CKB-VM and the standalone checker can prove that the corresponding machine blocks are present.

This is a consensus-facing feature. An accepted specification must precede positive lowering.

Portfolio status

This is a candidate consensus-runtime workstream, not an authorized 0.26 or P0 implementation commitment. Until the post-0.25 evidence review accepts concrete use cases, an accountable owner, an independent reviewer, capacity, and stop conditions, only Phase 0 specification and use-case discovery are authorized. The issue priority describes semantic risk, not a promised release slot.

Why this is a real gap

Today, N is only a static complexity declaration. It is not evidence that runtime execution observed at most N Cells. The current boundary is documented in the collections support matrix.

Explicit fixed-arity parameters work, but they do not express protocols whose input cardinality is bounded yet chosen by each transaction—for example batched account updates, bounded receipt settlement, or a capped set of claims.

Argent's open range PR #44 is a useful design signal, not production evidence: its runtime builder and several interaction classes remain follow-up work. CellScript must define the CKB Script Group, Molecule, identity, and linear-lifecycle contract directly.

Required semantic contract

The first accepted version should be deliberately narrow:

  • support Type Script group inputs first;
  • require an explicit group source; never scan the whole transaction implicitly;
  • bind T to an exact Type Script identity and canonical schema;
  • compute the actual group cardinality in CKB-VM and require actual_count <= N;
  • decode every selected Cell exactly once;
  • execute the predicate exactly once for every decoded element;
  • fail the whole Script on any predicate, identity, source, count, or decoding failure;
  • discharge every selected Cell through the linear consume lifecycle;
  • preserve canonical group-relative order in metadata, traces, and builder evidence.

Lock Script support must be a separate explicitly justified shape if its observable group and authority rules differ.

flowchart LR
    TX["Candidate CKB transaction"] --> SG["Exact Type Script group inputs"]
    SG --> COUNT["Load actual group count"]
    COUNT --> BOUND{"count <= N?"}
    BOUND -- "no" --> REJECT["Stable runtime error"]
    BOUND -- "yes" --> LOOP["For each group-relative input"]
    LOOP --> ID["Verify Script identity"]
    ID --> DECODE["Decode canonical Molecule T"]
    DECODE --> PRED["Run predicate exactly once"]
    PRED --> LIFE["Record/discharge consume"]
    LIFE --> ACCEPT["All selected Cells covered"]
Loading

Required failure taxonomy

Each failure must have a stable registered runtime error and a source-linked ProofPlan obligation:

Failure Required behavior
wrong source kind Reject before trusting data
wrong Type Script identity Reject the selected Cell
missing or ambiguous identity Reject; never fall back to schema-only matching
malformed Molecule data Reject with a decoding-specific error
actual count greater than N Reject before iteration
duplicate logical identity Reject when the resource policy requires uniqueness
predicate returns false Reject the complete transaction
predicate or decode path omitted by codegen Standalone checker mutation must reject the artifact
lifecycle not discharged Compile-time ownership error or production rejection

Implementation phases

Phase 0 — specification

Add an accepted bounded-lifecycle RFC covering:

  1. observable source and group ordering;
  2. Type Script identity policy;
  3. canonical Molecule codec;
  4. zero-input semantics;
  5. uniqueness policy;
  6. predicate evaluation and side-effect rules;
  7. error-code allocation;
  8. ProofPlan and typed-semantics records;
  9. Lock versus Type Script differences;
  10. cycle, stack, and serialized-size budgets.

No positive runtime lowering should land before this phase is accepted.

Phase 1 — typed and metadata boundary

  • keep the predicate and source selection in typed semantics;
  • make actual-cardinality observation explicit;
  • add independent ProofPlan records for selection, identity, decode, count, predicate, and lifecycle discharge;
  • update entry ABI and builder assumptions;
  • ensure the executable-surface classifier distinguishes the newly supported shape from all unsupported variants.

Phase 2 — CKB runtime lowering

  • use canonical Script Group input syscalls;
  • enforce actual count before iteration;
  • lower a bounded loop with deterministic memory use;
  • decode each element once and retain a typed addressable view;
  • propagate exact runtime errors;
  • keep unsupported shapes fail-closed with E2105.

Phase 3 — verification and tooling

  • extend the standalone artifact checker and mutation corpus;
  • add simulator, CKB-VM, and stateful CKB acceptance fixtures;
  • update builder validation, LSP, VS Code, Playground summaries, docs, and release notes;
  • measure worst-case cycles, stack, code size, transaction size, and occupied capacity.

Acceptance matrix

The same fixture identity must be exercised in simulator, CKB-VM, and the stateful harness.

Case Expected
zero matching inputs, when minimum is zero pass
one matching input pass
exactly N matching inputs pass
N + 1 matching inputs stable count error
wrong Type Script hash stable identity error
malformed Molecule payload stable decode error
predicate false on first/middle/last element same predicate error
duplicate logical identity stable identity-policy error
transaction-wide match outside the Script Group ignored or rejected according to the accepted source rule; never silently selected
removed count/identity/decode/predicate machine block standalone checker rejects the mutation

Completion criteria

  • The bounded-lifecycle RFC is accepted.
  • A selected supported shape no longer emits runtime error 24 or E2105.
  • Unsupported sources and element shapes remain fail-closed.
  • Typed semantics and ProofPlan record actual runtime cardinality observation.
  • The machine lowering has deterministic mutation coverage.
  • Simulator, CKB-VM, and stateful CKB fixtures agree.
  • dev, ci, and backend gates pass.
  • At least one independent security review focuses on source selection, identity, decoding, and lifecycle coverage.
  • Release evidence includes worst-case cycles and size bounds.

Non-goals

  • allocator-backed collections;
  • arbitrary transaction-wide queries;
  • unbounded loops;
  • generic Cell-backed collection returns;
  • implicit schema-only identity;
  • hiding builder assumptions as on-chain authorization;
  • implementing create_each in this issue.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions