ZK state channels on Mina Protocol
z2zlib: A Formal Specification of Zero-Knowledge State Channels for Mina Protocol
Overview
This specification defines a zero-knowledge state channel construction for the Mina Protocol. It allows two participants to run an off-chain state machine, advancing the state optimistically without blockchain interaction. Disputes are resolved by submitting zero-knowledge proofs on-chain to confirm or refute the validity of disputed state transitions. The design leverages Mina’s recursive proofs and efficient verification, ensuring minimal on-chain overhead and strong security guarantees.
Formal Notation and Definitions
Participants and Keys
Let be the set of channel participants:
- : Alice
- : Bob
Each participant has:
- : Public/private key pair suitable for signatures and on-chain identity.
- : Signature function, producing a signature on message .
- : Signature verification function.
State Representation
The channel maintains a sequence of states:
- : The state at step .
- Each is represented on-chain by a hash , where is a collision-resistant hash (e.g., Poseidon).
A move (or action) transforms into :
- is the state transition function at step .
- : A predicate for validating transitions. iff is a valid move according to the application’s rules.
Turn Taking
A turn mapping function defines whose turn it is at step :
For a generalization, this can be extended to more complex turn orderings encoded into the state or the circuit.
Zero-Knowledge Proofs
We use zero-knowledge proofs for:
- State Transition Proof (): Proves that a given transition from to is valid without revealing internal state.
- Fraud Proof (): Proves that a claimed transition is invalid.
- Final Proof (): Aggregates and proves that a final state is the result of a series of valid transitions from to .
We assume primitives:
- : Given a statement , produce a proof .
- : Verify that proves .
Settlement Contract
A smart contract manages disputes and finalization:
SC.settle(S_f, π_{final})
: Finalize the channel state if proves all transitions were valid.SC.submit(S_i, π_{fraud})
: Resolve disputes by verifying a proof of invalidity for a proposed transition.
The contract stores minimal data (e.g., the latest agreed-upon state hash), ensuring scalability.
Protocol Specification
1. Setup Phase
-
Key Exchange:
Both parties know each other’s public keys.
-
Initial State Agreement:
-
Alice proposes initial state :
-
Bob verifies and countersigns:
Now both agree on and its hash .
-
2. Program Execution
During the program’s execution phase, the state channel progresses off-chain using a combination of signatures and, when required, zero-knowledge proofs. The protocol supports two main execution flows:
-
Optimistic Execution (Signatures-Only): When no private inputs or complex verifications are required, transitions are performed and verified using digital signatures alone.
-
ZK Proof-Based Execution: When a state transition depends on private inputs or requires complex verification, a zero-knowledge proof of the state transition is generated and verified off-chain before acceptance.
If disagreements arise over a proposed transition, participants can resort to on-chain dispute resolution using fraud proofs.
2.1 Optimistic Execution (Signatures-Only)
This is the simplest scenario, relying solely on signatures and local verification of state transitions:
-
Suppose at state , it is Bob’s turn to act. Bob computes:
and constructs:
Bob sends to Alice.
-
Upon receiving , Alice verifies:
- is valid.
- , ensuring is a legal and correct move.
If valid, Alice proceeds with her move:
She then sends:
to Bob.
-
This pattern continues optimistically. If all moves are straightforward and verifiable without revealing any hidden data, no zero-knowledge proofs are necessary at this stage.
2.2 ZK Proof-Based Execution (Private Inputs)
When a move requires private inputs—e.g., secret randomness, confidential financial data, or hidden game elements—a signature alone is insufficient to assure the other party of correctness. In this case, the participant generating the move also produces a zero-knowledge state transition proof that the move is valid without revealing the secret input.
-
Suppose it is Alice’s turn to move from to using a move that depends on secret information (e.g., a hidden card in a game):
-
Alice generates a zero-knowledge proof:
This proof ensures that is a valid next state from given the confidential move , without exposing ’s private details.
-
Alice sends:
to Bob. Here, includes the zero-knowledge proof instead of directly disclosing the private input.
-
Bob verifies:
If the verification passes, Bob is convinced that the transition is valid, even though he does not know the private inputs that produced it. Bob then proceeds with his turn.
This approach preserves privacy and trust: complex or secret-dependent transitions can be validated without revealing secrets.
2.3 Fraud Handling (On-Chain Dispute Resolution)
If at any point a participant suspects fraud—either in the optimistic or ZK proof-based approach—their remedy is to produce a succinct zero-knowledge fraud proof and submit it on-chain:
-
The accusing participant constructs:
demonstrating that the claimed transition is invalid.
-
Submit to the settlement contract:
-
If , the contract settles the dispute in favor of the accuser, penalizing the cheater. Thus, on-chain dispute resolution ensures that no fraudulent transition can be enforced.
Summary of Execution Scenarios:
- Optimistic (No Private Input): Transitions rely on signatures. Participants trust each other’s verification, resorting to on-chain disputes only if necessary.
- ZK Proof-Based (Private Input): If a transition involves hidden data, a zero-knowledge proof is used off-chain to guarantee correctness. The other party verifies the proof rather than the underlying data.
- Fraud Handling: At any point, if a participant believes the other is cheating, they can produce a fraud proof and finalize the dispute on-chain.
3. Settlement Phase
When no more updates are desired:
-
Final State Agreement: Both participants finalize with a last message:
They now have mutually signed final state data.
-
On-chain Settlement: They can either:
- Just submit signatures if they trust each other’s previous steps.
- Or provide a recursive proof that all transitions from to were valid:
SC.settle(S_f, π_{final})
If , the contract finalizes and releases funds or concludes the channel.
Circuit Specifications
State Transition Circuit
Circuit StateTransition {
public inputs:
prev_state_hash: Field,
next_state_hash: Field,
transition_index: Field
private inputs:
prev_state: State,
next_state: State,
move: Move
constraints:
hash(prev_state) == prev_state_hash
hash(next_state) == next_state_hash
is_valid_transition(prev_state, next_state, move) == true
verify_turn(transition_index, prev_state.turn_mapping) == true
}
This ensures that given a previous state and a move, the next state is correct and the right participant made the move.
Fraud Proof Circuit
Circuit FraudProof {
public inputs:
state_hash: Field,
claimed_next_hash: Field
private inputs:
state: State,
claimed_next: State,
move: Move
constraints:
hash(state) == state_hash
hash(claimed_next) == claimed_next_hash
is_valid_transition(state, claimed_next, move) == false
}
This proves a purported transition is invalid.
Final Aggregated Proof Circuit
A recursive circuit can combine multiple StateTransition
proofs:
Circuit FinalProof {
public inputs:
initial_state_hash: Field,
final_state_hash: Field
private inputs:
transition_proofs: [π_{st,1}, π_{st,2}, ... π_{st,f}]
constraints:
// Recursively verify that each π_{st,i} is valid and chained correctly:
check_chaining(initial_state_hash, final_state_hash, transition_proofs)
}
This yields a single proving the entire chain of states is valid.
Security Properties
Safety:
-
State Validity:
Ensures no invalid states are accepted.
-
Authorization:
Only the designated participant at each turn can produce the valid signed state.
Liveness:
- Progress:
Honest participants can always produce the next state off-chain without going on-chain, ensuring responsiveness. - Finality:
A final state can always be settled on-chain with a proof or mutual signatures.
Privacy:
- Internal states and moves remain off-chain. On-chain, only hashes and succinct proofs are revealed, preserving the privacy of the channel’s execution details.
Implementation
-
Efficiency in Proof Generation:
- Use batching and recursion to reduce overhead.
- Employ Mina’s SNARK-friendly hash functions (e.g., Poseidon).
-
State Representation:
- Compact states (e.g., Merkle roots) to reduce proving complexity.
- Efficiently encode moves so the circuit remains small.
-
On-Chain Data Minimization:
- Store only hashes on-chain; never publish full states.
- Post proofs only when disputes occur or for final settlement.
-
Rational Incentives:
- Fraud proofs deter malicious behavior since cheating can be proved and penalized.
- Low overhead ensures participants have little incentive to escalate on-chain unless necessary.