Divi Games

Courses / The side-chain

State and state roots

All chain state is one sorted key-value map, stored in SQLite (chain.db, WAL mode). The core keys:

KeyHolds
acct/<addr>/noncethe account's next nonce
bal/<addr>/<TOKEN>a balance in base units
token/<TOKEN>token info (decimals, issuer, supply, faucet)
faucet/<addr>/<TOKEN>height of the last faucet claim
cfg/issuerswho may record course certificates
m/<module>/...a module's own data

The state root

Each block commits to the whole history of writes:

state_root = SHA256( prev_state_root || writes_digest )

writes_digest is the SHA256 of this block's writes, in key order. Genesis chains from 32 zero bytes.

This is a chained commitment, not a Merkle tree. It cannot prove a single balance on its own. What it does give you is cheapness and a check anyone can run: re-execute every block and see if you reach the same root.

Why modules must be deterministic

The root only matches on replay if every module does exactly the same thing every time. So modules may not use the clock, random number generators, floating point, or HashMap iteration order. They use ctx.height(), ctx.block_time_ms() and public randomness derived from the Divi checkpoint.

Transaction isolation

A block runs in an overlay and each transaction in a child overlay. If the action fails, the child is dropped and only the nonce bump survives.