LPsLux Proposals
X-Chain
LP-240

X-Chain Wire Format

Final

The Lux X-chain wire is ZAP. The Go struct IS the wire. No marshal. No codec. No encode/decode step.

Category
Core
Created
2026-06-02

Abstract

The Lux X-chain wire is ZAP. The Go struct IS the wire — there is no codec, no marshal step, no encode or decode. A BaseTx is a buffer; accessors are offset reads on that buffer; Bytes() returns the buffer.

There is no other wire on this network. No legacy. No backwards compatibility.

The struct IS the wire

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

func (t BaseTxWire) NetworkID() uint32   { return t.obj.Uint32(OffsetNetworkID) }
func (t BaseTxWire) Bytes()  []byte      { return t.msg.Bytes() }

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.

tx.Bytes() returns the underlying buffer literally. WrapXxxTx(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/xvm/ is the package; the X-chain native ZAP wire types live directly at the root of xvm (not in a zap_native/ subdir). Each Go struct embeds a *zap.Message; the buffer IS the value.

Schema files:

wire_kind.go               TxKind discriminator + parseAndCheckKind
wire_base_tx.go            BaseTxWire
wire_create_asset_tx.go    CreateAssetTxWire + InitialState primitive
wire_operation_tx.go       OperationTxWire + Operation + UTXOID primitive
wire_import_tx.go          ImportTxWire
wire_export_tx.go          ExportTxWire
wire_input_list.go         TransferableInput + InputList + SigIndicesArray
wire_output_list.go        TransferableOutput + OutputList
wire_credential_list.go    Credential + CredentialList + SignatureArray
wire_encoding.go           little-endian stride writers (putU32/putU64)
wire_txid.go               sha256-of-buffer convenience

TxKind discriminator

Every X-chain tx fixed section starts with a 1-byte TxKind at offset 0. WrapXxxTx checks the discriminator before returning a typed accessor and rejects with ErrWrongTxKind on mismatch. This closes the cross-tx-type confusion surface where, e.g., an ImportTx buffer could be Wrap'd as a BaseTx and return garbage-but-deterministic field reads.

Kind valueTx type
0Reserved
1BaseTx
2CreateAssetTx
3OperationTx
4ImportTx
5ExportTx

Primitives

Mirror of the P-chain wire. Same offsets, same strides, same view types:

PrimitiveStrideNotes
TransferableOutput96AssetID + Amount + Threshold + Locktime + OwnerAddress (single-address v3 stub)
TransferableInput88TxID + OutputIndex + AssetID + Amount + SigIndicesStart/Count
Credential16SigsStart/Count into shared SignatureArray
SigIndex4one uint32 entry in shared SigIndicesArray
Signature blob65secp256k1 sig + recovery id (fixed stride)
UTXOID36TxID + OutputIndex (OperationTx primitive)
InitialState16FxIndex + OutputsStart/Count (CreateAssetTx)
Operation88AssetID + slices into shared arrays

Per-type schema layout

BaseTx (TxKind = 1, 85-byte fixed section)

OffsetSizeField
01TxKind
14NetworkID
532BlockchainID
378OutsList
458InsList
538CredsList
618SigIndicesArr
698SigArr
778Memo

CreateAssetTx (TxKind = 2, 122-byte fixed section)

OffsetSizeField
0..84BaseTx fields
851Denomination
868Name
948Symbol
1028InitialStatesList
1108StateOutputsList

OperationTx (TxKind = 3, 109-byte fixed section)

OffsetSizeField
0..84BaseTx fields
858OpsList
938OpUTXOIDsArr
1018OpOutsArr

ImportTx (TxKind = 4, 125-byte fixed section)

OffsetSizeField
0..84BaseTx fields
8532SourceChain
1178ImportedInsList

ExportTx (TxKind = 5, 125-byte fixed section)

OffsetSizeField
0..84BaseTx fields
8532DestinationChain
1178ExportedOutsList

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()). Block envelopes inherit the P-chain wire StandardBlock layout (parent + height + time + merkle root + tx list).

Out of scope

Wires owned by other repositories:

  • luxfi/crypto/secp256k1 — secp256k1 signature wire (embedded in credentials as opaque 65-byte blobs)
  • luxfi/zap — ZAP itself (LP-0210)

Schema extensions deferred to follow-up LPs:

  • Multi-address output owners. The v3 schema carries a single OwnerAddress per output. Multi-address outputs travel through a future schema version when the BAddressList primitive ships (matches P-chain).
  • Post-quantum credentials (ML-DSA, SLH-DSA, Ed25519, secp256r1, Schnorr, BLS12381). The v3 schema treats every signature blob as fixed-65-byte (secp256k1). PQ credentials get a new schema version when their wire shape is decided.
  • Fx output types beyond secp256k1fx.TransferOutput and secp256k1fx.MintOutput. Property-fx and NFT-fx travel through future schema extensions.

External RPC surface:

  • luxd JSON-RPC API (/v1/chain/x, /v1/info, etc.) — JSON at the process boundary, not an X-chain wire surface.

Rationale

One wire. Decomplection: 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.

Same primitives as P-chain. The X-chain TransferableOutput, TransferableInput, Credential, SigIndicesArray, SignatureArray are byte-identical to the P-chain. This is intentional: one canonical spending-envelope shape across both VMs, one cross-chain primitive library, one set of schemas to audit.

No backwards compatibility

None.

The network has one X-chain wire, present in the binary from the release that ships this LP. A node presenting non-ZAP bytes for an X-chain tx is not a member of the network by definition.

No replay rules

None. There are no pre-ZAP X-chain blocks on this network to replay under a different wire.

No flags

None. The binary speaks ZAP. Byte input that fails ZAP parse is rejected. No LUXD_ENABLE_LEGACY_CODEC knob, no dispatch by magic byte, no runtime selection.

Cross-implementation byte equality

X-chain interop with non-Go consensus stubs follows the same rule as the P-chain wire and LP-0700: every reference implementation reads the schema definitions in ~/work/lux/node/vms/xvm/wire_*.go as the single source of truth, and CI gates byte-equality before any release.

Implementation

Reference implementation lives in ~/work/lux/node/vms/xvm/wire_*.go. The ~/work/lux/codec/linearcodec package is absent from the X-chain hot path — codec.Codec{Marshal, Unmarshal} is not called from X-chain code.

Test cases

TestBaseTx_RoundTrip                    build → Bytes() → Parse → fields equal
TestBaseTx_RoundTrip_Empty              all-empty (Outs=Ins=Creds=Memo=nil)
TestCreateAssetTx_RoundTrip             Name + Symbol + Denomination + InitialState
TestImportTx_RoundTrip                  SourceChain + shared SigIndicesArr
TestExportTx_RoundTrip                  DestinationChain + ExportedOuts
TestOperationTx_RoundTrip               Operation with shared OpUTXOIDs + OpOuts
TestBytes_IsUnderlyingBuffer            Bytes() returns msg buffer, no copy
TestWrap_RefusesNonZAP                  random bytes reject at Parse
TestWrap_RefusesCrossTypeConfusion      BaseTx buffer ≠ CreateAssetTx
TestPeekTxKind                          dispatcher helper reads kind for every type
TestParse_RefusesV1Header               legacy v1-header buffers rejected

Lives in ~/work/lux/node/vms/xvm/wire_test.go.

Reference implementation

~/work/lux/node/vms/xvm/wire_*.go — lands in the luxd release carrying this LP.

Cross-references

  • LP-0210 — ZAP
  • LP-1010 — P-chain wire (sibling)
  • LP-0700 — Consensus wire (sibling)

Appendix A: Benchmark results (informative)

Measured impact, Apple M1 Max, Go 1.24, native ZAP-native X-chain tx types (Parse only; Build is one-time per-proposer and dwarfed by the L1 finality budget):

Tx Typens/opallocs/opbytes/op
BaseTx25.17124
CreateAssetTx29.71124
ImportTx24.99124
ExportTx26.13124
OperationTx95.14124

Geometric mean Parse: ~32 ns/op, 1 alloc, 24 B. Parse is the per-validator-per-block hot path.

Reproduce: cd ~/work/lux/node/vms/xvm && GOWORK=off go test -bench=BenchmarkParse_ -benchmem -benchtime=1s

CC0.