Files
zeekay ca4572759c Every Rust chain reads and writes the wire a schema states
The P-chain, the Z-chain and the F-chain join the Q and X chains: what each
puts on a wire is stated once in chains/schema, and zapgen writes the
accessors. Five schemas, five emitted modules, and one runtime under all of
them — chains/rust/zap, also emitted. The five hand-written copies of that
runtime are gone: 4,056 lines that were the same reader written out five
times, three of them byte-identical and two variants nobody had reconciled.

WHAT THE VARIANTS DISAGREED ABOUT, and it was not cosmetic. Every hand copy
defaulted `Builder::new` to wire version 2; the emitted runtime keeps `new`
at version 1 and names `new_v2` for the other. So the swap silently moved
byte 4 of every message the P-chain wrote outside a generated builder, and
the warp differential caught it against the bytes Go wrote — a one-byte
divergence in a header nobody reads by hand. Every P-chain writer now says
new_v2, which is what it always wrote.

THE SCHEMA WAS PROVED BEFORE THE TABLE WAS DELETED. A test asserted every
offset and every size in pchain.zap against the constant the chain had been
using — 27 structs, every field — and it passed before a line was removed.
What replaces it now compares schema to schema: every kind's envelope is
Base's envelope, checked field by field against the emitted constants, so
`read_envelope` reading any transaction through Base's accessors is a thing
that is checked rather than a convention to remember.

THE BYTES DID NOT MOVE, and every chain says so against the corpus the Go
chain generated: 68 P transactions and 4 P blocks, 19 X transactions and 6 X
blocks, 12 Q blocks, 22 Z blocks, 43 F transactions, each re-encoded from the
values that were read and compared to Go's hex. Those are every vector the
corpus expects to parse; the rest are the deliberately malformed ones, and
they are still refused. `make chains` is 725 vectors, 4 implementations, 13
evaluators, AGREED on every compared field, exit 0, nothing under NOT
ANSWERED.

Two fields of one name and a struct named but not declared are now refused by
zapgen's front end, once, for every backend. The P-chain hit the first:
an envelope's owner-address POOL and the owner group a transaction hands
ownership TO were both called OwnerAddrs, and the emitted Rust had the same
struct member twice. They are named apart now — NewOwner on a chain
ownership transfer, NetworkOwner on a network being created.

WHAT IS STILL HAND-WRITTEN, and it is the P-chain only: warp.rs and
warpmsg.rs (the warp envelope and its payloads), genesis.rs, persist.rs (the
disk state), and components.rs (the fx primitives it spends). Those are real
remaining offsets and they are next.

The fx primitives belong in neither chain's schema — the X-chain makes them
and the P-chain spends them, so xchain.zap and a P-chain statement of the
same TransferOutput would be two statements of one format. Lifting them into
a shared fx.zap needs an import across schemas that zapgen does not have; the
attempt is what found the undeclared-struct hole, and the refusal now says so
at the schema rather than in emitted Rust.

378 platformvm, 290 xvm, 110 quantumvm, 150 zkvm and 97 fhevm unit tests, the
five corpus byte tests, the golden vectors and the differentials all pass.
2026-09-06 13:54:26 -07:00

43 lines
1.2 KiB
Plaintext

# SPDX-License-Identifier: BSD-3-Clause-Eco
# The F-chain wire.
#
# The offsets are the format. They are stated here once and every language's
# accessors come out of this file, so a transaction built in Rust is the bytes
# a Go peer builds.
#
# A transaction is TWO objects, one after the other, because it is two things.
# The first is the signing preimage — what the payer's signature covers, and
# therefore what can never carry it. The second is the authorization over
# those bytes. Both are self-delimiting, so the split is found by reading the
# first one's length rather than by re-encoding anything.
package fchain
type id32 = bytes_fixed[32]
type addr = bytes_fixed[20]
# The semantic fields, and nothing about who authorized them.
struct Tx {
Type u8 @0
Payer addr @1
Subject id32 @21
Gas u64 @53
Nonce u64 @61
Scheme bytes @69
Payload bytes @77
}
# What rides behind the preimage: the authorization and the signature over it.
struct Auth {
Auth bytes @0
Signature bytes @8
}
struct Block {
Parent id32 @0
Height u64 @32
Time i64 @40
TxLens list<u32> @48
TxBlob bytes @56
}