Background
CryptoKitties is a game about digital collectibles built on the Ethereum blockchain. It captured the attention of the cryptocurrency communities because it is bringing some of the core concepts of digital ledger technologies (e.g. wallets, transaction times, gas fees) to more of a mainstream audience.
It is also an example of digital scarcity. Unlike tokens which have been driving the explosion of initial coin offerings in cryptocurrency, CryptoKitties are an example of a digital asset, like a token, but where each is unique and can carry a unique value.
I’m currently working on some projects where we’re investigating similar concepts, so initially I started reviewing CryptoKitties as a proof-of-concept. However, I soon got pulled into the rabbit-hole of deciphering the puzzle of their genetic algorithm.
Breeding kitties for fun & profit
The premise is straightforward, breed two kitties with a set of unique cattributes and the offspring will have some mix of those cattributes.
For the most part, you can follow how the traits are passed on. For instance, above the bloodred trait was clearly inherited from the parents and passed on to one of the children.
Down the rabbit-hole
However, knowing that all of the breeding exists on the Ethereum blockchain makes this a lot more interesting. We know that, essentially the program that runs the breeding (the smart-contract) is available for everyone to see.
Soon after CryptoKitties launched, a myriad of fan-built tools and websites appeared to try to make sense of the kitties being bred (a population which quickly went into the 10,000s and then 100,000s).
One particularly interesting web tool is CryptoKittydex.
Cryptokittydex presented a fascinating puzzle about how the genes were encoded. Each kitty is represented as a unique long number, their genetic code, which is stored on the Ethereum blockchain.
I began to play around with this. Using what I know about procedural generation, I realized that there should be some base parts of each kitty which map to the cattribute and then to the appropriate gene.
As I started to map this out, something about CryptoKittydex was bothering me. Occasionally, you’d get duplicate values.
I soon realized that we should be looking at the binary code– and soon became obsessed with cracking the code.
I won’t go into each step of deciphering the code, I posted some of my work on in the Reddit group, with the subject CryptoKitties Genome Project.
CryptoKitties Genome — Deciphered
Here’s what I’ve found
- Genes are stored in 12 blocks of 4x5-bit codes
- Each 5-bit code represents a cattribute associated with the position in the gene (body, pattern type, eye color, eye type, primary color, pattern color, secondary color, fancy type, mouth)
- Each block of 4 codes represents 1 dominant trait expressed in the Kitty followed by 3 recessive traits.
- Codes are passed from either parent to child, with a low probability of swapping from the 1st recessive, and a lower probability of swapping from the 2nd or 3rd recessive.
- There is an occasional mutation on a gene, that seems to be a bitwise-rotation of a gene passed to a child.
- Fancy cats are either a unique combination of cattributes or a hidden fancy-type gene hidden in the 8th block.
- totesbasic is a special type of code where only 2-bits are responsible for the totesbasic cattribute which means it can hold hidden data.
Cattribute genes
Body
Pattern type
Eye color
Eye type
Primary color
Pattern color
Secondary color
Mouth
Fancy genes
Further research
Visible, recessive cattributes
I don’t yet understand how kitties that show more than 8 cattributes (with some not expressed) are storing those cattributes in the genes. There are 4 extra blocks in the genome, but some kitties have 13 or more cattributes listed.
Mutations
I’m not 100% sure how and when mutations occur. Is it completely random or is it something embedded in the genetic code?
Help with the project?
If you’ve found this research helpful, I’m taking donations of non-related attribute clones