Racing F1
On-chain racing game: cars as BFV-encrypted vectors. Training and speed computation via HE (BFV). Ed25519 signatures and a smart contract ensure integrity and anti-cheat.
Demo Video
Project Information
At a Glance
On-chain racing game: cars as BFV-encrypted vectors. Training and speed computation via HE (BFV). Ed25519 signatures and a smart contract ensure integrity and anti-cheat.
Description
PROTOCOL FLOW
- Setup (done by minimal trusted external program)
- Fix a prime p.
- Generate signing keys (f1,v1) (Ed25519).
- Generate HE (BFV) keys with Pyfhel: public keys p1,p2,p3 and private key k1.
- Distribute p1,p2,p3 to server and players; keep k1 only in the external program.
- Build a hidden quadratic speed polynomial P by sampling 66 coefficients in Zp (because a quadratic over 10 variables has 66 terms and the ten components of the car vector are used as the variables).
- Encrypt and distribute the encrypted coefficients to the server and the users.
- Never store plaintext cars or P (polynomial's coefficients).
- Registration: For each new player, the external programme generates a random 10-vector with entries in [1,999]. Encrypts it with p1, signs with f1 and delivers to the player (no plaintext retained by the programme). From now on, the player owns an encrypted and signed car.
- Training (up to 9 rounds per player) Per round: Player pays 1 token and submits one of their signed cars to the programme. The programme verifies the signature, generates a random integer 10-lenght vector with entries in [−19,19], it encrypts the vector with BFV and adds it to the car vector under homomorphic encryption. The programme signs the resulting encrypted car and returns it to the player. Player evaluates encrypted speed by applying encrypted P to the encrypted car using p1,p2,p3. He sends only the encrypted speed to the external program, which decrypts the scalar and returns the speed value in plaintext. This process lets players iteratively evolve cars while keeping both the previous and the trained car flags and the speed formula secret.
- Race & public verification To enter the race, a player pays 1 token and publishes the chosen encrypted, signed car to a smart contract. The server collects the published cars, verifies the signatures, evaluates all speeds homomorphically with BFV and sends only the encrypted speed results to the external program for decryption. The final leaderboard (plaintext speeds) is published on-chain.
Problems solved: -Anti-stealing: if two identical encrypted cars appear, only the first published is accepted (blockchain order = ownership). Moreover, the probability that two honest cars generated by the protocol are exactly identical is negligible, so duplicates flag copying. -Auditability: anyone can re-encrypt the published plaintext speeds and check they match the encrypted evaluations for each public car. If an inconsistency is found, the race is invalidated; otherwise the winner receives 100 tokens. -Anti-collusion: as in the training part there is only the interaction between the player and the programme and in the race part the speed is calculated by the server our systems prevents collusion.
We partially used AI (chatGPT, Claude) for the implementation
Technical Details
- Signing keys (f1,v1) using ECDSA Ed25519.
- Homomorphic encryption using BFV
- Build a hidden quadratic speed polynomial P by sampling 66 coefficients in Zp for the speed formula (evaluation of that polynomial using the 10 encrypted car flags as the variables)
- Random generator to generate the initial cars and for training.
Team
4giorgia caselli
Giuseppe Zampella
Alessia Vallefuoco
Alessandro Margaritelli