Skip to content

[Candidate][Consensus runtime] Implement executable bounded output-plan correspondence #8

Description

@a19q3

Summary

Implement the positive runtime semantics for BoundedList<P, N>::create_each.

The compiler already retains the plan predicate and create template, but production builds correctly reject the operation because there is no canonical witness codec or on-chain proof that every plan corresponds to exactly one output Cell in the required order, with the required identity, Script, data, lock, and capacity.

This issue depends on the selection and decoding foundations in #7, but it remains separate because output authorization and one-to-one correspondence have a larger attack surface than bounded input consumption.

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.

Security statement

A transaction builder may construct a plausible transaction, but builder behavior is not a consensus boundary. The emitted CKB Script must independently prove:

plan count == selected output count <= N
and
for every i: plan[i] authorizes exactly selected_output[i]

Missing, extra, duplicated, or reordered outputs must fail on chain.

flowchart LR
    W["WitnessArgs.input_type"] --> CODEC["Decode versioned PlanList<P>"]
    CODEC --> PC["plan_count"]
    GO["Canonical group-relative outputs"] --> OC["output_count"]
    PC --> EQ{"plan_count == output_count <= N?"}
    OC --> EQ
    EQ -- "no" --> REJECT["Stable correspondence error"]
    EQ -- "yes" --> ZIP["Zip plan[i] with output[i]"]
    ZIP --> SCRIPT["Verify Type/Lock Script policy"]
    SCRIPT --> DATA["Verify canonical output data"]
    DATA --> CAP["Verify occupied capacity floor"]
    CAP --> ID["Verify fresh/preserved identity policy"]
    ID --> ACCEPT["Every pair covered exactly once"]
Loading

Required semantic contract

The first supported shape should require:

  • a versioned canonical Molecule list in WitnessArgs.input_type;
  • a compile-time maximum N and runtime count enforcement;
  • canonical Type Script group-relative output ordering;
  • exact one-to-one plan/output correspondence;
  • one evaluation of each plan predicate and one materialization of each output template;
  • explicit Type Script, Lock Script, data schema, and capacity policies;
  • an explicit identity rule for every created resource;
  • stable failures for omission, duplication, reordering, malformed plans, and under-capacity outputs;
  • builder evidence that mirrors—but never replaces—the checks performed by the Script.

The accepted RFC must decide whether the initial version permits zero plans. It must not infer freshness or authority from action/function names.

Correspondence model

sequenceDiagram
    participant B as Transaction builder
    participant W as Witness PlanList
    participant T as Candidate outputs
    participant V as CellScript verifier
    B->>W: encode versioned plans
    B->>T: construct candidate outputs
    V->>W: decode and bound count
    V->>T: select canonical group outputs
    loop each index i
        V->>V: validate plan[i] against output[i]
    end
    V-->>B: accept only if all pairs and counts match
Loading

The builder and verifier must use the same ordering specification. A global-index witness is acceptable only if the Script proves uniqueness, monotonicity, group membership, and complete coverage.

Required failure taxonomy

Failure Required behavior
missing or empty required witness field stable witness/codec error
unknown plan codec version reject
malformed offset table or truncated item stable Molecule error
plan count greater than N stable count error
fewer outputs than plans stable missing-output error
more outputs than plans stable extra-output error
reordered outputs stable correspondence error
duplicate plan or output index stable duplication error
wrong Type Script or Lock Script stable Script-policy error
wrong data/schema stable output-data error
insufficient capacity stable capacity error
reused identity where freshness is required stable identity error
machine block removed standalone checker rejects the mutation

Implementation phases

Phase 0 — specification

Extend or add an accepted RFC that fixes:

  1. witness field and Molecule schema;
  2. codec versioning and canonical encoding;
  3. output selection source and ordering;
  4. count and zero-element behavior;
  5. one-to-one correspondence;
  6. Script/data/lock verification;
  7. occupied-capacity policy;
  8. fresh and preserved identity policies;
  9. ProofPlan and typed-semantics records;
  10. error codes and resource budgets.

Phase 1 — codec and typed boundary

  • generate and verify the canonical plan-list codec;
  • bind codec identity into entry ABI and metadata;
  • retain the full create template and predicate in typed semantics;
  • add separate ProofPlan obligations for decode, count, selection, ordering, pair correspondence, identity, and capacity;
  • make the builder manifest generate a fillable but non-authoritative plan skeleton.

Phase 2 — CKB runtime lowering

  • decode once with strict bounds;
  • select group-relative outputs canonically;
  • compare counts before materialization;
  • lower a deterministic bounded pair loop;
  • verify all output fields the compiler claims are constructed;
  • retain fail-closed behavior for every unsupported shape.

Phase 3 — independent verification and builder parity

  • teach the standalone checker to link every pair-validation block to typed semantics and source ranges;
  • add mutations deleting or bypassing count, ordering, identity, capacity, and data checks;
  • ensure generated builders and cellc tx validate use the same ordering and codec;
  • run every positive and adversarial fixture in simulator, CKB-VM, and the stateful harness.

Acceptance matrix

Case Expected
zero plans/outputs when allowed pass
one plan/output pass
exactly N pairs pass
N + 1 plans stable count error
missing output stable missing-output error
extra output stable extra-output error
reordered outputs stable correspondence error
duplicated plan or selected output stable duplication error
wrong Type Script stable Script-policy error
wrong Lock Script stable Script-policy error
wrong data payload stable schema/data error
under-capacity output stable capacity error
reused Type ID or logical identity stable identity error
valid builder output with one adversarial post-build mutation CKB-VM rejects
removed correspondence block in ELF standalone checker rejects

Completion criteria

  • An accepted RFC fixes the codec, ordering, identity, and capacity contracts.
  • Supported shapes no longer emit runtime error 24 or E2105.
  • Unsupported output collections remain fail-closed.
  • The builder and Script share one versioned plan/order specification.
  • Every plan/output pair is verified on chain exactly once.
  • Standalone checker mutations cover count, ordering, pair, identity, data, lock, type, and capacity checks.
  • Simulator, CKB-VM, stateful acceptance, and tx validate agree.
  • Worst-case cycles, stack, code size, transaction size, and occupied capacity are recorded.
  • dev, ci, and backend gates pass.
  • Independent security review is complete.

Non-goals

  • arbitrary allocator-backed output vectors;
  • transaction-wide fuzzy matching;
  • builder-only authorization;
  • implicit output ordering;
  • identity inferred from source names;
  • Cell-backed collection return values;
  • ranged foreign-Script composition, which belongs to a protocol-composition design.

Dependencies

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