The ZAP Stack
A decomplected blockchain architecture where the ZAP buffer IS the wire format AND the in-memory representation AND the on-disk record. One byte stream from network to mempool to state to ZapDB to backup — no codec, no marshal, no encode/decode step.
Abstract
The ZAP Stack is a decomplected blockchain architecture. A
transaction is a ZAP buffer when it crosses the wire; it is the same
ZAP buffer when it sits in the mempool; it is the same ZAP buffer when
it lands in state; it is the same ZAP buffer when ZapDB streams it to
an age-encrypted snapshot. One byte stream. No codec.Manager runtime
registry. No reflection. No Marshal. No Unmarshal. No Encode. No
Decode. No Serialize. The buffer is the value.
Each layer of the stack does one job. ZAP frames the bytes. ZapDB
stores the bytes. Schemas describe the offsets. sha256.Sum256(buf)
yields stable identity. TupleHash256 with SP 800-185 framing yields a
cryptographic transcript. wire.SignSecp256k1 produces a signed-tx
envelope by emitting a credential window over the unsigned bytes.
Per-schema Verify() reads offset-indexed fields. Executor dispatch
keys on the TxKind byte. A block is a ZAP frame containing tx frames.
Consensus composes BLS + Pulsar + Corona + Magnetar legs as opaque
ZAP byte strings inside a QuasarCert. Each of these is a separate
concern, in a separate layer, with no braiding.
The reason this is elegant is not aesthetic. It is operational: the cost of every braided concern in a reflection-codec stack (re-marshalling between mempool and state, re-encoding for snapshot, parsing on every consensus-message hop, registering codec versions at runtime) is paid every block. Removing the braids removes the cost. Measured wins span 3× to 13× per operation. Composed across a running validator, the wins compound.
The 10-layer model
| # | Layer | One job | Implementation |
|---|---|---|---|
| 0 | ZAP frame | binary wire envelope (magic + version + object) | luxfi/zap (LP-0210) |
| 1 | ZapDB | LSM KV consuming ZAP bytes; incremental snapshots; age-encrypted backups | luxfi/zapdb (Badger fork, !grpc build tag, pb_zap.go native encoders) |
| 2 | Schemas | TypeKind + ShapeKind discriminator + offset map per type | pkg/wire/zap/schemas.go per repo; registry in LP-0230 |
| 3 | Identity | sha256.Sum256(buf) for stable IDs | callsites, no central impl |
| 4 | Transcript | TupleHash256 / cSHAKE256 with SP 800-185 framing — cryptographic injectivity over typed fields | consensus/protocol/quasar/round_digest.go, qblock.go::TranscriptHash |
| 5 | Signature | wire.SignSecp256k1(unsignedBytes, signers) → ZAP SignedTx{unsignedBytes, creds} | luxfi/utxo/wire/sign.go |
| 6 | Validator | per-schema Verify() reads offset-indexed fields, no codec dispatch | per-type validators in each VM |
| 7 | Executor | dispatch on TxKind byte (first byte of envelope); no Visit pattern; no type switch | per-chain executor with kind-byte registry |
| 8 | Block | block bytes are a ZAP frame containing a list of tx bytes (also ZAP frames); block ID = sha256(block.Bytes()) | per-chain block schema in consensus/pkg/wire/zap/qblock.go |
| 9 | Consensus | the QuasarCert (LP-0117) composes BLS + Pulsar + Corona + Magnetar legs as opaque ZAP byte strings; verify is per-leg dispatch | consensus/protocol/quasar/ |
| 10 | P2P transport | QUIC streams carrying ZAP frames; mDNS for LAN discovery; Kademlia DHT for content-addressable chunks | LP-0410 |
Each row is one job. Each row consumes the layer below and produces the layer above as a byte slice. No layer reaches across.
Decomplected concerns
Ten things a reflection-codec stack braids together, unbraided here.
1. Wire format ↔ in-memory type ↔ on-disk record
Braided: three Go structures — wire DTO, runtime struct, storage row —
with marshal/unmarshal hops between them. Every read parsed twice,
every write encoded twice. ZAP Stack: one buffer. The wire is the
struct is the record. Accessors are offset reads. Bytes() returns
the buffer. ZapDB stores the buffer as-is.
2. Signature payload ↔ transcript ↔ wire
Braided: a signed transaction had a marshal pass for the signature
payload, a separate marshal pass for the consensus transcript, and a
third marshal pass for the gossip envelope. ZAP Stack: one byte
stream feeds three orthogonal operations — sha256 for identity,
TupleHash256 over typed offsets for the consensus transcript, and
ecdsa(sha256(unsigned_bytes)) for the signature. Each operation
reads the same buffer at different offsets. No re-encoding.
3. Tx envelope ↔ kind dispatch ↔ executor visitor
Braided: the Visit pattern — tx.Visit(v UnsignedTxVisitor) —
required every executor to type-switch on Go interface assertions
inside generated code. ZAP Stack: the first byte of the unsigned
envelope is TxKind. The executor is a map[TxKind]Handler lookup.
No interface polymorphism, no generated visitors, no type switch.
Value-based dispatch on a buffer byte.
4. Block ↔ proposervm wrapper ↔ chain-VM block bytes
Braided: proposervm wrapped every chain-VM block in its own envelope with its own signature, and the wrapped bytes had to be parsed at every consensus hop. ZAP Stack: the proposer's signature is a leg of the QuasarCert (LP-0117), not a separate envelope. The block is the block. Validators verify the cert's BLS leg to authenticate the proposer.
5. Mempool ↔ chain ↔ network gossip
Braided: a transaction had three representations — gossip wire, mempool in-memory struct, chain bytes — with marshal hops between them. ZAP Stack: the same buffer that arrives over the wire goes into the mempool by reference, lands in a block by reference, and persists to ZapDB by reference. One buffer, three places.
6. Validator ↔ delegator ↔ L1-staker
Braided: three separate state tables with three separate marshalled
structures and three separate code paths for stake accounting. ZAP
Stack: one ZAP wire format with a StakerKind discriminator in the
P-Chain state schema. One table. One executor path. The kind byte
chooses the fee rules and the reward schedule.
7. P-chain ↔ X-chain ↔ EVM ↔ chains-VM primitives
Braided: each VM had its own copy of UTXO, OutputOwners,
Credential, BaseTx. ZAP Stack: luxfi/utxo/wire/ is the single
source of truth. The P-Chain wire, X-Chain wire (LP-0240), EVM internal
wire (LP-0250), and the 12 chain VMs (LP-0260) all consume the same nine
migrated fxs (secp256k1fx, nftfx, propertyfx, ed25519fx,
mldsafx, slhdsafx, secp256r1fx, pqfx, vrffx) through their
per-fx wire.go bridges.
8. Consensus transcript ↔ wire envelope
Braided: the consensus transcript was a separately marshalled
structure that had to be re-derived from the wire envelope at every
hop. ZAP Stack: the transcript function reads typed fields directly
from the ZAP buffer (consensus/pkg/wire/zap/qblock.go::TranscriptHash).
The wire is the input to the transcript. No re-derivation.
9. codec.Manager ↔ Sign ↔ Verify
Braided: codec.Manager was a runtime registry of versioned
type-codec pairs; every Sign and Verify call paid a registry lookup
and a reflective marshal. ZAP Stack: compile-time schemas declared in
pkg/wire/zap/schemas.go per repo. Sign and Verify read offsets
directly. No runtime registry. No reflection. No version negotiation
at runtime — versioning lives in the schema kind byte.
10. Genesis ↔ block ↔ state ↔ gossip
Braided: the genesis file format, the block format, the state-row
format, and the gossip format were four distinct codecs that all had
to be kept in sync. ZAP Stack: one wire codec across all of them. A
genesis is a ZAP buffer with a GenesisKind discriminator. A block
is a ZAP buffer containing a list of tx buffers. A state row is a
ZAP buffer. A gossip message is a ZAP buffer. Same parser, same
writer, same identity function.
Performance characteristics
Measured on node microbenchmarks against the reflection linearcodec
implementation. Numbers are wall-clock per operation and allocation
count from go test -bench.
| Op | Reflection codec | ZAP Stack | Win |
|---|---|---|---|
| Parse small tx | 129 ns/op, 2 allocs | 36 ns/op, 1 alloc | 3.6× |
| Parse complex tx | 1008 ns/op, 6 allocs | 75 ns/op, 1 alloc | 13.4× |
| Mempool insert | parse → struct → re-marshal | parse → buffer ref | ~5× |
| State write | unmarshal → mutate → marshal | wrap → mutate → write buffer | ~3× |
| Snapshot stream | re-encode for backup | direct buffer stream | ~10× (write-amp gone) |
| Consensus round Corona n=64 | 14 s serial-aggregate (incorrect) | 356–440 ms parallel (correct) | −97% |
These compose. A validator running consensus rounds while admitting transactions and writing state sees the per-op wins compound at every layer. The Corona row deserves a note: the serial-aggregate implementation was a bug, not a baseline; the parallel implementation is the honest comparison point. The win is real.
Why "elegant"
One wire, one identity, one transcript
Three concerns, three layers, no braiding. The wire is the byte
stream. Identity is sha256.Sum256(buf). The transcript is
TupleHash256 over typed offsets. Each is independently complete.
None reaches into the others. Adding a new transcript function does
not touch the wire. Changing the identity hash does not touch the
transcript. The layers do not know about each other.
TxKind dispatch ≠ interface polymorphism
A Visit-pattern type switch is a place — the code that names every
concrete type and dispatches on the runtime type tag. A TxKind byte
is a value — the dispatch table is map[TxKind]Handler, the handler
is selected by lookup, and the executor never names a concrete tx
type. Adding a tx kind is one entry in the registry. Removing one is
one deletion. The executor does not change.
The buffer IS the value
A place is a slot that can hold different things over time; a value is a thing that does not change. ZAP-native is values all the way down. The buffer that arrives over the wire is the same buffer in the mempool, the same buffer in the block, the same buffer in state, the same buffer in the snapshot. The identity is a function of the buffer. The transcript is a function of the buffer. The signature is over a window of the buffer. Nothing mutates. Nothing re-encodes. The buffer is the value.
Implementation status
PARTIAL. The architecture is the 10-layer model above. The following are residual migrations of legacy code paths onto that architecture, not architectural blockers.
codec.Manageris out of the tx/block/sign path. TheTx.Signcascade inplatformvmandxvmno longer routes throughcodec.Manager— the P-Chain and X-Chain transaction is the ZAP buffer (struct = wire), signed overhash(unsignedBytes). Zerocodec.Managerusages remain in node production; the reflection codec (pcodecs) is deleted and every VM's tx/block wire is native ZAP. The only residualluxfi/codecdependency is the leafcodec/wrappersbyte-packer innetwork/peer(handshake framing, not reflection) and Warp's own message codec (a separate cross-chain subsystem) — neither is the reflection tx codec, so the module stays a dependency for those two leaf uses only, not the tx/block/sign path.luxfi/p2pis still imported in 11 files. LP-0410 replaces it with QUIC + ZAP + mDNS + DHT. The replacement is in flight, not landed.service/infois blocked onluxfi/p2p's codec/jsonrpc. The info-service public API still speaks the legacy jsonrpc envelope on top ofluxfi/p2p's codec. It is replaced when LP-0410 lands.
Composition with the rest of the stack
| LP | Role |
|---|---|
| LP-0210 | ZAP wire protocol — frame format, magic byte, version byte, object discriminator. The bottom layer. |
| LP-0117 | The consensus finality message and QuorumCert the cert layer composes. |
| LP-0122 | Quasar cert composition — BLS + Pulsar + Corona + Magnetar legs as opaque ZAP byte strings. |
| LP-0230 | Schema registry — normative owner of every TypeKind / ShapeKind / precompile-slot allocation. |
| LP-0240 | X-Chain wire — BaseTx, ImportTx, ExportTx, CreateAssetTx, OperationTx. |
| LP-0250 | EVM internal wire — block and tx internal representation is ZAP; external Ethereum RLP is preserved at the RPC boundary. |
| LP-0260 | Chain VM wire — 12 VMs (mpcvm, fhevm, mvm, quantumvm, …) all consume the same wire layer. |
| LP-4805 | The pipelining and atomic-unwind contract the immutable buffer makes possible. |
| LP-0410 | ZAP P2P — the Transport.Pick() selector contract, QUIC default, mDNS LAN discovery, Kademlia DHT for content addressing. |
| LP-0420 | CXL Coherent State Pool — upgrades this LP's Layer 1 per-validator UMA buffer pool to a rack-pooled CXL Type-3 device for same-rack peers. |
| LP-0430 | RDMA over InfiniBand — cross-rack transport within a datacentre. |
| LP-0510 | Light client — samples proofs over ZapDB merkle paths; clients verify a transaction is in state without downloading the chain. |
| LP-4540 | Magnetar threshold SLH-DSA — the hash-based cert leg. |
Adjacent components that live outside this LP: luxfi/utxo's
gatekeeper (9 fxs on compile-time ZAP schemas, each exporting a per-fx
wire.go bridge), luxfi/zapdb (Badger fork with ZAP-native
pb_zap.go encoders under the !grpc build tag), the Quasar consensus
family (photon, wave, focus, horizon, ray, nova, nebula, prism,
quasar), the ZAP transport itself (luxfi/zap transport.go and
quic/), and rpcchainvm (grpc-free; VM plugin IPC speaks ZAP
transport).
Two further pieces are future work:
- State commitment. A Merkle tree directly over ZAP buffers: the hash function consumes the same buffer the storage layer stores; no re-encoding for commitment.
- Mempool gossip. QUIC streams plus delta-set reconciliation; the gossip envelope is a ZAP frame containing tx buffer references.
Copyright
Copyright and related rights waived via CC0.