AccountBlock v2, Witness Envelope & Public-Key Caching
TL;DR: Upgrade
AccountBlock.Versionfrom1to2on activation ofPostQuantumAccountsSpork. Keep the306-byteAccountBlock.ComputeHash()preimage, Protobuf tags1..23, and RLP list arity 100% unchanged. PrefixSignature(tag 23) andPublicKey(tag 22) with a 1-bytealgID, cache each account's PQPublicKeyinAccountStoreupon its first v2 block, and allow all subsequent blocks (Height > 1) to setPublicKey = nil—saving1,313 bytesperML-DSA-44tx and898 bytesperFN-DSA-512tx.
1. Why AccountBlock.ComputeHash() Requires Zero Changes
Inspecting internal/nom/account_block.go:124-166 confirms that Zenon's AccountBlock hash is computed over a fixed 306-byte stack buffer:
Bytes 0..8 : be_u64(Version) // 1 -> 2 post-Spork
Bytes 8..16 : be_u64(ChainIdentifier) // 1 on Alphanet
Bytes 16..24 : be_u64(BlockType) // 1..5
Bytes 24..56 : PreviousHash[32]
Bytes 56..64 : be_u64(Height)
Bytes 64..104 : MomentumAcknowledged[40] // Hash[32] || be_u64(Height)
Bytes 104..124 : Address[20]
Bytes 124..144 : ToAddress[20]
Bytes 144..176 : Amount[32]
Bytes 176..186 : TokenStandard[10]
Bytes 186..218 : FromBlockHash[32]
Bytes 218..250 : SHA3_256(DescendantHashes)[32]
Bytes 250..282 : SHA3_256(Data)[32]
Bytes 282..290 : be_u64(FusedPlasma)
Bytes 290..298 : be_u64(Difficulty)
Bytes 298..306 : Nonce[8]
BasePlasma, TotalPlasma, ChangesHash, PublicKey (tag 22), and Signature (tag 23) are excluded from ComputeHash(). Both Protobuf (SerializeProto in account_block.go:389-394) and RLP (EncodeRLP) already encode PublicKey and Signature as arbitrary variable-length []byte slices!
2. Canonical algID Witness Wire Envelope (Version == 2)
In AccountBlock (Version == 2) and Momentum (Version >= 3 or post-PostQuantumConsensusSpork), witness byte slices carry an explicit 1-byte algorithm tag at index 0:
PublicKeyWire := []byte{} // Omitted when cached in AccountStore / AuthRegistry!
OR [algID] || RawPublicKeyBytes
SignatureWire := [algID] || RawSignatureBytes
Exact Byte-Length Validation Table (Consensus-Critical)
Any deviation from the exact byte lengths below MUST return vmerr.ErrABSignatureInvalid (on AccountBlock) or vmerr.ErrMSignatureInvalid (on Momentum), never panicking and never returning ErrVerifierInternal:
algID | Constant | len(PublicKeyWire) (When Present) | len(SignatureWire) (Always Required on User Blocks) | Signing Domain Message |
|---|---|---|---|---|
0x00 | AlgEd25519 | 1 + 32 = 33 B (or raw 32 B in v1) | 1 + 64 = 65 B (or raw 64 B in v1) | block.Hash[:] (32 B) |
0x01 | AlgMLDSA44 | 1 + 1,312 = 1,313 B | 1 + 2,420 = 2,421 B | block.Hash[:] with FIPS 204 ctx = "zenon-ab:v2" ("zenon-mom:v2" for Momentums) |
0x02 | AlgFNDSA512 | 1 + 897 = 898 B | 1 + 666 = 667 B | "zenon-ab:v2" || block.Hash[:] |
0x03 | AlgSLHDSA128s | 1 + 32 = 33 B | 1 + 7,856 = 7,857 B | block.Hash[:] with FIPS 205 ctx = "zenon-ab:v2" |
0x81 | AlgHybridEdMLDSA44 | 1 + 32 + 1,312 = 1,345 B | 1 + 64 + 2,420 = 2,485 B | Both Ed25519 AND ML-DSA-44 MUST verify |
Both FIPS 204 (ML-DSA) and FIPS 205 (SLH-DSA) natively accept a domain-separation context string (0..255 bytes) inside the standard Verify(pk, msg, sig, &Options{Context: ...}) call! Passing "zenon-ab:v2" for AccountBlocks, "zenon-mom:v2" for Momentums, "zenon-ptlc:v2" for PTLC, and "zenon-bridge:v2" for Bridge prevents cross-object signature replay across the entire protocol at zero extra hashing cost.
3. Sequential Account-Chain Public-Key Caching
State Storage Key in AccountStore
In go-zenon-v1/internal/chain/account_store.go, each user/contract AccountStore namespaces keys under the account's 20-byte address inside VersionedStore (nom DB), automatically participating in FlatOverlay staging, ChangesHash (Patch.Dump()), and 30-block fork rollbacks (Pop()).
Add a single per-account key:
PrefixAccountPubKey = [0x09] // Stores PublicKeyWire ([algID] || RawPublicKeyBytes)
Deterministic Resolution Order During Verification
When verifying a user AccountBlock (!types.IsEmbeddedAddress(block.Address) and block.Version == 2):
- Enforce Omission Once Cached (
ErrABPublicKeyMustBeCached): Once an account's public key is recorded inAuthRegistryorAccountStore[0x09], subsequent blocks MUST setblock.PublicKey = nil(len == 0). Forbidding redundant1,312 Bpublic keys prevents malicious senders from wasting Momentum byte space or malleating uncommitted witness bytes. - Rollback Safety: Because
AccountStore[0x09]is written inside the normalAccountBlockTransactionstorage.Patch, rolling back a side-chain Momentum (VersionedStore.Pop()) automatically revertsAccountStore[0x09]if theHeight = 1block is un-committed!
4. Preserving Lock-Free Stage-2 Parallel Pre-Verification
A signature strength of go-zenon-v1 (internal/vm/verifier/account_block.go:81-108) is PreverifyAccountBlock, which verifies ComputeHash(), VerifyEd25519, and CheckPoWNonce concurrently across GOMAXPROCS worker goroutines in Stage 2 completely outside database locks.
With Public-Key Caching (len(block.PublicKey) == 0 for Height > 1), how does Stage 2 pre-verify a signature without holding a DB lock?
HotStateCachePublic-Key Lookup:go-zenon-v1already maintains a lock-free 256-shard128 MiBHotStateCache(internal/storage/hotcache.go) alongside lock-free MVCC*pebble.Snapshotreads in Stage 3 (Prefetch).- Two-Path Stage-2 Preverify:
- If
len(block.PublicKey) > 0(Height == 1block): Stage 2 verifiesSignatureWireagainstblock.PublicKeyimmediately with zero lookups. - If
len(block.PublicKey) == 0(Height > 1block): Stage 2 probes the lock-freeHotStateCache(keyed by(Address, frontierEpoch)or immutableAccountStore[0x09]). On cache hit (>99% of active accounts), Stage 2 verifiesML-DSA-44/FN-DSA-512across all CPU cores and recordsresolvedPubKeyHash [32]byteonPreverifiedBlockso Stage 4 (accountBlockVerifier.signature) simply checkspv.resolvedPubKeyHash == activeKeyHashinO(1)!
- If
5. Updating wrapIfBodyTampered in verifier/momentum.go
In internal/vm/verifier/momentum.go:323-341, wrapIfBodyTampered prevents a malicious P2P peer from getting a canonical Momentum.Hash blacklisted by mutating uncommitted witness fields inside a DetailedMomentum (BlocksMsg 0x16 / NewBlockMsg 0x17):
// CURRENT v1 CODE (internal/vm/verifier/momentum.go:331):
if blk.ComputeHash() != blk.Hash || len(blk.PublicKey) > 32 || len(blk.Signature) > 64 {
return vmerr.UncommittedBodyError(err)
}
When AccountBlockVersion == 2 is active, update the upper-bound sanity guard from 32 / 64 to crypto.MaxValidPubKeyWireLen(blk.Version) (1,345 B) and crypto.MaxValidSigWireLen(blk.Version) (7,857 B)—and mark any ErrABSignatureInvalid / ErrABPublicKeyMustBeCached failure inside a DetailedMomentum body as UncommittedBodyError whenever blk.Header() == m.Content[i]! That preserves go-zenon-v1's exact P4-04 peer-quarantine immunity under post-quantum witnesses.