Direction check: should noir-ckb generate CKB Type Scripts from Noir circuits?

Thank you so much for the response!

You’re right that the Type script also gates spending. All applicable script groups must pass, so the distinction is not that the Lock can reject a transaction while the Type cannot. It is about execution scope and responsibility:

  • A Lock Script runs when a cell is consumed and normally answers whether that input is authorized to be spent.
  • A Type Script runs for typed inputs and outputs and normally answers whether that application state is being created, updated, or destroyed according to its rules.

A new output cell’s own Lock does not execute when that cell is created; its Type does. Type groups also naturally bring the old and new typed cells into the same validation context. That makes Types a natural home for rules that must persist across state transitions.

In the current prototype, one proof is split across two checks:

Generic verifier Lock:
  verify that the proof is mathematically valid
  for its public-input vector

Capsule Type Script:
  derive the expected public-input vector from
  the actual input cell, output cell, identity,
  action and replay domain and compare

The Type does not repeat the Groth16 verification. It checks that the values verified by the Lock actually describe the transaction being attempted.

For example, suppose a proof is valid for:

Capsule 11, old state A, new state B,
update action 1, replay domain 13

If someone attaches it to a transaction that performs A -> C, the proof remains mathematically valid for A -> B, so the verifier Lock accepts it. The Type reads the actual output, reconstructs A -> C, sees the mismatch, and rejects.

invalid proof
  -> Lock rejects

valid proof + intended transition
  -> both accept

valid proof + different transition
  -> Lock accepts mathematically
  -> Type rejects the binding

That third case is the main result the current CKB-VM test matrix demonstrates.

As I think about this more, I see at least four possible patterns. The appropriate one depends on whether the Cell holds evolving application state and whether ownership authorization and state-transition validity should be checked separately.

  1. Proof-only Lock for a stateless cell. Here, possession of a valid proof is the authorization to consume the cell. There may be no continuing application state and therefore no need to create a successor cell with the same rules. This is suitable for something like a proof-gated vault, one-time claim, faucet or private eligibility check. In this case, adding a Type Script may only introduce unnecessary complexity.

  2. Generic verifier Lock plus binding Type, which is what the current prototype implements. The Lock verifies one proof against its verification key and public-input vector. The Type does not verify the proof again; it reads the actual old and new cells and checks that the proof’s public values describe this exact transition. This separates mathematical proof validity from application meaning. It is useful when several applications can reuse the same verifier code while defining their own state-transition rules.

  3. Normal ownership Lock plus proof-verifying Type. A conventional Lock, such as a signature or multisig, controls who may consume the Cell. The Type then verifies the ZK proof and binds it to the old and new application state. This may be more natural for a persistent application such as Battleship: the player authorizes the move through the Lock, while the Type proves that the private game rules were followed and that the resulting game state is valid.

  4. Two-proof composition. The Lock verifies one proof for private authorization, while the Type verifies a different proof for the state transition. For example, proof A could establish that the spender belongs to an authorized set without revealing their identity, while proof B establishes that the committed application state changed correctly. Both proofs would have to pass atomically. They would also need shared public context such as application identity, cell identities, action, and replay domain; otherwise, they could be two valid but unrelated proofs in the same transaction.

The current project establishes the second pattern. I do not yet know whether the generator should support all four. Each has different ownership assumptions, witness layouts, verification-key placement, and adversarial tests. The next question is which additional patterns solve real CKB application needs and which would only increase complexity and security surface.

For Battleship, the third pattern may be more natural than my current layout. A normal player Lock could control the game cell. The circuit would prove that a hit-or-miss response is consistent with the committed board, while the game Type would verify and bind that proof to the game identity, turn, coordinate, old state, and new state. That is proposed, not implemented, but it shows why proof placement should depend on the application.

I also find your two-proof observation very interesting… CKB can require several script groups to pass atomically, so one proof could establish private authorization while another proves a legal state transition.

However, atomicity alone is not enough. Both proofs would need shared public context such as application identity, cell identities, state commitments, action, and replay domain. Otherwise, the transaction only establishes:

proof A is valid AND proof B is valid

not:

proof A and proof B authorize the same operation

Your input has made the next design question much clearer:

which of these additional patterns would solve real CKB application needs, and which would only add complexity and security surface to the generator?

3 Likes