The cryptography, in depth

Rocket Race, under the hood

The tour keeps it simple. Here is how a fair course actually gets made, written to be readable by anyone, with deeper asides for those who want them. The same ideas power every game in the arcade.

Verifiable randomness

beginner

Lots of games need randomness: a race course, a card shuffle, a loot drop. On a blockchain there is no Math.random(), and the easy sources are unsafe, a block hash or timestamp can be nudged by the validator producing the block, and anything already on-chain can be read and exploited before you act.

The fix is commit-reveal randomness: each participant locks a secret (publishing only its hash), and once everyone is committed they reveal. The shared result is the hash of all the secrets, so no one party can predict it or steer it.

seed = keccak256( secret₁ β€– secretβ‚‚ β€– … )
Hidden until reveal (unpredictable) and locked before you see the others (unsteerable).

Lock two secrets, then reveal to see the course they produce:

You
commitment
0x2ed80a69…
secret
hidden until reveal
Rival
commitment
0x4c0be47d…
secret
hidden until reveal

Both players locked in a secret and published only its hash. Neither can see the other's.

deeperOne subtlety is the last revealer: whoever reveals last sees the result first and could bail if they dislike it. Real systems defend against this with stakes and penalties, or with a VRF (verifiable random function), which emits a random output plus a proof that it was computed honestly from a seed, so it can't be cherry-picked.
in this gameThe race seed is commit-reveal randomness: every racer locks a secret before the start, then all are revealed and combined. The seed is keccak256(secret₁ β€– secretβ‚‚ β€– …), which becomes the course.

Commit and reveal

beginner

A commitment lets you lock in a secret now and reveal it later, with two guarantees:

  • Binding: you can't change what you committed. Any change to the data changes the root.
  • Hiding: the commitment (just a hash) reveals nothing about the data.

You publish the root up front. Later, when challenged, you reveal a specific piece plus its Merkle proof. The other side checks the proof against the root you already locked, so you can neither lie about it nor have changed it.

deeperEach cell is salted before hashing. Without a random salt, a ship-or-water cell is one of only two values, which an opponent could simply hash both ways and match. The salt makes each leaf unguessable.
in this gameThe commitment is what stops cheating: a racer who could pick their secret after seeing the others could grind for a course that suits them. Locking the hash first makes that impossible.

Hashing

beginner

A hash function takes any data, a word, a file, a whole game board, and returns a short fixed-size fingerprint. These games use keccak256, which always returns 32 bytes (64 hex characters).

h = keccak256(data)
Same input always gives the same 32-byte output.

Three properties matter:

  • Deterministic: the same input always gives the same hash.
  • One-way: you cannot run it backward to recover the input.
  • Avalanche: change one bit and the whole output changes.
keccak256(input) =
0x3c61050a35421655441c721d163a8e8568cc126d41746bc5371d9c3e36f4ba4d
change one character β†’ rocket at cell 13
0xb92f0de5e6204b300beef827386f056eecc45dd2bd3e57dcb1976d90dc8d9504

Same input, same output, every time (deterministic). Change a single character and the whole result scrambles (the avalanche effect), and there is no way to run it backward. That is what makes a hash a tamper-evident fingerprint.

deeperIt is also collision-resistant: finding two different inputs with the same hash would take roughly 2128 work, which is infeasible. That is precisely what lets a hash stand in for the data as an unforgeable commitment.
in this gameThe course itself is just the seed, hashed and sliced: each chunk of the hash places one gate. Because hashing is deterministic, the same seed always rebuilds the exact same course, and because it is one-way, nobody can work backward from a course they'd like to the seed that makes it.

The honest part

We're upfront about the trust model and what is still to come:

  • The real subtlety is the last revealer: whoever reveals last sees the seed first and could refuse to reveal a course they dislike. The standard fixes are a stake they forfeit for bailing, or a VRF that removes the choice entirely.
  • Verifying that a posted time is a real, human run (not a bot or a sped-up replay) is its own problem. The usual approach records your live inputs as you fly the revealed course, then re-simulates them to confirm the time. Your inputs are always made in real time against the course you can see, the recording is just the receipt.
  • No contract is deployed yet. This is the teaching tour; the playable, on-chain race is the next build.

Want the building blocks on their own? They live in the crypto encyclopedia, shared with every other game.