LPsLux Proposals
P-Chain
LP-1010

P-Chain Wire Format

Final

The P-Chain wire is ZAP. The Go struct IS the wire — no codec, no marshal step, no encode or decode. Tx and block identity are the hash of the buffer itself.

Category
Core
Created
2026-06-02

Abstract

The Lux P-Chain wire is ZAP. The Go struct is the wire — there is no codec, no marshal step, no encode or decode. An AdvanceTimeTx is a buffer; accessors are offset reads on that buffer; Bytes() returns the buffer.

There is one P-Chain wire on the network. A node presenting non-ZAP bytes for a P-Chain tx is not a member of the network by definition.

The struct IS the wire

type AdvanceTimeTx struct {
    msg *zap.Message       // the wire buffer itself
    obj zap.Object         // typed window into msg
}

func (t AdvanceTimeTx) Time() uint64    { return t.obj.Uint64(OffsetTime) }  // offset read
func (t AdvanceTimeTx) Bytes() []byte   { return t.msg.Bytes() }             // return buffer

There is no Marshal. There is no Unmarshal. There is no Encode. There is no Decode. There is no Serialize. Parse(b) wraps b in a typed accessor — it does not copy and does not decode. Build(...) writes fields into a buffer at known offsets and the buffer is the wire bytes — there is no encoding pass over it.

This is the Cap'n-Proto / FlatBuffers invariant: wire format is the in-memory representation.

tx.Bytes() returns the underlying buffer literally. Parse(b) wraps b in a typed accessor. TxID = sha256(buffer). No re-encoding step anywhere in the hot path.

Specification

Wire schemas

~/work/lux/node/vms/platformvm/txs/zap_native/ is the package; one file per tx type. Each Go struct embeds a *zap.Message; the buffer IS the value.

Tx types in scope (P-Chain platformvm):

# proposal (no spending state)
AdvanceTimeTx
RewardValidatorTx

# spending base
BaseTx

# network + chains — one-way, composable
CreateNetworkTx          # create a network at ANY level via `parent`
                         # (Primary⇒L1, L1⇒L2, recurse; level = depth).
                         # Sovereignty is DERIVED from `validators` (>0 ⇒ own
                         # set + manager; ==0 ⇒ inherited / restaked from
                         # parent) — no `sovereign` flag (LP-1020). `manager`
                         # lives on the network so an inherited L2 can hold
                         # local admin.
CreateChainTx            # add a chain to an existing network (reuses NetworkChain)
ConvertNetworkTx         # PROMOTE an existing network: inherited→sovereign
                         # (establish own validator set + manager), re-anchor
                         # `parent` (L2→L1, L3→L1). Owner-authorized. Distinct
                         # from CreateNetworkTx: Create = ∅→Network (birth),
                         # Convert = Network→Network (mutate). Shares
                         # NetworkValidator.
TransferChainOwnershipTx
RemoveChainValidatorTx
TransformChainTx

# staking
AddValidatorTx
AddDelegatorTx
AddPermissionlessValidatorTx
AddPermissionlessDelegatorTx
AddChainValidatorTx

# L1 validator lifecycle — warp-driven
RegisterL1ValidatorTx
SetL1ValidatorWeightTx
IncreaseL1ValidatorBalanceTx
DisableL1ValidatorTx

# cross-chain
ImportTx
ExportTx

Shared value components (encoded into the tx buffer, reused across txs): NetworkValidator (nodeID + weight + balance + BLS PoP + remaining / deactivation owners) and NetworkChain (name + vmID + fxIDs + genesis). One encoder each, composed by CreateNetworkTx (genesis) and CreateChainTx (append) — a free monoid of chains, no duplication.

Not in the P-Chain set

SlashValidatorTx     — no producer and no bridge; slashing is DETECTED by
                       consensus/core/slashing but never enforced through a
                       P-Chain tx. Not in the set.
CreateAssetTx        — X-Chain (money rail, LP-5210 §2/§3). Asset creation and
OperationTx            fx operations belong on xvm, not on the staking rail.
CreateSovereignL1Tx  — folded into CreateNetworkTx: the atomic spawn (LP-1020)
                       is the `validators`+`chains`-populated form of
                       CreateNetworkTx. "Birth, already sovereign" is not a
                       distinct concept.

ConvertNetworkTx is the promote endomorphism: re-anchor to the parent and establish a validator set. Create (birth) and Convert (promote) are orthogonal and both first-class.

Element-count convention

Fixed-stride list entries store the ENTRY count, not the byte count — the shared side-array pools (owner addresses, sig indices, NodeID bytes) are sliced by [start, start+count) with per-stride bounds clamps.

Variable-length fields (Memo, Outs, Ins, Credentials, Warp messages, Evidence) use ZAP's length-prefixed nested-object protocol — still no codec step, still a buffer with offset reads.

Tx ID

TxID = sha256.Sum256(tx.Bytes())

tx.Bytes() returns the ZAP buffer. No re-canonicalization. No re-encoding. The hash domain consumes whatever the wire layer presents.

Block ID

Same shape — block bytes are the ZAP buffer for the block envelope; block ID is sha256.Sum256(block.Bytes()).

Out of scope

Wires owned by other repositories:

  • luxfi/crypto/bls — BLS signature wire (embedded in signed tx credentials as opaque bytes)
  • luxfi/zap — ZAP itself

External RPC surface:

  • luxd JSON-RPC API (/v1/chain/p, /v1/info, etc.) — JSON at the process boundary, not a P-Chain wire surface.

Rationale

One wire. The wire layer does exactly one job: present typed accessors over a byte buffer. Multiple wires would braid two unrelated concerns (which wire to read) with one job (read the bytes).

ZAP because the struct IS the wire. Every other option — protobuf, RLP, linearcodec, msgpack, hand-rolled binary — is a codec: serialize on write, deserialize on read. ZAP eliminates the step. The buffer is the value. tx.Bytes() returns it. sha256(tx.Bytes()) requires no re-encoding. That is the property no other option offers.

No flags. The binary speaks ZAP. Byte input that fails ZAP parse is rejected. There is no legacy-codec knob, no dispatch by magic byte, no runtime selection.

No multi-version anything. codec.Codec{Marshal, Unmarshal} is not called from P-Chain code, and the multi-version codec Manager does not exist. There is one wire.

Cross-implementation byte equality

P-Chain interop with non-Go implementations follows one rule: every reference implementation reads the schema definitions in ~/work/lux/node/vms/platformvm/txs/zap_native/schemas.go as the single source of truth, and CI gates byte-equality before any release.

Test cases

TestAdvanceTimeTxBuildParseFieldEquality   build → Bytes() → Parse → fields equal
TestAdvanceTimeTxBytesIsUnderlyingBuffer   Bytes() returns msg buffer, no copy
TestAdvanceTimeTxParseRefusesNonZAP        non-ZAP bytes reject at Parse
TestPChainTxIDStability                    sha256(Bytes()) byte-identical to fixture
TestCrossImpl_ByteEquality_AllTxTypes      python/cpp/c/rust ≡ Go on every tx type
TestNoLegacyCodecInBinary                  grep build symbols — no Marshal*, no
                                           linearcodec, no codec.Codec in platformvm

Round-trip coverage spans the hardest cases: multisig + stakeable outputs/inputs, the nested NetworkValidator (NodeID + BLS PoP + two owners) and NetworkChain records, sovereign-L1 vs inherited-L2 CreateNetworkTx, and signed unsigned ‖ creds.

Reference implementation

~/work/lux/node/vms/platformvm/txs/zap_native/ — native github.com/luxfi/zap, no codec, no Marshal/Unmarshal, no codec.Manager. Each tx is a *zap.Message; accessors are offset reads; Parse(b) wraps zero-copy; New*Tx(...) builds once; TxID = sha256(Bytes()).

Appendix A: Benchmark results (informative)

Measured impact, Apple M1 Max, Go 1.24, real platformvm tx types (parse only; build is one-time per-proposer and dwarfed by the L1 finality budget):

Tx TypeCodec ns/opZAP ns/opSpeedupCodec allocsZAP allocs
AdvanceTimeTx281.654.65.2×21
RewardValidatorTx317.362.45.1×31
SetL1ValidatorWeightTx423.556.27.5×31
IncreaseL1ValidatorBalanceTx382.447.98.0×31
DisableL1ValidatorTx453.166.86.8×31
BaseTx470.060.47.8×31
RegisterL1ValidatorTx1008.075.013.4×61
SlashValidatorTx690.682.78.3×41
TransferChainOwnershipTx2459.0161.515.2×41
RemoveChainValidatorTx879.6117.27.5×41

Geometric mean Parse speedup across 10 types: 8.5×. Parse is the per-validator-per-block hot path. The "Codec" column is the cost of the step that no longer exists.

Reproduce: cd ~/work/lux/node/vms/platformvm/txs/zap_native && GOWORK=off go test -bench=. -benchmem -benchtime=2s

Copyright and related rights waived via CC0.