← Devlog
Contracts

The staking module is just another smart contract

Entry #03 · 2026-01-22 · Devlog

Entry #03

I finished Phase 2 of ValdiumChain last week. Smart contracts, deterministic VM, event receipts, the works. Big milestone. Felt good. I took a walk. Ate a sandwich. Came back and started Phase 3.

Phase 3 is BFT consensus — real multi-validator block production with voting rounds and quorums and slashing. Step one in that sequence, which I called 3.1 in my roadmap, is building a validator registry: a place the chain can look up "who are the validators right now, what are their pubkeys, how much stake do they have?"

Normally this is a core-protocol concern. You write a "staking module" in the node codebase. It has its own data structures, its own transaction types, its own RPC endpoints. Cosmos SDK has an entire x/staking module — thousands of lines of Go. Ethereum's beacon chain has a dedicated state subtree just for validators. It's a big, important, special thing.

I thought about it for maybe 20 minutes and then I wrote the staking module as... a smart contract. Sitting at a reserved address, 0x0000000000000000000000000000000000000001, that you call with bond(pubKey, amount) the same way you'd call transfer(to, amount) on an ERC-20.

And genuinely, literally, every single piece of existing infrastructure just worked for it on the first try.

the reserved address pattern

The idea: deploy a system contract at a known address during genesis. The protocol wires it up automatically. Users interact with it through regular contract calls. The chain itself treats it as a special read source when it needs to know things like "who is the current validator set?"

This isn't new. Ethereum has "precompiles" at low addresses. Cosmos has "module accounts" for staking. The pattern is well-established. But I don't think I fully appreciated how POWERFUL it was until I actually did it.

Here is the entire list of things I had to write to add validator bonding and unbonding to the chain:

  1. A JavaScript file with init, bond(pubKey, amount), unbond(amount), getValidators() methods. About 100 lines.
  2. A helper that deploys the contract at genesis to the reserved address. About 50 lines.
  3. A method on the node class that runs a read-only VM call against getValidators(). About 15 lines.
  4. An RPC endpoint at GET /validators. About 10 lines.
  5. Three CLI commands: validators list, validators bond, validators unbond. Maybe 80 lines total.

Total: about 250 lines of net new code. For an entire validator registry module, from "nothing" to "Alice just bonded 1,000 VLD and you can see her in the set."

the "everything just worked" moment

Here is the part that made me grin out loud, actually-out-loud, at 11pm on a Thursday. Because the staking module is a regular contract, all of this worked automatically, with zero extra code:

Event emission. The contract calls emit('Bond', { validator, amount, totalStake }). That event lands in the block receipt. You can curl /receipts/:txhash and see it rendered as JSON. Nothing was special-cased.

Cross-node determinism. A replica running the HTTP sync loop pulls the block containing the bond call, re-runs the VM against its own local state, verifies the receiptsRoot field. All the Phase 2 determinism machinery just fires.

The browser explorer. Opening the local explorer in a browser, you see the bond transaction with its CALL badge, the decoded method name and arguments inline, the Bond event rendered underneath. I did not touch a single line of the explorer code for any of this. It just showed up.

The CLI flow. valdium call <contract> bond --from alice --args [...] already existed from Phase 2. I just hardcoded the reserved address and renamed the command to valdium validators bond.

Gas metering. Bonding charges gas like any other call. Priced automatically by number of storage writes and event emissions.

I set up the contract, ran valdium validators list against a fresh node. It showed the faucet as validator #1, bonded at block 0 with 100,000 VLD. I created an account called alice, funded her from the faucet, ran valdium validators bond --from alice --amount 1000. Waited 3 seconds. Ran valdium validators list again. Two validators. The second one was Alice.

That's it. About 20 minutes from "let me think about this" to "Alice is on the validator set, observable from the browser explorer, persisted to disk across restarts, replicating to the replica node, emitting events in block receipts."

why this matters (the actual lesson)

There's a trap in systems design where you build special machinery for special things. The staking module is "important," so it deserves its own protocol mechanism. The governance module is "important," so it deserves its own transaction type. Before you know it, you've built ten subsystems that each have their own way of reading and writing state. Everyone who wants to understand the chain has to learn ten different patterns.

What you actually want is a small set of extremely general primitives, and then you compose them. If your smart contract VM is good enough, the staking module IS a smart contract. The governance module IS a smart contract. The treasury module IS a smart contract. Each one is independently deployable, independently auditable, replaceable via a governance vote.

The "core protocol" is just: the VM, the state store, the block production loop, the tx format. That's it. Everything else is code that users could technically write themselves.

This is not a new insight. Unix had it. Pipes and processes. But applying it to blockchain infrastructure — treating the VM as the one extensible primitive and everything else as a contract — still feels way more radical than it should, because the existing ecosystem has so much special-cased protocol-level machinery that people forget it's optional.

— dev team

« Previous

Our blockchain runs on hardened JavaScript — and we're never going back

Next »

More entries →

New entries weekly

Don't miss the next entry.

Join the launch list and we'll send you a note whenever there's a new devlog entry, a research drop, or a real milestone.

Join the launch list Read the thesis →
© 2026 Valdium. All rights reserved.
PrivacyTerms