Adds github.com/luxfi/utxo/wire package + per-fx wire.go adapters so
that luxfi/node's vms/{platformvm,xvm}/txs/codec.go can be deleted.
wire/ package mirrors luxfi/node/vms/wire — every fxs primitive carries
a (TypeKind, ShapeKind) discriminator pair on its wire envelope, then
a ZAP message describing its fields. Decomposes the legacy
codec.Manager slot map (which braided "fx family" and "primitive shape"
into a single dense uint32 slot id) into two orthogonal 1-byte tags.
PQ-specific schemas (pq_output_owners, pq_transfer_output,
pq_mint_output) handle the mldsafx/slhdsafx case where addresses are
full PQ pubkeys (1312-2592 bytes) rather than 20-byte hashed ShortIDs.
The wire layer is stride-agnostic — the per-fx wire.go resolves
SecurityLevel → pubkey stride before parsing.
Per-fx wire.go adapters provide (value T).Bytes() []byte (Go type →
wire envelope) and Wrap*(b []byte) (*T, error) (wire envelope → Go
type). The Initialize(vm)/codec.Manager.RegisterType chain stays in
place pending downstream coordination; this commit gets the wire/
package + adapters in so consumer agents (platformvm/warp,
platformvm/state, xvm) can pin a SHA and start their migrations.
UTXO.WireBytes() builds the outer envelope by calling the polymorphic
Out's Bytes() (any fxs primitive implementing wireSerializable).
WrapUTXOBytes(b) parses the outer envelope; the inner output is
dispatched by the caller via OutputDiscriminator() → fx-package
WrapTransferOutput / WrapMintOutput / WrapAttestationOutput.
Tests: 35 round-trip tests across 9 packages. go vet clean. go test
-race clean. gofmt clean.
Activation: 2025-12-25T16:20:00-08:00 (unix 1766708400). No
backwards compat — pre-activation legacy codec blobs are a
protocol-violation reject after activation.
9.2 KiB
utxo ZAP-keystone migration
Activation
2025-12-25T16:20:00-08:00 (unix 1766708400). New final Lux network — predates every block. No backwards compat, no env-var gate, no codec shim.
Goal
Replace github.com/luxfi/codec-based serialization with ZAP-native wire
schemas so that luxfi/node's vms/platformvm/txs/codec.go and
vms/xvm/txs/codec.go can be deleted. The fxs' Initialize(vm) registration
with vm.CodecRegistry() is the last codec.Manager dependency in the fxs
plugin system; once we provide a static ZAP schema per primitive, the
registration is dead code.
Audit — current codec dependencies
Module-level
github.com/luxfi/utxo go.mod requires github.com/luxfi/codec v1.1.4.
Consumed transitively by github.com/luxfi/vm for verify.State.
Files importing luxfi/codec
Root package (luxfi/utxo):
api.go—codec.Manager/codec.Marshalfor JSON UTXO responsesatomic_utxos.go—codec.Managerfor cross-chain export/importflow_checker.go—codec.Managerpassed through to verifytransferables.go—codec.ManagerinSortTransferableOutputs,IsSortedTransferableOutputs,VerifyTxutxo_state.go—codec.Manager.{Marshal,Unmarshal}for disk encoding, references the package-levelcodecVersionconstant
Per-fx (secp256k1fx, mldsafx, slhdsafx, ed25519fx, secp256r1fx,
schnorrfx, bls12381fx):
vm.go—codec.Registryon theVMinterface (the test surface for the codec.Manager passed in by the host VM)fx.go—Initialize(vm)callsvm.CodecRegistry().RegisterType(...)for every primitive type the fx owns. Tests + benchmarks construct alinearcodec.NewDefault()to satisfy the registration call.
External consumers — 204 Go files in luxfi/node import
github.com/luxfi/utxo, of which 116 reference the polymorphic typed Go
fields directly (*secp256k1fx.TransferOutput, etc.). The migration
strategy below avoids cascading into all 116.
UTXO struct
The polymorphic field is UTXO.Out verify.State (where verify.State is
an interface in github.com/luxfi/vm/components/verify). It is set to a
concrete type from one of the fx packages: *secp256k1fx.TransferOutput,
*secp256k1fx.MintOutput, *bls12381fx.AttestationOutput, etc.
fx packages
Each fx has:
transfer_output.go/transfer_input.go— value-bearing primitivesmint_output.go/mint_operation.go— mint authority primitivescredential.go— signature containeroutput_owners.go— owner group (threshold + addrs)
bls12381fx is attestation-only (no transfer/mint); it has
AttestationOutput, AttestationInput, Credential. nftfx and
propertyfx are operation-only (no value primitives).
Strategy — Option 2 chosen
Option 1 (UTXO.Out → []byte envelope, every consumer Wrap*Output on
read) cascades through ~116 consumer files in luxfi/node alone, with
more in luxfi/wallet / luxfi/cli / luxfi/genesis. That is too
broad an edit set for a single landing.
Option 2 (dual representation) is the chosen path:
- Keep the typed Go field for in-memory consumers (no breakage of the 116 files).
- Add a new
github.com/luxfi/utxo/wirepackage that provides ZAP-native wire schemas + zero-copy accessors mirroringgithub.com/luxfi/node/vms/wire. - Per-fx, add
wire_*.gofiles exposing(value T).Bytes() []byte(Go type → wire envelope) andWrap*(b []byte) (T, error)(wire envelope → Go type). The Go type is the in-memory representation; the wire envelope is the on-wire representation. Marshal/Unmarshal go through these. - Drop the
Initialize(vm)codec.Manager registration. The wire schema is static at compile time — there is nothing to register. - Wire over the
codec.Managercall sites at the root package (e.g.utxo_state.go,transferables.go) to use the newwire.UTXOetc. directly. - Delete the
codec.Registryfield from each fx'sVMinterface (it is used only byInitialize).
The hard cut is that the Initialize(vm) chain is gone — the fxs are
configured statically, not via a registration callback. The host VM
gives the fx a Logger() and a Clock() (the only other VM methods);
no codec on the wire.
Files created
github.com/luxfi/utxo/wire/:
discriminator.go— TypeKind + ShapeKind constants, envelope prefix read/write helpersutxo.go— UTXO wire schematransfer_output.go/transfer_input.go— cross-fx classical schemasmint_output.go/mint_operation.go— cross-fx schemascredential.go— cross-fx schema (TypeKind names fx, supports pubkey-recoverable and pubkey-carrying credentials)output_owners.go— cross-fx owner schema (20-byte ShortID addresses)pchain_owner.go— P-chain warp owner subset of OutputOwnersattestation.go— AttestationOutput + AttestationInput for bls12381fxpq_output_owners.go— PQ-fx OutputOwners with variable-length pubkeys (mldsafx, slhdsafx — addresses are full PQ pubkeys, not 20-byte hashes)pq_transfer_output.go— PQ-fx TransferOutputpq_mint_output.go— PQ-fx MintOutputsigned_tx.go— outer envelope (unsigned bytes + credentials)sign.go—SignSecp256k1(unsignedBytes, signers)for the classical fx signing entry pointwire_test.go/pq_test.go/sign_test.go— round-trip tests
Per-fx wire.go files providing Bytes() + Wrap* adapters between
the in-memory Go type and the wire envelope. The schemas use the same
TypeKind discriminator from wire/discriminator.go so a TransferOutput
parsed off the wire knows its owning fx without a dispatch table.
Files created per fx:
secp256k1fx/wire.go+secp256k1fx/wire_test.goed25519fx/wire.go+ed25519fx/wire_test.gosecp256r1fx/wire.go+secp256r1fx/wire_test.goschnorrfx/wire.go+schnorrfx/wire_test.gomldsafx/wire.go+mldsafx/wire_test.goslhdsafx/wire.go+slhdsafx/wire_test.gobls12381fx/wire.go+bls12381fx/wire_test.go
Root package:
utxo_wire.go—UTXO.WireBytes()builds the outer envelope by calling the polymorphicOut'sBytes();WrapUTXOBytes(b)parses the outer envelope and returns awire.UTXOaccessor. The inner output envelope must be parsed by the caller through the appropriate fx package'sWrapTransferOutput/WrapMintOutput/WrapAttestationOutput— the root package cannot import the fx packages (would be a cycle).utxo_wire_test.go— round-trip test exercising the full UTXO → wire → fx parse → equality dispatch.
Files NOT yet deleted (next cut)
The following still reference luxfi/codec and remain pending the
downstream agents' coordinated cut:
utxo_state.go—utxoState.codec codec.Managerfor disk encoding. Replace withWireBytes()/WrapUTXOBytesafter the consumer agents' state migrations land.atomic_utxos.go—atomicUTXOManager.codec codec.Managerfor cross-chain UTXO export/import.transferables.go—codec.ManagerinSortTransferableOutputs,IsSortedTransferableOutputs,VerifyTx.flow_checker.go—codec.Managerpassed through to verify.api.go— usescodec.Uint32/codec.Uint64(JSON-quote wrapper types, NOTcodec.Manager); these are orthogonal to the codec rip and can stay.- Per-fx
vm.go—codec.Registryon theVMinterface; used only by the per-fxInitialize(vm)to callvm.CodecRegistry().RegisterType(...). Once consumers stop callingInitialize, both go away. - Per-fx
fx.goInitialize(vm)— callsvm.CodecRegistry().RegisterTypefor every primitive. Drop after consumers stop calling Initialize.
These are the second-cut targets; this first commit gets the wire/ package + per-fx adapters in so the downstream agents can pin a SHA and start their migrations.
Coordination
Three parallel agents are landing:
platformvm/warpZAP migration — consumes ourwire.OutputOwnersandwire.PChainOwner.platformvm/stateZAP migration — consumes ourwire.UTXOfor the state's persisted UTXOs.xvmZAP migration — consumes ourwire.UTXOfor the X-chain state + every fxswire.*Output/wire.*Input/wire.Credentialschema.
When they land they pin a SHA from this branch. They do not modify the
typed Go field paths in luxfi/utxo — those remain for the 116 callers
that still hold typed references.
Test plan
cd ~/work/lux/utxo && GOWORK=off go build ./...cd ~/work/lux/utxo && GOWORK=off go test ./... -count=1 -timeout=10m- Round-trip test per fx primitive + per cross-fx schema (in
wire/wire_test.go+ per-fxwire_test.go). - Verify
luxfi/codecis gone from go.mod after the final cleanup (after consumers have migrated; for the first cut we keep the dep alive sinceutxo_state.gostill goes through the legacy codec pending downstream coordination).
Commit + tag
First cut commits the wire/ package + per-fx wire_*.go adapters; the
Initialize(vm) chain stays in place pending the downstream agents'
coordinated cut. Subsequent cuts will remove the codec.Manager
references in utxo_state.go, transferables.go, atomic_utxos.go
once the agents have switched their state to call wire.NewUTXO /
wire.WrapUTXO.
The commit SHA from this first cut is what the downstream agents pin.