Skip to main content

go-zenon-v1 LLM Implementation Blueprint (Go 1.26)

Audience: Starts with the acyclic package map (L0–L9) for human maintainers, followed by an 8-stage, file-by-file AI coding agent refactoring blueprint with ready-to-compile Go 1.26 crypto/mldsa and crypto/mlkem implementations, error-precedence rules, cross-client notes (zenon-rs & syrius), and Bend 2.0.40 + Lean 4.34.0 proof laws.


Ground-Truth Impact Map Across go-zenon-v1 (L0–L9)​

go-zenon-v1 enforces a strictly acyclic L0 → L9 package DAG (OWNERSHIP.tsv). Every post-quantum addition fits cleanly inside existing layers without introducing a single new external go.mod dependency for Phase 1 (ML-DSA-44, SLH-DSA-SHAKE-128s, and ML-KEM-768 all build on Go 1.26 stdlib + internal/crypto/keccak.go):

LayerPackage PathFiles Added / ModifiedResponsibility
L0internal/commonparams.goAdd PostQuantumAccountsSporkID, PostQuantumConsensusSporkID, LegacyCryptoSunsetSporkID, AccountBlockVersionV2 = 2, ABWitnessBytePlasma = 17
L1internal/cryptopq.go (new), mldsa.go (new), slhdsa.go (new), slip0010_pq.go (new)AlgID dispatch, Go 1.26 crypto/mldsa wrapper, pure-Keccak SLH-DSA-SHAKE-128s, domain-separated PQ SLIP-0010 KDF
L2internal/typesaddress.goAdd PQUserAddrByte = 0x02, PQPubKeyToAddress(algID, rawPub), era-gated IsUserAddress
L3internal/nomaccount_block.go, momentum.goZero wire changes needed; add helper methods SigAlgID() (uint8, bool)
L4internal/powplasma.goAdd stateless WitnessPlasma(block) inside GetBasePlasmaForAccountBlock when hasPQAccounts && block.Version >= 2
L5internal/chainaccount_store.go, spork_index.goAdd PrefixAccountPubKey = 0x09 (GetCachedPubKey / SetCachedPubKey) + HotStateCache pubkey slot
L6internal/vmcontracts/auth/ (new), contracts/ptlc/ptlc.go, contracts/bridge/, verifier/account_block.go, verifier/momentum.goAuthRegistryContract, Stage-2 PreverifyAccountBlock PQ dispatch, AccountStore[0x09] enforcement, wrapIfBodyTampered bounds, PTLC types 3..4, Bridge PQ Guardian quorum
L7internal/p2plibp2p/server.go, switcher/switcher.goEnable hybrid X25519MLKEM768 stream security via Go 1.26 crypto/tls / crypto/mlkem; sunset RLPx
L8internal/wallet, internal/rpckeystore.go, manager.go, api_embedded_ext.goDerive m/44'/73404'/1'/alg'/idx', sign Version = 2 blocks, expose embedded.auth.* JSON-RPC methods

Detailed AI / LLM Coding Blueprint (go-zenon-v1)​

Instructions for an AI Coding Agent Modifying go-zenon-v1

Execute Stages 1 through 8 strictly in order, one commit/PR per stage. After every stage, run:

  1. CGO_ENABLED=0 go test -race ./...
  2. Historical Alphanet replay & golden wire tests (go test ./internal/nom/... ./internal/vm/... ./test/fuzz/...)
  3. test/bend/run.sh (verifying zero regressions on all 300 existing Alphanet laws).

Hard Consensus Invariants (NEVER violate):

  1. Pre-Spork blocks (Version == 1, momentumHeight prior to PostQuantumAccountsSpork enforcement) MUST execute bit-for-bit identically to Alphanet (ChangesHash, error strings, and error precedence).
  2. VerifyPQ and ParsePQPublicKey MUST never panic on arbitrary malformed or truncated P2P/RPC byte slices; invalid lengths or encodings ALWAYS map to vmerr.ErrABSignatureInvalid / vmerr.ErrMSignatureInvalid (never ErrVerifierInternal).
  3. GetBasePlasmaForAccountBlock MUST remain 100% stateless (zero DB reads).
  4. Preserve CGO_ENABLED=0 across all targets except cmd/libznn.

Stage 1: Add internal/crypto/mldsa.go & pq.go Using Go 1.26 crypto/mldsa​

Create internal/crypto/pq.go and internal/crypto/mldsa.go wrapping Go 1.26's standard library crypto/mldsa with strict length guards and FIPS 204 domain-separation contexts:

internal/crypto/pq.go
package crypto

import (
"crypto/ed25519"
"crypto/mldsa"
"errors"
)

const (
AlgEd25519 uint8 = 0x00
AlgMLDSA44 uint8 = 0x01
AlgFNDSA512 uint8 = 0x02
AlgSLHDSA128s uint8 = 0x03
AlgHybridEdMLDSA44 uint8 = 0x81

MLDSA44PubKeySize = 1312
MLDSA44SigSize = 2420
MLDSA44SeedSize = mldsa.PrivateKeySize // 32 bytes

FNDSA512PubKeySize = 897
FNDSA512SigSize = 666

SLHDSA128sPubKeySize = 32
SLHDSA128sSigSize = 7856

DomainAccountBlockV2 = "zenon-ab:v2"
DomainMomentumV2 = "zenon-mom:v2"
DomainAuthRotateV1 = "zenon-auth-rotate:v1"
DomainPtlcV2 = "zenon-ptlc:v2"
DomainBridgeV2 = "zenon-bridge:v2"
)

var (
ErrUnsupportedSigAlg = errors.New("crypto: unsupported signature algorithm")
ErrInvalidPQKeyLen = errors.New("crypto: invalid post-quantum public key length")
ErrInvalidPQSigLen = errors.New("crypto: invalid post-quantum signature length")
)

// ExpectedWireLengths returns exact (len(PublicKeyWire), len(SignatureWire)) including the 1-byte algID prefix.
func ExpectedWireLengths(algID uint8) (pkWireLen, sigWireLen int, ok bool) {
switch algID {
case AlgEd25519:
return 1 + ed25519.PublicKeySize, 1 + ed25519.SignatureSize, true
case AlgMLDSA44:
return 1 + MLDSA44PubKeySize, 1 + MLDSA44SigSize, true
case AlgFNDSA512:
return 1 + FNDSA512PubKeySize, 1 + FNDSA512SigSize, true
case AlgSLHDSA128s:
return 1 + SLHDSA128sPubKeySize, 1 + SLHDSA128sSigSize, true
case AlgHybridEdMLDSA44:
return 1 + ed25519.PublicKeySize + MLDSA44PubKeySize, 1 + ed25519.SignatureSize + MLDSA44SigSize, true
default:
return 0, 0, false
}
}

// VerifyWire verifies sigWire ([algID] || rawSig) against pubWire ([algID] || rawPub) over msg with domainCtx.
// Never panics on malformed inputs.
func VerifyWire(pubWire, msg, sigWire []byte, domainCtx string) bool {
if len(pubWire) == 0 || len(sigWire) == 0 || pubWire[0] != sigWire[0] {
return false
}
algID := sigWire[0]
wantPK, wantSig, ok := ExpectedWireLengths(algID)
if !ok || len(pubWire) != wantPK || len(sigWire) != wantSig {
return false
}
rawPub := pubWire[1:]
rawSig := sigWire[1:]

switch algID {
case AlgEd25519:
return VerifyEd25519(rawPub, msg, rawSig)
case AlgMLDSA44:
return VerifyMLDSA44(rawPub, msg, rawSig, domainCtx)
case AlgHybridEdMLDSA44:
return VerifyEd25519(rawPub[:32], msg, rawSig[:64]) &&
VerifyMLDSA44(rawPub[32:], msg, rawSig[64:], domainCtx)
case AlgSLHDSA128s:
return VerifySLHDSA128s(rawPub, msg, rawSig, domainCtx)
case AlgFNDSA512:
return VerifyFNDSA512(rawPub, msg, rawSig, domainCtx)
default:
return false
}
}
internal/crypto/mldsa.go
package crypto

import "crypto/mldsa"

// MLDSA44KeyPairFromSeed derives a deterministic FIPS 204 ML-DSA-44 keypair from a 32-byte seed.
func MLDSA44KeyPairFromSeed(seed32 []byte) (rawPub []byte, priv *mldsa.PrivateKey, err error) {
if len(seed32) != MLDSA44SeedSize {
return nil, nil, ErrInvalidPQKeyLen
}
sk, err := mldsa.NewPrivateKey(mldsa.MLDSA44(), seed32)
if err != nil {
return nil, nil, err
}
return sk.PublicKey().Bytes(), sk, nil
}

// SignMLDSA44Deterministic computes a deterministic 2,420-byte FIPS 204 ML-DSA-44 signature.
func SignMLDSA44Deterministic(sk *mldsa.PrivateKey, msg []byte, domainCtx string) ([]byte, error) {
return sk.Sign(nil, msg, &mldsa.Options{
Context: domainCtx,
Deterministic: true,
})
}

// VerifyMLDSA44 verifies a 2,420-byte ML-DSA-44 signature against a 1,312-byte public key.
func VerifyMLDSA44(rawPub, msg, rawSig []byte, domainCtx string) bool {
if len(rawPub) != MLDSA44PubKeySize || len(rawSig) != MLDSA44SigSize {
return false
}
pk, err := mldsa.NewPublicKey(mldsa.MLDSA44(), rawPub)
if err != nil {
return false
}
return mldsa.Verify(pk, msg, rawSig, &mldsa.Options{Context: domainCtx}) == nil
}

Stage 2: Add Domain-Separated PQ SLIP-0010 Derivation (internal/crypto/slip0010_pq.go)​

  1. Define var slip0010PQSeedKey = []byte("zenon-pq-slip0010:v1") (never reusing "ed25519 seed").
  2. Implement DeriveZenonPQKey(bip39Seed []byte, algID uint8, accountIndex uint32) (SLIP0010Key, error) deriving hardened path m / 44' / 73404' / 1' / uint32(algID)' / accountIndex'.
  3. Scrub all intermediate SLIP0010Key and HMAC-SHA512 stack buffers with clear(...) matching internal/crypto/slip0010.go:46.

Stage 3: Add 0x02 PQUserAddrByte to internal/types/address.go​

  1. Add PQUserAddrByte byte = 0x02.
  2. Add PQPubKeyToAddress(pubWire []byte) (Address, error):
    • Reject len(pubWire) == 0 or pubWire[0] == AlgEd25519 (0x00 keys belong exclusively to 0x00 addresses).
    • Validate len(pubWire) against crypto.ExpectedWireLengths(pubWire[0]).
    • Hash "zenon-pq-addr:v1" || pubWire with crypto.SHA3256 and return [0x02] || sum[0:19].

Stage 4: Add Stateless WitnessPlasma to internal/pow/plasma.go​

  1. Extend SporkMask (internal/pow/plasma.go:45) from 5 bits to 8 bits:
    • SporkBitPQAccounts SporkMask = 1 << 5
    • SporkBitPQConsensus SporkMask = 1 << 6
    • SporkBitLegacySunset SporkMask = 1 << 7 (with implication closure LegacySunset => PQConsensus => PQAccounts => DynamicPlasma).
  2. In GetBasePlasmaForAccountBlock(block, sporkMask):
    • Compute base exactly as today when block.Version == 1 or !hasPQAccounts.
    • When hasPQAccounts && block.Version == 2 && !types.IsEmbeddedAddress(block.Address), add WitnessPlasma(block) (max(0, len(PublicKey)+len(Signature)-96)*17 + VerifyComputePlasma(algID)).

Stage 5: Add AccountStore[0x09] Caching & AuthRegistryContract​

  1. In internal/chain/account_store.go, add GetCachedPubKey() ([]byte, error) and SetCachedPubKey(pubWire []byte) error at sub-key [0x09], mirrored in HotStateCache.
  2. Implement internal/vm/contracts/auth/auth.go (AuthRegistryContract):
    • RotateKey(uint8 algId, bytes newPublicKey, bytes newKeyPopSignature, bool revokeLegacy) (EmbeddedSimplePlasma = 52,500 + calldata/witness plasma).
    • Register AuthRegistryContract in internal/vm/supervisor/registry_all.go gated on SporkBitPQAccounts.

Stage 6: Update PreverifyAccountBlock, accountBlockVerifier & VerifyMomentum​

  1. internal/vm/verifier/account_block.go:
    • Step 1 (version): Accept Version == 2 iff PostQuantumAccountsSpork is active at MomentumAcknowledged; reject Version == 1 once LegacyCryptoSunsetSpork is active.
    • PreverifyAccountBlock: If block.Version == 2, resolve pubWire from block.PublicKey (if non-empty) or lock-free HotStateCache, then invoke crypto.VerifyWire(pubWire, block.Hash[:], block.Signature, crypto.DomainAccountBlockV2).
    • signature & producer: Enforce the exact resolution order (AuthRegistry → AccountStore[0x09] → first-reveal block.PublicKey), returning ErrABPublicKeyMustBeCached if block.PublicKey is non-empty when already cached.
  2. internal/vm/verifier/momentum.go:
    • Update wrapIfBodyTampered (line 331) to use version-aware witness bounds and mark uncommitted Version == 2 witness tampering as vmerr.UncommittedBodyError.
    • Update VerifyMomentumStaticWithPreverified and LegacyDposV1.VerifyMomentumProducer to accept algID ∈ {0x01, 0x02} once PostQuantumConsensusSpork is active.

Stage 7: Upgrade PtlcContract, BridgeContract & go-libp2p (X25519MLKEM768)​

  1. internal/vm/contracts/ptlc/ptlc.go: Add PointTypeMLDSA44 = 3 and PointTypeFNDSA512 = 4 (pointLock = SHA3-256(rawPub)[32], witness = rawPub || rawSig).
  2. internal/vm/contracts/bridge/: Add Guardian PQ public-key registry and t-of-n bitmap multi-signature verification over UnwrapMessageHash (DomainBridgeV2).
  3. internal/p2p/libp2p/server.go: Enable Go 1.26 crypto/tls (CurvePreferences: []tls.CurveID{tls.X25519MLKEM768}) alongside Noise / PQ-peer-ID support.

Stage 8: Cross-Client Parity (zenon-rs & syrius) and Bend 2.0.40 Formal Laws​

  • zenon-rs (Rust): Use the RustCrypto audited crates ml-dsa (FIPS 204), slh-dsa (FIPS 205), and fn-dsa (c-fn-dsa / pure-Rust integer verifier by Thomas Pornin) behind the exact same algID wire tags. Run the 6-node 3-way mixed-testnet-fuzzer (go-zenon-v1 + zenon-rs) across live PostQuantumAccountsSpork activation, 3v3 reorgs (Pop() reverting AccountStore[0x09] and AuthRegistry), and malformed witness fuzzing.
  • syrius (Dart/Flutter): Expose libznn C-ABI exports (ZnnSignAccountBlockPQ, ZnnDerivePQAddress) directly from go-zenon-v1/cmd/libznn/exports.go so syrius desktop/mobile inherits Go 1.26's constant-time crypto/mldsa with zero duplicate Dart lattice math!
  • New Bend 2.0.40 Formal Verification Suite (test/bend/pq_witness/):
    1. Law_PKCache_Idempotence: Once AccountStore[0x09] or AuthRegistry is populated at height H, every valid block at H' > H satisfies len(PublicKey) == 0, and Pop(H) restores exact pre-H auth state.
    2. Law_LegacyLockout_Monotonic: Once authRecord.legacyRevoked == true, no sequence of Ed25519 (0x00) blocks is ever accepted on that address.
    3. Law_WitnessPlasma_Monotonic: For all blocks b1, b2, larger excess witness bytes strictly increase CanonicalBasePlasma, bounding worst-case Momentum verification CPU and wire bytes under MaxMomentumContentBytes (8 MiB).