We want to implement a card game with EVM and Smart Contracts. After defining all-important game information we asked ourselves how we can include the cards in the Smart Contract but don't make it public for all the Users interacting with the Contract.

The Game is based on betting per round, so the Users need to see their cards first to decide which amount of ether they want to invest.

So basically we want to include the dealt cards so that the Players can't change them.

Is it possible to decrypt the cards in the contract?


Your biggest problem is that all information is public on the blockchain. That also means that all information the smart contract uses is public. So if you encrypt some data, send the decryption key to the contract so it could decrypt data when needed, the decryption key would also become public the moment you send it.

I'm not quite sure how your game would work but you could consider hash functions, whether they might be of use to you. So the basic idea would be that the hashed strings would be public but in order to create the same hash string you need to know the exact inputs so you couldn't cheat. One of the problems here is that there are only a limited amount of cards in play so it would be easy to brute-force and check all possible combinations to get the right hash output.

One extra difficulty you will face is randomness, if you decide to organize the game purely in the blockchain. It's very difficult to get really random numbers in a deterministic blockchain. If you want to pursue this goal, then you should check out a project called RanDAO.

There are other alternatives for secret data such as zk-Snarks but I'm really not familiar with those and they get rather complicated. The basic idea is that you can prove you have some data without letting anyone know what the actual data is - a bit similar to hash functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.