mirror of
https://github.com/luxfi/chains.git
synced 2026-09-24 00:26:00 +00:00
Wave 3B of codec final rip (#101). bridgevm/codec.go was a 4-call singleton registering 3 types (Block, BridgeRequest, Genesis) — the Block + BridgeRequest pair persists on-disk via db.Put and ships over the wire via ParseBlock, so json's allocation cost and lack of stable field ordering are unacceptable. Hand-rolled binary mirrors zkvm/ (Wave 3A) for the canonical one-and-only-one way. Genesis was registered but never marshaled by Codec (vm.go uses json.Unmarshal on vmInit.Genesis), so it's dropped from the codec surface entirely — no replacement needed. Wire format (big-endian, length-prefixed): Block = parentID(32) | height(8) | timestamp(8) | nReqs(4) BridgeRequest* | nSigs(4) { nodeID(20) sig(len4|bytes) }* (sorted by NodeID) BridgeRequest = id(32) | srcChain(len4|str) | dstChain(len4|str) | asset(32) | amount(8) | recipient(len4|bytes) | sourceTxID(32) | confirmations(4) | status(len4|str) | nSigs(4) (len4|bytes)* | createdAtUnixNano(8) MPCSignatures (map[NodeID][]byte) is sorted by NodeID before write so encoding is deterministic across map-iteration orders — required for byte-identical output across nodes. Changes: - chains/bridgevm/codec.go: deleted singleton, replaced with package-level marshalBlock/unmarshalBlock + marshalBridgeRequest/unmarshalBridgeRequest following zkvm primitive-writer style (writeU32, readBytes, etc.) - chains/bridgevm/block.go: Codec.Marshal → marshalBlock in Bytes() - chains/bridgevm/vm.go: 3 sites Codec.{Marshal,Unmarshal} → marshal/unmarshalBlock - chains/bridgevm/codec_test.go: round-trip, determinism, short-buffer, trailing-bytes, nil-safety coverage Tests pass: bridgevm (0.39s, 7 new + all existing). Final grep "github.com/luxfi/codec" in bridgevm/: zero. Pre-check confirmed zero external consumers of bridgevm.Codec or bridgevm.codecVersion — only bridgevm.VMID / bridgevm.Factory used externally (node/node/vms.go). Remaining codec.go callers in chains/ module: zkvm (Wave 3A in flight).