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.26crypto/mldsaandcrypto/mlkemimplementations, 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):
| Layer | Package Path | Files Added / Modified | Responsibility |
|---|---|---|---|
| L0 | internal/common | params.go | Add PostQuantumAccountsSporkID, PostQuantumConsensusSporkID, LegacyCryptoSunsetSporkID, AccountBlockVersionV2 = 2, ABWitnessBytePlasma = 17 |
| L1 | internal/crypto | pq.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 |
| L2 | internal/types | address.go | Add PQUserAddrByte = 0x02, PQPubKeyToAddress(algID, rawPub), era-gated IsUserAddress |
| L3 | internal/nom | account_block.go, momentum.go | Zero wire changes needed; add helper methods SigAlgID() (uint8, bool) |
| L4 | internal/pow | plasma.go | Add stateless WitnessPlasma(block) inside GetBasePlasmaForAccountBlock when hasPQAccounts && block.Version >= 2 |
| L5 | internal/chain | account_store.go, spork_index.go | Add PrefixAccountPubKey = 0x09 (GetCachedPubKey / SetCachedPubKey) + HotStateCache pubkey slot |
| L6 | internal/vm | contracts/auth/ (new), contracts/ptlc/ptlc.go, contracts/bridge/, verifier/account_block.go, verifier/momentum.go | AuthRegistryContract, Stage-2 PreverifyAccountBlock PQ dispatch, AccountStore[0x09] enforcement, wrapIfBodyTampered bounds, PTLC types 3..4, Bridge PQ Guardian quorum |
| L7 | internal/p2p | libp2p/server.go, switcher/switcher.go | Enable hybrid X25519MLKEM768 stream security via Go 1.26 crypto/tls / crypto/mlkem; sunset RLPx |
| L8 | internal/wallet, internal/rpc | keystore.go, manager.go, api_embedded_ext.go | Derive m/44'/73404'/1'/alg'/idx', sign Version = 2 blocks, expose embedded.auth.* JSON-RPC methods |
Detailed AI / LLM Coding Blueprint (go-zenon-v1)
go-zenon-v1Execute Stages 1 through 8 strictly in order, one commit/PR per stage. After every stage, run:
CGO_ENABLED=0 go test -race ./...- Historical Alphanet replay & golden wire tests (
go test ./internal/nom/... ./internal/vm/... ./test/fuzz/...) test/bend/run.sh(verifying zero regressions on all 300 existing Alphanet laws).
Hard Consensus Invariants (NEVER violate):
- Pre-Spork blocks (
Version == 1,momentumHeightprior toPostQuantumAccountsSporkenforcement) MUST execute bit-for-bit identically to Alphanet (ChangesHash, error strings, and error precedence). VerifyPQandParsePQPublicKeyMUST never panic on arbitrary malformed or truncated P2P/RPC byte slices; invalid lengths or encodings ALWAYS map tovmerr.ErrABSignatureInvalid/vmerr.ErrMSignatureInvalid(neverErrVerifierInternal).GetBasePlasmaForAccountBlockMUST remain 100% stateless (zero DB reads).- Preserve
CGO_ENABLED=0across all targets exceptcmd/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:
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
}
}
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)
- Define
var slip0010PQSeedKey = []byte("zenon-pq-slip0010:v1")(never reusing"ed25519 seed"). - Implement
DeriveZenonPQKey(bip39Seed []byte, algID uint8, accountIndex uint32) (SLIP0010Key, error)deriving hardened pathm / 44' / 73404' / 1' / uint32(algID)' / accountIndex'. - Scrub all intermediate
SLIP0010KeyandHMAC-SHA512stack buffers withclear(...)matchinginternal/crypto/slip0010.go:46.
Stage 3: Add 0x02 PQUserAddrByte to internal/types/address.go
- Add
PQUserAddrByte byte = 0x02. - Add
PQPubKeyToAddress(pubWire []byte) (Address, error):- Reject
len(pubWire) == 0orpubWire[0] == AlgEd25519(0x00keys belong exclusively to0x00addresses). - Validate
len(pubWire)againstcrypto.ExpectedWireLengths(pubWire[0]). - Hash
"zenon-pq-addr:v1" || pubWirewithcrypto.SHA3256and return[0x02] || sum[0:19].
- Reject
Stage 4: Add Stateless WitnessPlasma to internal/pow/plasma.go
- Extend
SporkMask(internal/pow/plasma.go:45) from 5 bits to 8 bits:SporkBitPQAccounts SporkMask = 1 << 5SporkBitPQConsensus SporkMask = 1 << 6SporkBitLegacySunset SporkMask = 1 << 7(with implication closureLegacySunset => PQConsensus => PQAccounts => DynamicPlasma).
- In
GetBasePlasmaForAccountBlock(block, sporkMask):- Compute
baseexactly as today whenblock.Version == 1or!hasPQAccounts. - When
hasPQAccounts && block.Version == 2 && !types.IsEmbeddedAddress(block.Address), addWitnessPlasma(block)(max(0, len(PublicKey)+len(Signature)-96)*17 + VerifyComputePlasma(algID)).
- Compute
Stage 5: Add AccountStore[0x09] Caching & AuthRegistryContract
- In
internal/chain/account_store.go, addGetCachedPubKey() ([]byte, error)andSetCachedPubKey(pubWire []byte) errorat sub-key[0x09], mirrored inHotStateCache. - Implement
internal/vm/contracts/auth/auth.go(AuthRegistryContract):RotateKey(uint8 algId, bytes newPublicKey, bytes newKeyPopSignature, bool revokeLegacy)(EmbeddedSimplePlasma = 52,500+ calldata/witness plasma).- Register
AuthRegistryContractininternal/vm/supervisor/registry_all.gogated onSporkBitPQAccounts.
Stage 6: Update PreverifyAccountBlock, accountBlockVerifier & VerifyMomentum
internal/vm/verifier/account_block.go:- Step 1 (
version): AcceptVersion == 2iffPostQuantumAccountsSporkis active atMomentumAcknowledged; rejectVersion == 1onceLegacyCryptoSunsetSporkis active. PreverifyAccountBlock: Ifblock.Version == 2, resolvepubWirefromblock.PublicKey(if non-empty) or lock-freeHotStateCache, then invokecrypto.VerifyWire(pubWire, block.Hash[:], block.Signature, crypto.DomainAccountBlockV2).signature&producer: Enforce the exact resolution order (AuthRegistry→AccountStore[0x09]→ first-revealblock.PublicKey), returningErrABPublicKeyMustBeCachedifblock.PublicKeyis non-empty when already cached.
- Step 1 (
internal/vm/verifier/momentum.go:- Update
wrapIfBodyTampered(line 331) to use version-aware witness bounds and mark uncommittedVersion == 2witness tampering asvmerr.UncommittedBodyError. - Update
VerifyMomentumStaticWithPreverifiedandLegacyDposV1.VerifyMomentumProducerto acceptalgID∈{0x01, 0x02}oncePostQuantumConsensusSporkis active.
- Update
Stage 7: Upgrade PtlcContract, BridgeContract & go-libp2p (X25519MLKEM768)
internal/vm/contracts/ptlc/ptlc.go: AddPointTypeMLDSA44 = 3andPointTypeFNDSA512 = 4(pointLock = SHA3-256(rawPub)[32],witness = rawPub || rawSig).internal/vm/contracts/bridge/: Add Guardian PQ public-key registry andt-of-nbitmap multi-signature verification overUnwrapMessageHash(DomainBridgeV2).internal/p2p/libp2p/server.go: Enable Go 1.26crypto/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 cratesml-dsa(FIPS 204),slh-dsa(FIPS 205), andfn-dsa(c-fn-dsa/ pure-Rust integer verifier by Thomas Pornin) behind the exact samealgIDwire tags. Run the 6-node 3-waymixed-testnet-fuzzer(go-zenon-v1 + zenon-rs) across livePostQuantumAccountsSporkactivation, 3v3 reorgs (Pop()revertingAccountStore[0x09]andAuthRegistry), and malformed witness fuzzing.syrius(Dart/Flutter): ExposelibznnC-ABI exports (ZnnSignAccountBlockPQ,ZnnDerivePQAddress) directly fromgo-zenon-v1/cmd/libznn/exports.gososyriusdesktop/mobile inherits Go 1.26's constant-timecrypto/mldsawith zero duplicate Dart lattice math!- New Bend 2.0.40 Formal Verification Suite (
test/bend/pq_witness/):Law_PKCache_Idempotence: OnceAccountStore[0x09]orAuthRegistryis populated at heightH, every valid block atH' > Hsatisfieslen(PublicKey) == 0, andPop(H)restores exact pre-Hauth state.Law_LegacyLockout_Monotonic: OnceauthRecord.legacyRevoked == true, no sequence ofEd25519(0x00) blocks is ever accepted on that address.Law_WitnessPlasma_Monotonic: For all blocksb1, b2, larger excess witness bytes strictly increaseCanonicalBasePlasma, bounding worst-caseMomentumverification CPU and wire bytes underMaxMomentumContentBytes(8 MiB).