Every player's position is sealed inside MagicBlock's Private Ephemeral Rollup (an Intel TDX enclave). Your wallet can read your own line of sight and nothing else.
Play ยท Watch it ยท How it works ยท Run locally
- The idea
- See it in action
- Features
- How to play
- How it works
- Tech stack
- Run it yourself
- Tests & verification
- Project structure
- Roadmap
- Credits & license
Onchain games have always been played with the cards face up. Every account is public, so any "hidden" information (where your opponent is, what's in their hand) can be read straight from the RPC. That's why fog of war, the backbone of strategy games and battle royales, has been nearly impossible onchain. Dark Forest needed ZK circuits and ran at a crawl.
Nightfall fixes it with MagicBlock's Private Ephemeral Rollups. All positions live in a World account sealed inside
a TEE with zero readers. Every move, the program recomputes what each player is allowed to see and writes it to a
per-player Vision account that only that player's wallet can read. The result is a real-time, blocky battle
royale where you see only what your torch lights, and nobody can cheat their way past that, the host included.
Try to cheat: press X in a match. The X-ray panel queries the TEE with your own token:
World โ null,Opponent's Vision โ null,Your Vision โ 155 bytes.
A real devnet match recorded headlessly against MagicBlock's TEE. Every step and swing is a transaction.
Gameplay
- โ๏ธ Up to 6 players (humans or bots) in a shrinking-border battle royale. Last one standing takes the onchain pot.
- ๐ฆ Three-layer fog of war: what you see (torch radius + line of sight), what you remember (dimmed terrain), and what you hear (the TEE tells you the direction of unseen enemies within 8 tiles, never their position).
- ๐พ Tall grass hides you unless someone is right next to you; stone and trees block sight; arrows fly over water.
- ๐งฐ 10 loot chests: Diamond Sword, Battle Axe (9 dmg, slow), War Hammer (knockback), Spear (reach 2), Golden Apples, arrows, and powers: Ender Pearl (blink over walls), Cloak (invisible + silent), Flare (far sight).
- ๐บ๏ธ Three arenas ร night or day. Spawns fill the corners first, plus 10 s of spawn protection.
- ๐ค Bots with personalities (archer / brawler / mixed) that play from their own sealed Vision, so they can't cheat either.
Feel & onboarding
โถ๏ธ One button to play. No wallet popups: a devnet burner lives in the browser.- ๐๏ธ Warm-up yard while the chain sets up: four quick quests teach every control by doing them, and you choose when to drop in.
- ๐ฌ Just-in-time coaching: a single tip the first time you see a chest, an enemy, footsteps, or the border.
- ๐ฎ Game feel: hit-stop, damage numbers, screen shake, kill streaks, heartbeat at low health, countdown beeps, synthesized night ambience and stereo footsteps. Zero asset files: every block, skin, icon and sound is generated in code.
- ๐๏ธ Spectate without a code: an onchain registry lists recent arenas, live first; follow any player with โ/โ.
| Key | Action |
|---|---|
| WASD / arrows, or click the ground | Move (click-to-walk pathfinds for you) |
| Space | Attack: auto-aims. Melee if someone's in reach, bow if they're lined up |
| F | Shoot the bow straight ahead |
| E | Use your power (Pearl / Cloak / Flare) |
| H ยท X ยท M | Help ยท X-ray (try to cheat) ยท Mute |
Rules: you only see what your torch lights โ loot chests โ the border waits 60 s then closes a tile every 14 s โ outside it you burn โ last one standing wins.
flowchart LR
subgraph Browser["Player's browser"]
UI["three.js voxel client + burner wallet"]
end
subgraph Solana["Solana devnet - base layer"]
P["Nightfall program - Anchor 1.0"]
V["Vault PDA - stakes, never delegated"]
R["Registry PDA - recent arenas"]
end
subgraph TEE["MagicBlock Private ER - Intel TDX"]
A["Arena - public scoreboard, border, feed"]
W["World - sealed, NO readers"]
VI["Vision per player - readable only by its owner"]
B["Broadcast - public, about 10 s delayed"]
end
CR["MagicBlock crank"]
VRF["MagicBlock VRF"]
UI -->|create, join, delegate| P
UI -->|act: move, attack, bow, power| W
W -->|recomputed every tx| VI
VI -->|auth-token RPC and websocket| UI
CR -->|tick: border and broadcast| A
VRF -->|spawn callback| W
A -->|commit and undelegate| P
P -->|claim| V
sequenceDiagram
autonumber
participant H as Host (you)
participant S as Solana
participant T as TEE rollup
participant O as VRF oracle
H->>S: create_arena (map, day/night) + delegate own Vision
Note over H: warm-up yard starts: walk, hit, shoot, blink
H->>S: 3 bots join + delegate their Visions
H->>S: delegate Arena, World, Broadcast
H->>T: init_permission รN: World=sealed, Vision[i]=player i, Arena/Broadcast=public
H->>T: request_spawn (refused unless everything is provably sealed)
O-->>T: spawn_callback(randomness) โ positions written inside the enclave
loop every move (~100 ms)
H->>T: act(...) โ rules run โ every Vision rewritten
end
T->>T: crank: tick โ border shrinks, broadcast snapshot
H->>T: reveal (World โ public) ยท settle (commit + undelegate)
H->>S: claim โ winner paid from the vault
| Threat | Defence |
|---|---|
| Read positions from the RPC | World has an EphemeralPermission with no members; the TEE returns null to everyone, host included |
| Grant yourself access to someone's Vision | init_permission ignores caller input: the program decides members (Vision โ its owner only) |
| Spawn on the public base layer to learn positions | request_spawn / spawn_fallback parse every permission account and refuse unless World and all Visions are sealed |
| Blind an opponent by omitting their Vision | every act/tick must pass all Visions in slot order |
| Leak through logs | no instruction ever logs a position |
| Spectate your own match to see everyone | spectators get a public broadcast written from snapshots ~10 s old, like an esports delay |
| Rig the spawn | spawns come from MagicBlock VRF inside the rollup (TEE-mixed entropy fallback only if the oracle stalls) |
| Primitive | Where |
|---|---|
| Ephemeral Rollup | Every step, swing, arrow and power is its own gasless transaction (~100 ms round trip) |
| Private ER (TEE) | Sealed World, per-player Vision, public Arena/Broadcast via EphemeralPermission CPIs |
| VRF | request_spawn โ spawn_callback writes spawns and chest loot straight into the sealed World |
| Crank / scheduler | schedule_ticks puts the border and broadcast on the rollup's scheduler (clients tick as a fallback) |
| Commit / undelegate | settle brings the result back to Solana; claim pays the pot from a never-delegated vault |
| Layer | Tech |
|---|---|
| Program | Rust 1.89 ยท Anchor 1.0.2 ยท ephemeral-rollups-sdk 0.17.3 (access-control, VRF, crank) ยท Agave 3.1.9 |
| Client | TypeScript ยท three.js ยท Vite ยท @magicblock-labs/ephemeral-rollups-sdk ยท @solana/web3.js ยท Anchor TS |
| Art & audio | Procedural pixel textures, voxel characters and items, WebAudio synthesis; no asset files |
| Infra | Solana devnet ยท MagicBlock devnet TEE (devnet-tee.magicblock.app) ยท Vercel |
Just play: https://nightfall-blitz.vercel.app. Press PLAY; if your burner needs devnet SOL, the game walks you through the faucet.
Run the client locally
git clone https://github.com/codeswithroh/nightfall && cd nightfall/app
npm install
npm run dev # http://localhost:5173, talks to the deployed devnet programFill a lobby from the terminal (bots funded from ~/.config/solana/id.json)
cd app && npm run guest -- <arena code> 3Build, test and deploy the program
# toolchain: Agave 3.1.9, Anchor 1.0.2, Rust 1.89 (rust-toolchain.toml pins it)
anchor build
cargo test --manifest-path programs/nightfall/Cargo.toml # 12 rule tests
anchor deploy --provider.cluster devnet
cd app && npm run sync-idl- 12 rule tests (
programs/nightfall/src/logic.rs): line of sight, tall grass, hearing octants, border timing, spawn spread and protection, every weapon (axe damage + cooldown, hammer knockback stopped by walls, spear reach), chest loot, every power (pearl blinks over walls, cloak hides even adjacent players until you attack, flare range), daylight sight, broadcast delay, all three maps. - Devnet end-to-end (
app/tests/e2e.ts): two players, real TEE, full lifecycle.
match live, vrf = true
guest peeks host vision โ null โ
sealed
guest peeks world โ null โ
sealed
host peeks world โ null โ
sealed (even the host)
spectator reads public arena โ ok โ
player 1 spotted player 0 through the fog at step 18
status 3 winner slot 0 kills [ 1, 0 ]
after reveal, guest reads world โ visible โ
winner received 0.02 SOL
โ
e2e complete
- Played in the browser end to end: title โ warm-up quests โ drop in โ loot โ fight โ win โ reveal โ settle โ paid, plus a second tab spectating the same match. The previews above were captured from real devnet matches.
nightfall/
โโโ programs/nightfall/src/
โ โโโ lib.rs # instructions: lobby, delegation, permissions, VRF spawn, act, tick, crank, reveal, settle, claim
โ โโโ logic.rs # pure rules: fog, hearing, weapons, powers, border, broadcast (+ tests)
โ โโโ state.rs # Arena ยท World ยท Vision ยท Broadcast ยท Registry
โ โโโ map.rs # generated by scripts/gen-map.py (3 symmetric, connectivity-checked arenas)
โโโ app/
โ โโโ src/lib/ # NightfallClient: base + TEE connections, auth tokens, reliable send/confirm
โ โโโ src/game/ # scene, voxel characters, session (HUD, prediction, spectating), warm-up yard, bots, sfx
โ โโโ tests/ # e2e.ts (devnet + TEE), guest.ts (terminal bots)
โโโ scripts/gen-map.py
โโโ docs/media/ # README previews
- Session keys + Phantom/Backpack for real-wallet play (burner stays as the instant option)
- Server-side bots so matches keep going if the host closes their tab
- Ranked seasons with an onchain leaderboard (Magic Actions on settle)
- Squads (2v2v2) with shared team Visions, a natural fit for permission groups
- Replays from the revealed World + move history
Built for the MagicBlock Solana Blitz hackathon on MagicBlock's Ephemeral Rollups, Private Ephemeral Rollups, VRF and crank scheduler. All art and audio are procedurally generated. The blocky look is a tribute to classic block games; the characters, items and arenas are original.
Released under the MIT License.








