Skip to main content

AccountBlock v2, Witness Envelope & Public-Key Caching

TL;DR: Upgrade AccountBlock.Version from 1 to 2 on activation of PostQuantumAccountsSpork. Keep the 306-byte AccountBlock.ComputeHash() preimage, Protobuf tags 1..23, and RLP list arity 100% unchanged. Prefix Signature (tag 23) and PublicKey (tag 22) with a 1-byte algID, cache each account's PQ PublicKey in AccountStore upon its first v2 block, and allow all subsequent blocks (Height > 1) to set PublicKey = nil—saving 1,313 bytes per ML-DSA-44 tx and 898 bytes per FN-DSA-512 tx.


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:

algIDConstantlen(PublicKeyWire) (When Present)len(SignatureWire) (Always Required on User Blocks)Signing Domain Message
0x00AlgEd255191 + 32 = 33 B (or raw 32 B in v1)1 + 64 = 65 B (or raw 64 B in v1)block.Hash[:] (32 B)
0x01AlgMLDSA441 + 1,312 = 1,313 B1 + 2,420 = 2,421 Bblock.Hash[:] with FIPS 204 ctx = "zenon-ab:v2" ("zenon-mom:v2" for Momentums)
0x02AlgFNDSA5121 + 897 = 898 B1 + 666 = 667 B"zenon-ab:v2" || block.Hash[:]
0x03AlgSLHDSA128s1 + 32 = 33 B1 + 7,856 = 7,857 Bblock.Hash[:] with FIPS 205 ctx = "zenon-ab:v2"
0x81AlgHybridEdMLDSA441 + 32 + 1,312 = 1,345 B1 + 64 + 2,420 = 2,485 BBoth Ed25519 AND ML-DSA-44 MUST verify
Built-in FIPS 204 / FIPS 205 Context String Domain Separation

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):

  1. Enforce Omission Once Cached (ErrABPublicKeyMustBeCached): Once an account's public key is recorded in AuthRegistry or AccountStore[0x09], subsequent blocks MUST set block.PublicKey = nil (len == 0). Forbidding redundant 1,312 B public keys prevents malicious senders from wasting Momentum byte space or malleating uncommitted witness bytes.
  2. Rollback Safety: Because AccountStore[0x09] is written inside the normal AccountBlockTransaction storage.Patch, rolling back a side-chain Momentum (VersionedStore.Pop()) automatically reverts AccountStore[0x09] if the Height = 1 block 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?

  • HotStateCache Public-Key Lookup: go-zenon-v1 already maintains a lock-free 256-shard 128 MiB HotStateCache (internal/storage/hotcache.go) alongside lock-free MVCC *pebble.Snapshot reads in Stage 3 (Prefetch).
  • Two-Path Stage-2 Preverify:
    1. If len(block.PublicKey) > 0 (Height == 1 block): Stage 2 verifies SignatureWire against block.PublicKey immediately with zero lookups.
    2. If len(block.PublicKey) == 0 (Height > 1 block): Stage 2 probes the lock-free HotStateCache (keyed by (Address, frontierEpoch) or immutable AccountStore[0x09]). On cache hit (>99% of active accounts), Stage 2 verifies ML-DSA-44 / FN-DSA-512 across all CPU cores and records resolvedPubKeyHash [32]byte on PreverifiedBlock so Stage 4 (accountBlockVerifier.signature) simply checks pv.resolvedPubKeyHash == activeKeyHash in O(1)!

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.