zkHoldem
Presentation: https://www.youtube.com/watch?v=vQ5-Sn2dHFE
Introduction
zkHoldem is a Texas Hold'em game built on zkShuffle and launched on Manta Network.
The subtitle of zkShuffle is "Mental Poker on SNARK for Ethereum." The term Mental Poker was introduced in a 1979 paper by Adi Shamir, Ron Rivest, and Leonard Adleman. It explores whether a fair poker game can be played online without physical cards while ensuring the following three principles:
Hide the card values from all players
Ensure that the cards are dealt correctly, with fair randomness
Reveal a card to a specific player or group of players
Background
Please read ElGamal Encryption before continuing on.
Protocol Explanation
Overview of zkShuffle
zkShuffle is a protocol that distributes and shuffles cards among players. It primarily follows the Barnett and Smart structure, which has also been improved and implemented by Geometry.
The key novelty of zkHoldem compared to Geometry's implementation is that it utilizes Groth16 to implement the shuffle argument more efficiently. For further details, interested readers can refer to the Geometry blog.
Modified ElGamal Encryption
Randomly select a secret key in the range .
Compute the public key as follows:
where is a generator of an additive group of a large prime size.
When called for the first time, and , the message. This value is used for nested encryption.
A random scalar where is used to determine the shared secret .
Generate the ciphertext as follows:
is computed using the value that was used when calling . Note that this computed individually by each party is different from the iterative from .
Compute the plaintext as follows:
Properties of Modified ElGamal
Consider a scenario where Alice, Bob, and Carol each have private keys and their corresponding public keys . Now, let's examine the encryption process for a card .
Alice encrypts using :
Bob encrypts using :
Carol encrypts using :
After this process, the final ciphertext is generated as follows:
At this stage, Alice, Bob, and Carol can decrypt in any order to retrieve the original message . Suppose they decrypt in the order Bob → Carol → Alice:
Bob decrypts using :
Carol decrypts using :
Alice decrypts using :
Advantages of Modified ElGamal
One of the key features of Modified ElGamal is its order-independent decryption property.
This is particularly useful in blockchain environments, where:
Decryption results need to be submitted as on-chain transactions (tx).
The ordering of transactions within a block is unpredictable.
Since decryption can be performed in any order, this significantly enhances the usability of the protocol in decentralized systems.
Shuffling
In Texas Hold'em, a deck of 52 cards must be shuffled, which needs to be mathematically represented. For example, suppose we start with a set of four cards:
If Alice wants to shuffle them into the following order:
how can we express this mathematically?
This can be represented using a permutation matrix as a matrix multiplication:
Conditions for a Permutation Matrix
A matrix is a permutation matrix if it satisfies the following three conditions:
must be a square matrix.
All elements of must be either 0 or 1.
The function is defined as:
Each row and each column of must sum to 1.
The function is defined as:
The function is defined as:
Thus, the function can be defined as:
zkShuffle Scheme
Consider a scenario where players participate, and there are cards in the game. Each player is responsible for shuffling an encrypted deck . Here, is .
Where:
is an elliptic curve group, such as Baby Jubjub.
is the scalar field of the elliptic curve.
is the generator of the elliptic curve group.
All cards are given publicly known values, for example:
Thus, for , if is given, the corresponding card can be determined.
Each player randomly generates a secret key .
The public key is computed as follows:

Player generates a random permutation matrix .
Upon receiving deck from player , the shuffled deck is computed as follows:
Player generates random values (for ).
Player encrypts the shuffled deck into where each card is calculated as follows (for ):
Player generates a ZK-proof for the following circuit and submits it along with in a transaction:

Each player decrypts a received encrypted card to obtain as follows (The reason shuffling does not need to be considered during decryption is that if we assume the cards were shuffled using , the final recovered message () will always be one of the elements in .):
Each player decrypts an encrypted card to obtain :
The player generates a ZK-proof for the following circuit and submits it along with in a transaction:
Since the contract already has the shuffled encrypted cards, it knows which card is at the top of the deck and which card needs to be decrypted. It verifies whether the public input corresponds to the correct card for decryption.
Game Flow
Shuffling Cards
Cards are given publicly known values.
All players shuffle the cards using .
Distributing Two Cards to Each Player
Cards are dealt from the top of the deck to players in a predetermined order.
For all dealt cards that do not belong to them, players call .
After step b is finished by every player, players reveal their own cards to themselves with .
Revealing Three Community Cards
The top three cards from the deck are placed on the table.
All players call for these cards, revealing them.
Revealing Additional Community Cards (Two Rounds)
One additional card from the top of the deck is placed on the table in each round.
All players call for these cards, revealing them.
Revealing Player Cards
Players who remain until the end reveal their cards using .
How Are the Three Principles Ensured?
Hide the card values from all players.
Cards are encrypted using . Therefore, unless all players participate in decryption, they cannot access the original card value.
Ensure that the cards are dealt correctly, with fair randomness.
Before the game starts, all players contribute randomness to shuffle the cards. Even if some players collude, the deck remains randomly shuffled.
ensures that all players have encrypted the shuffled cards according to the shuffling rules using ZK.
From the shuffle ZK proof, the contract knows the order of the deck.
If a player attempts to decrypt a card that is not at "the top of the deck", the contract will reject the request.
Reveal a card to a specific player or group of players.
Revealing to one player
A player's card is revealed to them when calling after all other players have run .
Since does not submit the result to the contract, other players cannot see their cards.
Revealing to all players
Once every player calls on a card, it is revealed.
Conclusion
The Circom code for zkHoldem is private, but according to the paper:
includes 3,500 constraints.
includes 170,000 constraints.
Using ZK for online Texas Hold'em is an exciting concept.
However, there are some limitations:
Receiving a single card requires multiple interactions with other players for decryption.
Even if a player folds, they must stay online to complete the decryption process.
These challenges highlight key areas for improvement in real-world applications.
References
Last updated