z2zlib — P2P State Channel on Mina

Alperen Tunçkıran
9 min readFeb 13, 2025

--

1. Introduction

The magic of Mina is not exactly that it has a very small (22kb) chain size.

The real magic of Mina comes from the fact that you can verify everything on Mina.

Using DeFi apps on Mina may be slow, but it offers a very secure environment. There is no limit to what you can do in this environment.

  • You can store your passwords encrypted in a secure smart contract.
  • You can verify Ethereum state transitions.
  • You can even program a Proof of Reserve system and ensure the reliability of exchanges through Mina.

If you haven’t decided what to develop on Mina in the Navigators Program Season 3, I offer you a very nice example in this article.

To get information about the Navigators program:

Enjoy your reading :)

2. WTF is State Channel?

Blockchains are public networks that operate with a global state machine. Your transactions are sent, tracked and published openly to the world.

Your wallet address is your identity. No privacy.

You have agreed with a user that you want to exchange a token/NFT via a swap. If you trust this user, you can handle this transaction in a simple way. But if you don’t, you can use a smart contract on the blockchain.

But what if you want to keep the transaction private? Then you should use State Channel.

Let’s take another example. Imagine a chess game where the matches and results are written on the blockchain. You wouldn’t like a wallet app that opens after each move, would you?

In this case, by creating a State Channel between two chess players playing against each other, the opponents, the result of the game, and the winner can be written to the blockchain at a much lower cost and without annoying them.

State channels enable participants to conduct multiple transactions off-chain, requiring only two on-chain interactions, one at the start (to open the channel) and one at the end (to settle the final state).

This significantly reduces the number of transactions processed by the main blockchain, improving speed and lowering transaction costs.

Participants lock a certain amount of cryptocurrency or other blockchain assets in a multi-signature smart contract on-chain. This contract defines the rules for state updates and dispute resolution. Once the channel is open, transactions occur directly between participants without involving the blockchain.

Each new state update is signed by all parties and replaces the previous state. When participants decide to close the channel, they submit the final state to the blockchain, which verifies the validity of the transactions and settles the balances accordingly.

3. ZK State Channels ⚔️ Optimistic State Channels

Different approaches exist for verifying the correctness of off-chain state transitions.

The two primary models are Zero Knowledge State Channels and Optimistic State Channels, each offering distinct mechanisms for security, dispute resolution, and privacy.

ZK State Channels integrate zero knowledge proofs into the state channel framework, ensuring that off-chain transactions remain private while being verifiable.

In this model, when participants update the channel’s state, they generate a cryptographic proof that attests to the correctness of the new state without revealing transaction details. The blockchain only needs to verify the validity of the proof, ensuring that state updates comply with pre-defined rules without requiring all transaction data to be submitted on-chain.

This approach provides maximum privacy and stronger security guarantees, as invalid state transitions cannot even be proposed.

Optimistic State Channels operate under an “assume honesty” principle, meaning transactions are considered valid by default unless proven otherwise. When participants interact off-chain, state updates are exchanged and signed without immediate blockchain verification.

Instead, state updates are only posted on-chain in case of a dispute. If a party tries to submit an incorrect or outdated state, the honest participant can challenge it within a dispute window by submitting proof of the correct latest state. This model significantly reduces computational overhead, making Optimistic State Channels more efficient in terms of processing speed and transaction costs. However, they require active monitoring to detect fraud and ensure that incorrect states do not get finalized.

-> One of the key differences between the two models is their approach to security and fraud prevention. ZK State Channels proactively prevent invalid transactions by requiring every state transition to be cryptographically proven before it is accepted. This reduces reliance on watchtowers (third-party monitors) and minimizes the risk of fraud. In contrast, Optimistic State Channels rely on a challenge-response mechanism, meaning that if one party does not actively monitor the network, an attacker could exploit the system by submitting an outdated or fraudulent state. While the challenge mechanism provides security, it introduces a delay before the final state can be confirmed.

-> Privacy is another critical distinction between ZK and Optimistic State Channels. In ZK State Channels, transactions remain completely private because only the final cryptographic proof is submitted on-chain. The blockchain does not store transaction details, making this approach ideal for confidential financial transactions, gaming, or business contracts where privacy is crucial. Optimistic State Channels, however, do not provide the same level of privacy. While off-chain transactions are not immediately visible, if a dispute arises, the correct state must be revealed on-chain for verification. This means that in contested situations, transaction history may become publicly accessible, reducing confidentiality.

  • > In terms of performance and efficiency, Optimistic State Channels generally have lower computational overhead since they do not require constant cryptographic proof generation. Instead, they rely on delayed verification, which only activates if a dispute occurs. This makes them a preferred choice for applications where computational efficiency is more important than strict privacy, such as gaming, microtransactions, and low-risk interactions. ZK State Channels, while offering stronger security and privacy, require complex cryptographic computations for each state update. The cost of generating and verifying zero-knowledge proofs can be higher, making them better suited for use cases where privacy and security outweigh computational concerns, such as high-value financial transactions or regulatory-compliant private contracts.

4. z2zlib — P2P State Channel on Mina

4.1. Network Stack

z2zlib’s network stack is a critical component designed to facilitate efficient and secure peer-to-peer (P2P) communication within the Mina Protocol ecosystem. Built upon the libp2p.js framework, it manages peer discovery, connection establishment, and data transfer between participants.

The stack comprises two primary components: Connection Setup and Proof Exchange.

Connection Setup focuses on establishing direct communication channels between peers, even when they are behind Network Address Translation (NAT) devices. To achieve this, z2zlib employs a hole punching protocol for NAT traversal. Initially, an Interactive Connectivity Establishment (ICE) server is utilized to facilitate the connection process.

GLOSSARY OF TECHNICAL TERMS

NAT (Network Address Translation) devices are routers or firewalls that manage private IP addresses within a local network while allowing devices to communicate with external networks (like the internet) using a shared public IP. NAT traversal is required for z2zlib, as direct connections between devices behind NATs are usually blocked. Techniques like hole punching and relay servers help establish these connections. z2zlib uses hole punching protocol.
— — — — — — — — — — — — — — — — — — —

ICE servers help devices discover the best path for direct communication by using STUN (Session Traversal Utilities for NAT) to determine public IP addresses and TURN (Traversal Using Relays around NAT) as a fallback when direct connections fail. This ensures reliable NAT traversal for z2zlib, enabling seamless P2P communication.
— — — — — — — — — — — — — — — — — — —

WebRTC (Web Real-Time Communication) enables direct P2P communication for real-time audio, video, and data transfer over the internet without needing intermediaries.

It uses ICE (Interactive Connectivity Establishment) for NAT traversal, STUN/TURN servers for connection establishment, and secure encryption to ensure private communication. WebRTC is widely used in video calls, online gaming, and decentralized applications like z2zlib to facilitate efficient off-chain state proof exchange.

Once a connection is established, the Proof Exchange component manages the secure and efficient transfer of state proofs between participants.

z2zlib implements WebRTC as the transport layer, enabling real-time, peer-to-peer communication. This setup ensures that state proofs are exchanged reliably and securely, maintaining the integrity and confidentiality of the data transmitted between peers.

4.2. State Management

The management of state channels involves several technical aspects:

  • Channel Initialization: Participants establish a state channel by creating a multi-signature smart contract on the blockchain, locking in assets and defining the initial state. This contract ensures that the funds can only be accessed or modified according to the agreed-upon rules.
  • Off-Chain State Transitions: Within the open channel, participants can perform numerous transactions by mutually signing updated states. These off-chain transactions are instantaneous and incur no fees, as they do not require immediate blockchain validation.
  • Channel Closure: When participants decide to close the channel, the final agreed-upon state is submitted to the blockchain. The smart contract then verifies the validity of the state and distributes the locked assets accordingly.

4.3. Zero-Knowledge Proof Generation and Verification of State Transitions

ZKPs are utilized to ensure the integrity and privacy of off-chain state transitions:

  • Proof Generation: For each state transition, a ZKP is generated to verify that the transition follows predefined rules without revealing the underlying transaction details. This involves complex cryptographic computations to create a succinct proof that can be efficiently verified.
  • Proof Verification: After the channel is closed, the accumulated ZKPs are combined with the final state into a common zero knowledge proof and sent to the blockchain. The smart contract verifies this final proof to confirm that all off-chain transactions are valid and that the final state is correct.

5. Potential Use Cases of z2zlib

5.1. Micropayments
z2zlib enables participants to conduct numerous off-chain transactions with minimal fees, making it ideal for micropayments. This capability is particularly beneficial for services like content streaming, where users can pay per unit of consumption (e.g., per second of video or per article read) without incurring prohibitive transaction costs.

5.2. Decentralized Finance (DeFi) Applications
In DeFi, z2zlib can facilitate high-frequency trading and off-chain liquidity management. Traders can execute multiple transactions off-chain, only settling net balances on-chain, thereby reducing gas fees and improving transaction speeds.

5.3. Gaming and Virtual Worlds
For blockchain-based games and virtual environments that require frequent state updates (e.g., character movements, in-game asset transactions), z2zlib’s state channels allow these interactions to occur off-chain. This approach reduces latency and enhances the user experience by providing real-time responsiveness.

5.4. Supply Chain Management
z2zlib can be applied to supply chain systems where multiple parties need to update the status of goods as they move through the chain. Off-chain state channels enable efficient and private recording of transactions between suppliers, manufacturers, and retailers, with the final state periodically committed on-chain for transparency and auditability.

5.5. Private Transactions
By leveraging zero-knowledge proofs, z2zlib ensures that transaction details remain confidential while still providing verifiable proofs of validity. This feature is valuable for applications requiring privacy, such as confidential business contracts or private financial transactions.

6. Conclusion and References

The main purpose of this article is to illustrate a potential use case of Mina for Mina users and those developing applications on Mina.

If you are not sure what to develop within the Navigators Program, rest assured that there are countless unique types of applications you can develop on Mina.

Some applications can be developed on any blockchain, some blockchains offer a quality environment for the development of certain types of applications.

You can easily develop any cryptography related application on Mina.

Thanks for reading..:)

--

--

No responses yet