How it works
Two brains. The whole connectome runs on a server in the published whole-brain model, embodied in a world, and is anchored to BNB Smart Chain by hashes and fed by burns. A 155-neuron core runs entirely inside a contract. This page covers both.
Part 1 · The whole brain
The model
All 139,248 neurons of FlyWire release 783 and the 2,700,429 connections with at least five synapses (34.2 M synapses in total), as leaky integrate-and-fire units with the parameters of Shiu et al. 2024 (Nature 634:210), the model every whole-brain demo of the last year uses: resting and reset potential −52 mV, threshold −45 mV, membrane time constant 20 ms, synaptic time constant 5 ms, refractory period 2.2 ms, synaptic delay 1.8 ms, and 0.275 mV of drive per synapse, negative when the presynaptic neuron is predicted GABAergic or glutamatergic. Time step 0.1 ms. Sensory neurons are driven as Poisson spike sources.
The kernel is event-driven and compiled (Numba): only neurons that spike touch their outgoing synapses. On 16 CPU cores the whole brain runs at 1.0–1.2× real time. The random stream is hashed from the step number and the neuron index, so a run is reproducible bit for bit from any snapshot.
Senses
| Sense | Real neurons driven | Driven by |
|---|---|---|
| Smell | ORNs of the fruit-responsive glomeruli DM1, DM4, VA2, DM2, VM2, DP1m (Or42b, Or59b, Or92a, Or22a, Or43b …), split by antenna; all other ORNs at 2 Hz | Gaussian odor plumes of the food items (σ 30 body lengths). Bilateral contrast is sharpened before the antennae (gain 8, clipped) because a smooth plume is far gentler than the filaments and head-casting a real fly uses. |
| Sight | R1–R6 photoreceptors, 8,452 cells, by eye | Uniform dim light (3 Hz). A lamp gradient is implemented but off for now: it competes with the odor for steering. |
| Looming | LC4 (104) and LPLC2 (210) visual projection neurons, by side | A predator approaching from an edge: LC4 by angular expansion rate, LPLC2 by angular size (Ache et al. 2019). |
| Taste | 213 labellar gustatory neurons | 80 Hz while standing on food. |
Motor
- Turning. DNa02 and DNa01, left minus right, plus the 26-per-side DNa descending population. DNa02 activation drives an ipsilateral turn (Rayshubskiy et al. 2025); turning is distributed across many DNs (Braun et al. 2024). Each neuron's rate is compared to its own slowly adapting baseline (τ 8 s), because the reconstruction has strong fixed left–right asymmetries; rates are integrated over 300 ms.
- Walking. Speed follows the surge-and-cast program measured in walking flies by Álvarez-Salvado et al. 2018: rising odor → surge (4.5 body lengths/s, straight), falling odor → cast (slow, sustained turning in the direction the DNs favour), otherwise walk at 3. DNp09 adds forward drive; MDN subtracts (backward walking).
- Jumping. A spike in DNp01, the giant fiber, is an escape jump of 12 body lengths away from the predator.
Metabolism and the chain
One simulated second costs one second of energy. Eating restores it. Every ten minutes the server hashes the complete brain state, saves the snapshot, and calls FlyWorld.checkpoint() on BNB Smart Chain with the hash, position, energy and spike count. Food exists only through FlyWorld.placeFood(): the server reads the event and puts the food into the arena. At zero energy the server reports the death with a final hash; resurrect() burns $FLY and the same brain is restored from that snapshot. To verify a checkpoint, download its snapshot, run brain/world.py with the same food placements, and compare the next checkpoint's hash.
Part 2 · The on-chain core
Integer leaky-integrate-and-fire neurons, synchronous spikes, deterministic noise, packed storage. Everything the EVM can do exactly, and nothing it cannot.
The neuron model
Each of the 155 neurons has a membrane potential v (an int16 in storage, int32 while computing). Every simulation step, for every neuron:
v -= v * LEAK / 1024 // leak toward 0
v += pendingInput[i] // spikes that arrived last step
v += noise(step, i) * NOISE / 128 // deterministic background noise
v += bias[i] * G_BIAS // the engram
if (stimulus active) v += stimI[i] // injected current
if (v < V_MIN) v = V_MIN
if (v >= THRESH) { v = RESET; spike } // fire
Spikes fired at step t arrive at their targets at t + 1: for every synapse of a spiking neuron, pendingInput[post] += weight × gain[preType] / 16. Weight is the FlyWire synapse count between the two cells (clipped to 255). Gain is one signed number per presynaptic cell type, negative for Δ7, which FlyWire predicts to be glutamatergic and which is inhibitory in this circuit.
The same recipe as every whole-brain demo (Shiu et al. 2024: leaky integrate-and-fire, weight proportional to synapse count, sign from neurotransmitter), reduced to integers so the EVM computes it exactly.
Parameters of the live fly (v2)
| Parameter | Value | Meaning |
|---|---|---|
| leak | 69/1024 | fraction of potential lost per step |
| thresh / reset / vMin | 1000 / -200 / -4000 | spike threshold, post-spike potential, floor |
| gains [EPG, EPGt, PEG, PEN_a, PEN_b, Δ7] | [130, 28, 447, 56, 40, -372] | synaptic gain per presynaptic type |
| noise | 67 | amplitude of keccak-derived background noise |
| stimGain / stimTTL | 161 / 64 | current per unit stimulus strength; steps a stimulus lasts |
| gBias | 4 | engram gain |
| walkThreshold | 100 | minimum bump strength per step to walk |
| maxSteps | 64 | max steps per tick |
These were found by a search over 12,000 candidates scored on four trajectories: does a cue create a bump at the right wedge, does the bump persist for 128 free steps, does left PEN drive rotate it, does it survive, does a Δ7 shock collapse it. The calibration script and its report are in sim/.
Noise without an oracle
Real neurons are noisy. A contract must be deterministic. So noise is keccak256(stepNumber), re-hashed every 32 neurons, one signed byte per neuron. No block hash, no timestamp. Anyone can replay the brain's entire life from its events and get the same bits.
The engram
At the end of every tick, a neuron that fired in at least one eighth of the steps gains one unit of bias; a neuron that never fired loses one. Bias is bounded at ±24 and multiplied by gBias into the membrane potential. It is slow, permanent, and survives death. It is the fly's memory of its habits.
Heading and walking
Each EPG spike contributes a unit vector at its wedge's angle. The sum over a tick is the population vector (headX, headY). If its magnitude exceeds walkThreshold × steps, the fly moves STRIDE/256 cells per step in that direction. The wedge with the most spikes increments the heading histogram.
Storage layout
- Circuit table: one SSTORE2 data contract (bytecode, 15,065 bytes): version, N, S, cell types, wedges, hemisphere sides, CSR offsets, (post, weight) synapse pairs, and 155 FlyWire root IDs as uint64. keccak256 is an immutable in FlyBrain.
- Membrane potentials: 16 × int16 per word (10 words). Pending input: 8 × int32 per word (20 words). Engram: 32 × int8 per word (5 words). Heading histogram: 16 × uint16 in one word.
- Lineage: dynamic array of structs. Caretakers: mapping address → (fed, ticks, stimuli).
Gas
The inner loop is hand-written Yul. Measured on the live circuit: about 25k gas per step for the 155 neurons, plus roughly 70 gas per synapse event. A 32-step tick with an active bump costs 4.4–7M gas; a strong turn stimulus (many PEN and EPG spikes) up to 12M. BSC's 0.05 gwei makes that 0.0002–0.0006 BNB per tick.
Determinism, tested
test/Differential.t.sol deploys the contract in Foundry, replays the exact transactions sent to the v1 mainnet fly, and asserts the spike counts, heading vectors and positions recorded in the mainnet events. The Python and TypeScript simulators pass the same replay.