This repo contains the Alice and Bob Super Battle game demoed at ETH Prague. The game leverages the Sunscreen Fully Homomorphic Encryption (FHE) compiler to hide players' power levels. Through the power of FHE, the game loop is able to deal damage and level them up players without ever decrypting players' stats!
You can easily try out the code in our playground!
The game plays as follows:
Power level (PL) is effectively the player's health and the maximum damage they can deal.
- A service (e.g. a smart contract) initializes each players'
total_pl
to100
encrypted under their respective public keys. - At the start of battle, each player chooses a
play_pl
:0 < play_pl < total_pl
, encrypts it with their public key, shares it, and publishes a zero-knowlege proof (ZKP, not implemented) to show theirplay_pl
is valid. This helps obfuscate players' maximum health during battle. - The service assigns
current_pl = play_pl
(i.e. it copies the ciphertext). - Each round, players choose
damage
to deal to their opponent between0 < damage < current_pl
. They encrypt this damage under their opponent's public key, publish the ciphertext, and produce a ZKP (not implemented) to show their choice is valid. - The trusted service uses homomorphically subtracts the damage from each player's
current_pl
. - Each player must prove (not implemented) either their
current_pl > 0
orcurrent_pl < -10
. Otherwise, they die. Whencurrent_pl < -10
, the service resets theircurrent_pl
to theplay_pl
ciphertext, resurrecting them to full health. This punishes overkilling your opponent. - If one player remains alive the service levels them up with the following formula run homomorphically:
total_pl = (total_pl - play_pl)^2
. Dead player(s) retain their oldtotal_pl
. - Play continues with more powerful players! Goto 2.