Boy Maas (bitgnosys)
┌─posts/2024-08-15-jamzig-a-jam-client-in-zig

JamZig⚡, a JAM client in Zig

Why Zig, what Milestone 1 meant, what is next

The posts on this site stop around 2015. A lot happened since. The biggest thing on my desk today is JamZig⚡, a JAM client written in Zig. I am the sole developer. It was the first implementation to pass Milestone 1 in the systems-language category, and after the M1 interview I am the JAM Prize M1 candidate for it. Twenty-two teams entered the prize. JamZig⚡ is the only Zig implementation among them.

Why a JAM client

JAM, the Join-Accumulate Machine, is the protocol Gavin Wood designed as the successor to the Polkadot relay chain. The Web3 Foundation runs a prize for independent implementations, split into tiers by language category. The point of the prize is not one winner. It is many clients, in many languages, from people who share neither a codebase nor an employer. When they all agree on every state transition, the specification is the protocol. No single codebase is, and no single company is.

Why Polkadot

Most blockchains are maintained by one company or one small circle. The protocol changes when those people say so, and everyone else has to trust them. The Polkadot Fellowship manifesto names this problem directly. It calls technical decision making one of the most pressing areas undermining decentralisation, and describes the usual outcome: an opaque power structure where social cues decide what logic node operators actually run.

The Fellowship is the answer this ecosystem chose, and it is the part I value most. It is a rules-based, ranked-membership organisation that lives on chain and is run by its own members. Members are inducted and promoted by the votes of members above them, judged on their work on node internals, consensus, cryptography and the runtime. The manifesto calls it a source of expertise and leadership over the technology that keeps the network running, and an incentivisation mechanism to keep that expertise. Members receive a monthly allowance in DOT. So the people who understand the protocol deepest are recognised, paid, and expected to keep building it. That is a team of incentivised knowledge holders, and it belongs to no single party. Its power is bounded too: whatever authority it holds is granted by, and held in check by, the wider referendum system.

Put the two together: many independent clients, and a body of fellows whose job is to hold the knowledge and carry the software forward. The technology is not held by one company. I think that is a solid foundation for the future, and I think it is beautiful. It is why I wanted JamZig⚡ to be one of the clients.

Why Zig

I have been in Rust for years and still like it. For a protocol client the appeal of Zig is that nothing is hidden. Every allocation takes an allocator you handed over yourself. No hidden control flow, no destructor running behind your back, no macro layer between you and the code. When a state transition has to match a reference byte for byte, that plainness is worth a lot. Comptime covers most of what I would use generics or code generation for elsewhere. And the language is small enough to hold in your head next to a protocol. That was the bet, and it still feels right.

The process

The specification keeps moving, so keeping up is a constant background task. The work went piece by piece. First the RISC-V virtual machine, the PVM, which runs services and their refine and accumulate logic. Then the cryptography the protocol asks for: Bandersnatch ring VRFs, Ed25519, BLS12-381, Blake2b, Keccak-256. Then Reed-Solomon erasure coding and the Merkle structures for availability and state. Then block authoring, validation, and the state transition function, checked against the official test vectors.

Milestone 1 of the prize is about conformance. The state transition function has to match the reference implementation under fuzzing: ten runs of one hundred thousand steps each, no divergence. Passing it is less a finish line than a change of state. Before it, every bug could be anywhere. After it, the core of the client is known to agree with everyone else, and work can move outward from there.

What is next

The prize has further milestones past conformance, and those are the road ahead. Conformance releases and test exports are published in the org, so other implementations can check themselves against the same runs.

The project lives at jamzig.dev, the code at github.com/jamzig, and the running commentary on X at @jamzig_dev. If you are building a JAM client in another language, say hello.

j/k scrollh/l prev/nextq backgg/G ends