Skip to main content

SimpleX Protocol Analysis - Documentation Index

Project: SimpleGo - Native ESP32 SMP Implementation Version: v0.1.18-alpha Last Updated: 2026-03-26 (Session 50 -- Queue Rotation Multi-Fix: Unlimited Consecutive Rotations)


LATEST: Queue Rotation Multi-Fix (Session 50)​

Made Queue Rotation work for unlimited consecutive rotations. 6 fixes across 7 files. Root cause: CQ E2E peer key cache filled with stale data during rotation by incoming QTEST messages - cache invalidation at rotation_start() insufficient, needed second invalidation after Phase 1b key write. One day lost on Mausi error (accepted wrong bug classification without checking known facts). 4 consecutive rotations verified with PQ crypto on fresh device. GoChat support started.

Bugs: 81 total (rotation issues resolved, count unchanged) Lessons: 277 total (7 new in S50: #271-#277)

PREVIOUS: Queue Rotation from Zero to Working (Session 49)​

PREVIOUS: Performance + Statusbar + Splash + Matrix + Reconnect (Session 48)​

PREVIOUS: UX Overhaul, NVS Resize, PQ UI (Session 47)​

PREVIOUS: Consolidation and Quality Pass (Session 42)​

Session 42 was a pure consolidation session. No new features. Production-grade code hygiene, architectural correctness, and AGPL-3.0 license compliance across all 47 source files:

  • smp_handshake.c debug cleanup: 74 lines removed, zero printf in production
  • smp_globals.c dissolved: 7 symbols migrated to owning modules, file deleted
  • smp_app_run() refactored: 530 lines to 118 lines via 5 static helpers
  • License headers: all 47 source files standardized (AGPL-3.0, SPDX)
  • extern TODO markers resolved, re-delivery log verified correct

Bugs: 71 total (no new bugs, structural changes only) Lessons: 229 total (4 new in S42: #226-#229)

PREVIOUS: Pre-GitHub Cleanup (Session 41)​

Session 40 implemented a three-stage sliding window architecture for unlimited encrypted chat history at constant memory consumption. Three-stage pipeline: SD Card (unlimited, AES-256-GCM) to PSRAM Cache (30 messages) to LVGL Window (5 bubbles, ~6KB). Crypto-separation from SPI mutex (500ms to < 10ms). Bidirectional scroll with re-entrancy guard.

PREVIOUS: On-Device WiFi Manager (Session 39)​

On February 28 - March 1, 2026, Session 38 added backlight control and identified the display freeze root cause:

  • Display Backlight: GPIO 42 pulse-counting (16 levels)
  • Keyboard Backlight: I2C 0x55 with auto-off timer
  • Settings Screen: Brightness sliders + gear button
  • WiFi/LWIP → PSRAM: 56KB internal SRAM freed
  • Root Cause Found: SPI2 bus sharing (display + SD card)
  • 8 Hypotheses Tested: 7 wrong, 1 correct (SD removal = stable!)
  • LVGL Heap Discovery: Separate 64KB pool, ~8 bubbles max

Bugs: 61 total (2 new in S38: #60-#61) Lessons Learned: 209 total (5 new in S38)

PREVIOUS: Encrypted Chat History (Session 37)​

On February 25-27, 2026, Session 37 implemented encrypted chat persistence:

  • AES-256-GCM Encrypted History: Per-contact HKDF-SHA256 key derivation
  • Append-Only SD Storage: /sdcard/simplego/msgs/chat_XX.bin
  • SPI2 Bus Serialization: LVGL mutex for display + SD collision
  • DMA Draw Buffer Fix: Moved to internal SRAM (anti-tearing)
  • Chunked Rendering: 3 bubbles/tick progressive loading
  • Contact List Redesign: 28px single-line cards, search, bottom bar

Bugs: 59 total (2 new in S37: #58-#59) Lessons Learned: 204 total (2 new in S37)

PREVIOUS: Contact Lifecycle (Session 36)​

On February 25, 2026, Session 36 completed the full contact lifecycle:

  • NTP Timestamps: Real clock in chat bubbles (Mon | 14:35)
  • Contact Name from ConnInfo: displayName extracted from JSON
  • NVS 4-Key Cleanup: rat_XX, peer_XX, hand_XX, rq_XX on delete
  • KEY-HELLO Race Condition: FreeRTOS TaskNotification sync
  • UI Cleanup on Delete: Bubbles cleared, QR reset, stale cache gone
  • Contact List Redesign: Long-press menu with Delete and Info
  • Full Lifecycle Verified: Create → Chat → Delete → Recreate (no erase-flash!)

Bugs: 57 total (7 new in S36: #51-#57 + Bug E) Lessons Learned: 202 total (10 new in S36)

PREVIOUS: Multi-Contact Victory (Session 35)​

On February 24, 2026, Session 35 fixed all remaining multi-contact bugs:

  • Ratchet Slot Ordering: set_active BEFORE process_message
  • KEY Target Queue: Reply Queue (not Contact Queue)
  • Per-Contact Chat Filter: Bubble tagging + LV_OBJ_FLAG_HIDDEN
  • PSRAM Guard: Prevents NVS overwrite of active session
  • NVS Fallback: Contact >0 PSRAM loads from NVS after boot
  • Verified: 2 contacts, bidirectional, receipts, 20+ messages, erase-flash tested

Bugs: 50 total (no new protocol bugs in S35) Lessons Learned: 192 total (6 new in S35)


Documentation Structure​

The complete protocol analysis (~33,000+ lines, 670+ sections) is split into 47 parts:

PartFileLinesContent
103_PART1_INTRO_SESSIONS_1-2.md~2,300Introduction, Foundation, TLS 1.3
204_PART2_SESSIONS_3-4.md~1,000Wire format, Bugs #1-8
305_PART3_SESSIONS_5-6.md~800X448 breakthrough, SMPQueueInfo
406_PART4_SESSION_7.md~3,200AES-GCM verification, Tail encoding
507_PART5_SESSION_8.md~400AgentConfirmation works!
608_PART6_SESSION_9.md~450Reply Queue HSalsa20 fix
709_PART7_SESSION_10.md~400cmNonce fix, app "connecting"
810_PART8_SESSION_11.md~400Regression & Recovery
911_PART9_SESSION_12.md~400E2E Keypair Fix Attempt
1012_PART10_SESSION_13.md~700E2E Crypto Deep Analysis
1113_PART11_SESSION_14.md~900DH SECRET VERIFIED!
1214_PART12_SESSION_15.md~650Root Cause Found
1315_PART13_SESSION_16.md~900Custom XSalsa20 + Double Ratchet
1416_PART14_SESSION_17.md~500Key Consistency Debug
1517_PART15_SESSION_18.md~600BUG #18 SOLVED! E2E SUCCESS
1618_PART16_SESSION_19.md~550Header Decrypt SUCCESS!
1719_PART17_SESSION_20.md~600Body Decrypt! Peer Profile!
1820_PART18_SESSION_21.md~700v3 Format + HELLO Debugging
1921_PART19_SESSION_22.md~600Reply Queue Flow Discovery
2022_PART20_SESSION_23.md~570CONNECTED! Historic Milestone!
2123_PART21_SESSION_24.md~600First Chat Message! Milestone #2!
2224_PART22_SESSION_25.md~480** Bidirectional + Receipts! M3,4,5!**
2325_PART23_SESSION_26.md~600** Persistence! Milestone 6!**
2426_PART24_SESSION_27.md~650** FreeRTOS Architecture Investigation**
2527_PART25_SESSION_28.md~550** Phase 2b Success -- Tasks Running!**
2628_PART26_SESSION_29.md~750** Multi-Task Architecture BREAKTHROUGH!**
2729_PART27_SESSION_30.md~660** Intensive Debug -- 10 Hypotheses, 14 Fixes**
2830_PART28_SESSION_31.md~850** Bidirectional Chat Restored! Milestone 7!**
2931_PART29_SESSION_32.md~500** "The Demonstration" -- From Protocol to Messenger**
3032_PART30_SESSION_34.md~473** Multi-Contact Architecture -- Per-Contact Reply Queue**
3133_PART31_SESSION_34_BREAKTHROUGH.md~545** Multi-Contact Bidirectional -- 11 Bugs, HISTORIC MILESTONE**
3234_PART32_SESSION_35.md~304** Multi-Contact Victory -- All Planned Bugs Fixed**
3335_PART33_SESSION_36.md~389** Contact Lifecycle: Delete, Recreate, Zero Compromise**
3436_PART34_SESSION_37.md~332** Encrypted Chat History: SD Card, SPI Bus Wars**
3537_PART35_SESSION_38.md~324** The SPI2 Bus Hunt: Eight Hypotheses, One Root Cause**
3638_PART36_SESSION_39.md~310WiFi Manager: First On-Device WiFi Setup for T-Deck
3739_PART37_SESSION_40.md~273Sliding Window: Unlimited Encrypted History at Constant Memory
3840_PART38_SESSION_41.md~145** Pre-GitHub Cleanup and Stabilization**
3941_PART39_SESSION_42.md~130** Consolidation and Quality Pass**
4042_PART40_SESSION_43.md~210** Documentation + Security Cleanup + Display Name**
4143_PART41_SESSION_44.md~155** Hardware Class 1 Security Architecture**
4244_PART42_SESSION_45.md~155** Security Implementation: 4 Findings Closed (SEC-01/02/04/05)**
4345_PART43_SESSION_46.md~230** MEGABLAST: Post-Quantum Double Ratchet - World First**
4446_PART44_SESSION_47.md~200** UX Overhaul: NVS 1 MB, QR 16-Stage Flow, PQ UI**
4547_PART45_SESSION_48.md~190** Performance + Statusbar + Splash + Matrix + Reconnect (16h)**
4648_PART46_SESSION_49.md~220** Queue Rotation: QADD/QKEY/QUSE/QTEST, Live Server Switch**
4749_PART47_SESSION_50.md~230** Queue Rotation Multi-Fix: Unlimited Consecutive Rotations**
Total~33,000+670+ Sections

Quick Reference Documents​

DocumentLinesDescription
README.md~1,370Project overview and navigation
BUG_TRACKER.md~2,800All 71 bugs documented, 232 lessons
QUICK_REFERENCE.md~3,000Constants, wire formats, verified values

Session Overview​

SessionDateFocusResult
1-3Dec 2025FoundationTLS 1.3, Basic SMP
4Jan 23, 2026Wire FormatBugs #1-8 fixed
5Jan 24, 2026CryptoX448 byte-order (Bug #9)
6Jan 24, 2026HandshakeSMPQueueInfo (Bugs #10-12)
7Jan 24-25, 2026ResearchFirst native SMP confirmed!
8Jan 27, 2026BREAKTHROUGHAgentConfirmation works! (Bugs #13-14)
9Jan 27, 2026Reply QueueHSalsa20 fix (Bugs #15-16)
10CJan 28, 2026E2E LayercmNonce fix (Bug #17)
11Jan 30, 2026RecoveryRegression fixed
12-13Jan 30, 2026AnalysisE2E Crypto Deep Dive
14Jan 31 - Feb 1VerificationDH SECRET VERIFIED!
15Feb 1, 2026Root CauseTheory (later disproven)
16Feb 1-3, 2026Custom CryptoXSalsa20 + Double Ratchet
17Feb 4, 2026DebugKey Consistency
18Feb 5, 2026SOLVEDBug #18 ONE LINE FIX!
19Feb 5, 2026HeaderHeader Decrypt SUCCESS! (Bug #19)
20Feb 6, 2026PROFILEBody Decrypt! Peer Profile!
21Feb 6-7, 2026HELLOv3 Format (Bugs #20-26)
22Feb 7, 2026DISCOVERYReply Queue Flow (Bugs #27-31)
23Feb 7-8, 2026CONNECTED** First SimpleX on Microcontroller!**
24Feb 11-13, 2026FIRST A_MSG** First Chat Message!**
25Feb 13-14, 2026BIDIRECTIONAL** Chat + Receipts! (8 bugs)**
26Feb 14, 2026PERSISTENCE** Milestone 6! Ratchet State Persistence**
27Feb 14-15, 2026ARCHITECTURE** FreeRTOS Investigation (17 lessons)**
28Feb 15, 2026TASKS** Phase 2b Success -- 3 Tasks Running!**
29Feb 16, 2026ARCHITECTURE** Multi-Task BREAKTHROUGH!**
30Feb 16-18, 2026DEBUG** 10 Hypotheses, 14 Fixes, Awaiting Evgeny**
31Feb 18, 2026RESOLVED** Bidirectional Restored! Milestone 7!**
32Feb 19-20, 2026UI** "The Demonstration" -- Full Messenger UI**
34Feb 23, 2026ARCHITECTURE** Multi-Contact -- Per-Contact Reply Queue**
34bFeb 24, 2026BREAKTHROUGH** Multi-Contact Bidirectional -- 11 Bugs Fixed!**
35Feb 24, 2026VICTORY** All Planned Bugs Fixed -- Chat Filter Working!**
36Feb 25, 2026LIFECYCLE** Contact Lifecycle: Delete, Recreate, Zero Compromise**
37Feb 25-27, 2026HISTORY** Encrypted Chat History: SD Card, SPI Bus Wars**
38Feb 28 - Mar 1, 2026SPI HUNT** Eight Hypotheses, One Root Cause**
39Mar 3, 2026WIFI** First On-Device WiFi Manager for T-Deck**
40Mar 3-4, 2026WINDOWSliding Window: Unlimited Encrypted History
41Mar 4, 2026CLEANUP** Pre-GitHub Cleanup and Stabilization**
42Mar 4-5, 2026QUALITY** Consolidation and Quality Pass**
43Mar 5-8, 2026DOCS+SEC+UX** Wiki + Security Cleanup + Display Name + Bug #20**
44Mar 8, 2026SECURITY** Hardware Class 1 Security Architecture (15 docs, 3,243 lines)**
45Mar 10, 2026SECURITY** 4 Findings Closed (SEC-01/02/04/05), HMAC NVS Vault Live**
46Mar 11-12, 2026MEGABLAST** Post-Quantum Double Ratchet - World First! 6/6 SEC CLOSED**
47Mar 15-16, 2026UX** 7 Bugs, NVS 1 MB, QR 16-Stage Flow, PQ UI, Per-Contact PQ Abandoned**
48Mar 16-17, 2026MEGA SESSION** Bug #30+#31, Statusbar, Splash, Matrix, Reconnect (16h, 23 files)**
49Mar 18-21, 2026QUEUE ROTATION** QADD/QKEY/QUSE/QTEST, Live Server Switch, 21 Servers, SEC-07 (4 days)**
50Mar 22-26, 2026ROTATION FIX** Unlimited Consecutive Rotations, Cache Timing Root Cause, GoChat**

Key Achievements​

COMPLETE MULTI-TASK BIDIRECTIONAL CHAT (Session 31)​

  • TLS 1.3 Handshake
  • SMP Protocol (Contact + Reply Queues)
  • X3DH Key Agreement
  • Double Ratchet Header+Body Decrypt
  • E2E Encrypt/Decrypt both directions
  • A_MSG Send + Receive
  • Delivery Receipts ()
  • Ratchet State Persistence (NVS)
  • ESP32 survives reboot!
  • ESP32 ↔ SimpleX App -- Full Chat!
  • Zstd Decompression
  • ConnInfo JSON Parsing
  • Peer Profile on ESP32: "displayName": "cannatoshi"
  • TLS Reconnect to Reply Queue
  • SUB + KEY Commands
  • HELLO Exchange (both directions)
  • CON -- "CONNECTED"!
  • FreeRTOS Multi-Task Architecture
  • TCP Keep-Alive + SMP PING/PONG
  • Batched txCount > 1 Handling
  • TX2 MSG Forwarding
  • Re-Delivery Detection
  • Milestone 7: Multi-Task Bidirectional Chat
  • LVGL Keyboard Integration (T-Deck HW)
  • **Delivery Status: ... → → → **
  • Receipt Parsing (inner_tag 'V')
  • UI Event Queue (app_to_ui_queue)
  • 128-Contact PSRAM Architecture
  • Production Cleanup (zero private keys in logs)
  • Runtime Add-Contact (NET_CMD via Ring Buffer)
  • Per-Contact 42d Tracking (128-bit bitmap)
  • Per-Contact Reply Queue (128 slots, ~49KB PSRAM)
  • SMP v7 Signing Fix (1-byte session prefix)
  • PSRAM Total: ~158KB / 8MB (1.9%)
  • KEY Command Fix (Contact Queue credentials)
  • Ghost Write Elimination (5 errors in reply_queue_create)
  • Global State Elimination (peer_prepare_for_contact)
  • Reply Queue Encoder Fix (byte-identical)
  • Crypto Fix (beforenm vs scalarmult)
  • Contact 0 + Contact 1 Bidirectional Encrypted
  • MILESTONE 10: Multi-Contact Bidirectional Messaging
  • Per-Contact Chat Filter (bubble tagging + HIDDEN)
  • Ratchet Slot Ordering Fix (set_active BEFORE decrypt)
  • KEY Targets Reply Queue (not Contact Queue)
  • PSRAM Guard + NVS Fallback for Contact >0
  • MILESTONE 11: Multi-Contact Chat Filter
  • NTP Timestamps in Chat Bubbles (SNTP sync)
  • Contact Name from ConnInfo JSON (displayName)
  • 4-Key NVS Cleanup on Delete (rat/peer/hand/rq)
  • KEY-HELLO Race Condition Fix (TaskNotification)
  • UI Cleanup on Delete (bubbles + QR reset)
  • Contact List Redesign (665 lines, long-press menu)
  • Full Contact Lifecycle (create/chat/delete/recreate)
  • UART 8x Speedup (921600 baud)
  • Handshake 3.25x Speedup (6.5s → 2s)
  • MILESTONE 12: Contact Lifecycle
  • AES-256-GCM Encrypted Chat History on SD Card
  • HKDF-SHA256 Per-Contact Key Derivation
  • SPI2 Bus Serialization (Display + SD)
  • DMA Draw Buffer to Internal SRAM (Anti-Tearing)
  • Chunked Rendering (3 bubbles/tick)
  • Contact List Redesign (28px, search, bottom bar)
  • MILESTONE 13: Encrypted Chat History
  • Display Backlight Control (GPIO 42, 16 levels)
  • Keyboard Backlight Control (I2C 0x55, auto-off)
  • Settings Screen with Brightness Sliders
  • WiFi/LWIP Buffers to PSRAM (56KB freed)
  • SPI2 Root Cause Identified (8 hypotheses, SD removal = stable)
  • LVGL Heap Discovery (64KB separate pool, ~8 bubbles)
  • MAX_VISIBLE_BUBBLES Sliding Window
  • MILESTONE 14: Backlight Control + SPI Root Cause
  • Unified WiFi Manager (Single State Machine, NVS-only)
  • First-Boot Auto-Launch WiFi Manager
  • WPA3 SAE Fix (WIFI_AUTH_WPA2_PSK threshold)
  • SPI DMA Buffer pinned to Internal SRAM
  • Dynamic Main Header (SSID/Unread/NoWiFi)
  • Info Tab Redesign (Live Heap/PSRAM/LVGL Stats)
  • First On-Device WiFi Manager for T-Deck Hardware
  • MILESTONE 15: On-Device WiFi Manager
  • Three-Stage Pipeline: SD > PSRAM Cache > LVGL Window
  • Crypto-Separation from SPI Mutex (500ms to < 10ms)
  • LVGL Pool Profiling (~1.2KB/bubble, 64KB pool)
  • Bidirectional Scroll with Re-Entrancy Guard
  • MILESTONE 16: Sliding Window Chat History
  • Pre-Release Security Cleanup (debug crypto removed, CWE-14)
  • Hardware AES Fix (software fallback for DMA SRAM fragmentation)
  • Screen Lifecycle Fix (ephemeral screens, ~14KB pool recovered)
  • Dangling Pointer Protection (null guards on background-callable UI)
  • Live Bubble Eviction Order Fix (evict-before-create)
  • Comment Cleanup (9 files, session refs removed, German to English)
  • README Rewrite for GitHub Audience
  • MILESTONE 17: Pre-GitHub Stabilization
  • smp_handshake.c: 74 lines debug removed, zero printf
  • smp_globals.c dissolved: 7 symbols to owning modules
  • smp_app_run(): 530 to 118 lines via 5 static helpers
  • License headers: 47 files AGPL-3.0 + SPDX standardized
  • Ownership model: smp_types.h = types only, no objects
  • MILESTONE 18: Production Code Quality
  • Docusaurus 3 Documentation Site at docs.simplego.dev
  • 17 Documents Migrated from Legacy markdown
  • smp-in-c/ Guide: 10 Pages, World-First SMP-in-C Documentation
  • SimpleGo Cited in Official SimpleX Network Architecture Doc
  • MILESTONE 19: Professional Documentation Site
  • Security Log Cleanup (3 files, 16 removals, zero crypto on serial)
  • Display Name Feature (NVS-backed, first-boot prompt, settings editor)
  • Crash Fix: ui_connect.c dangling pointer after screen deletion
  • Performance: QR 60% faster, handshake 40%, boot 30%
  • BUG #20 DISCOVERED: SEND fails after 6+ hours idle (SHOWSTOPPER)
  • Security Architecture: 15 docs, 3,243 lines, 191 KB 🔒
  • Four Security Modes: Open / Vault / Fortress / Bunker 🔒
  • HMAC NVS Encryption (BLOCK_KEY1, HMAC_UP) 🔒
  • Post-Quantum: sntrup761 required (not Kyber) 🔒
  • 8 ESP32 Vulnerabilities Cataloged (AR2022-003) 🔒
  • ESP32-P4 Evolution Path (KMU, anti-DPA) 🔒
  • Bug #20 Demoted: SHOWSTOPPER to KNOWN 🔒
  • Bug #21: SD Card Phantom Counter 🔒
  • MILESTONE 20: Hardware Security Architecture 🔒
  • SEC-01 CLOSED: sodium_memzero on 123KB PSRAM cache (4 call sites) 🛡️
  • SEC-02 CLOSED: HMAC NVS vault (eFuse BLOCK_KEY1, auto-provisioned) 🛡️
  • SEC-04 CLOSED: Auto-lock screen (60s timeout, memory wipe) 🛡️
  • SEC-05 CLOSED: Device-bound HKDF (chip MAC in info) 🛡️
  • 5/6 Security Findings CLOSED 🛡️
  • MILESTONE 21: Runtime Security + HMAC NVS Vault 🛡️
  • SEC-06 CLOSED: sntrup761 Post-Quantum KEM in Double Ratchet 🔮
  • WORLD FIRST: Quantum-Resistant Message on Dedicated Hardware (2026-03-12 09:16 CET) 🔮
  • SimpleX App Confirms "Quantum Resistant" for SimpleGo Contact 🔮
  • Five Encryption Layers Per Message (was four before MEGABLAST) 🔮
  • 6/6 Security Findings ALL CLOSED 🔮
  • sntrup761 ESP-IDF Component (PQClean, github.com/saschadaemgen/sntrup761) 🔮
  • PQ State Machine (3 receive cases, anti-downgrade, wire format byte-identical) 🔮
  • Background Pre-Computation (1.85s keygen hidden from user) 🔮
  • PSRAM Crypto Task (80 KB, safe: no NVS writes, memory-mapped SHA-512) 🔮
  • MILESTONE 22: Post-Quantum Double Ratchet (Codename MEGABLAST) 🔮
  • NVS Partition 128 KB to 1 MB (128 PQ contacts at 5.7 KB) 🎨
  • QR Connection Flow: 16 Live Status Stages with Auto-Navigation 🎨
  • PQ Chat Header: Quantum-Resistant / Negotiating / Standard 🎨
  • Global PQ Toggle in Settings (new connections only) 🎨
  • Bug #22 Root Cause: Settings timer cleanup (not stack overflow) 🎨
  • Bug #23: Heap alloc for 5.7 KB ratchet_state_t (was stack) 🎨
  • Bug #24: Chat + Settings restore after lock screen 🎨
  • Bug #26: PQ NVS ghost cleanup (7 keys, 5.2 KB per contact) 🎨
  • Per-Contact PQ Toggle: Impossible (State Machine Analysis) 🎨
  • BACKLOG.md (7 categories, 36 entries) 🎨
  • Bug #30 CLOSED: subscribe_all 7x->1x (QR 5590->650ms, boot 16->9s) ⚡
  • Shared Statusbar Module (FULL+CHAT, 4 screens migrated) ⚡
  • Splash Screen Redesign (animated boot progress, 9 stages) ⚡
  • Matrix Rain Screensaver (canvas PSRAM, 20 FPS, 3 palettes) ⚡
  • NTP Non-Blocking + Configurable Timezone (UTC-12 to +14) ⚡
  • Lock Timer Configurable (5s to 15min, 7 levels) ⚡
  • Pending Contact Abort on Back-Navigation ⚡
  • 3 Crashes Resolved (SPI2 splash, NVS PSRAM, MMU WiFi) ⚡
  • Bug #31 CLOSED: Network Auto-Reconnect (exponential backoff 2s-60s) ⚡
  • Developer Screen Deleted ⚡
  • 42d Bitmap Boot Reset (CONNECT_SCANNED spam eliminated) ⚡
  • Queue Rotation: QADD/QKEY/QUSE/QTEST Protocol Operational 🔄
  • Live Server Switch (no reboot, credentials in RAM + NVS) 🔄
  • 21 Preset SMP Servers (14 SimpleX, 6 Flux, 1 SimpleGo) 🔄
  • SEC-07: TLS Fingerprint Verification at 4 Connection Points 🔄
  • Server-Switch Override (protects existing contacts) 🔄
  • Bug #32 CLOSED (subscribe_all restored after S48 removal) 🔄
  • 3 Critical Protocol Rules: v1-v4 versions, Nothing forbidden, per-contact snd_id 🔄
  • Dual-TLS: ~1,500 bytes SRAM per connection confirmed 🔄
  • DH Key Separation (new server keys vs old peer keys) 🔄
  • Unlimited Consecutive Queue Rotations (4 verified with PQ) 🔄
  • Cache Timing Root Cause: Invalidate AFTER Phase 1b, Not Just at Start 🔄
  • Conditional Auth/DH Backup (first rotation only, originals preserved) 🔄
  • rq->snd_id Semantics Fixed (Main Queue, not Reply Queue) 🔄
  • DIAG-Based Analysis: Hex-Dump Key Comparison, Byte-by-Byte 🔄
  • GoChat Support Started (X3DH, HKDF, Ratchet, Zstd documentation) 🔄
  • Mausi Error Documented: Wrong Bug Classification Cost 1 Day 🔄

Session 23: The 7-Step Handshake​

1. App: NEW → Q_A, Invitation
2. ESP32→App: SKEY + CONF Tag 'D' (Q_B + Profile)
3. App: processConf → CONF Event
4. App: LET/Accept Confirmation
5. App→ESP32: KEY + SKEY + Tag 'I'
6. ESP32: Reconnect + SUB + KEY + HELLO
7. Both: CON → "CONNECTED"

Session 22 Correction​

  • HELLO IS needed (for Legacy Path with PHConfirmation 'K')
  • App sends Tag 'I', not 'D' (we send 'D')
  • Modern Path (PHEmpty '_') would skip HELLO, but we use Legacy!

Bug Summary​

Total bugs found and fixed: 71 (69 fixed, #60 identified for SPI3 fix, #61 temp fix)

CategoryCountSessions
Length Prefix bugs7S4, S8
KDF/IV Order bugs3S4, S8
Byte Order bugs1S5
Encoding bugs3S6
NaCl Crypto bugs2S9
Nonce bugs1S10C
Envelope Length bugs1S12-18
Key Management bugs1S19-20
HELLO Format bugs7S21
E2E Version/KEM/NHK bugs5S22
Bidirectional + Receipt bugs8S25
Multi-Contact Routing bugs11S34b

Lessons Learned: 232 (documented in BUG_TRACKER.md)


Protocol Discoveries​

Session 35: KEY Target Correction (Reply Queue, NOT Contact Queue)​

Session 34b found: KEY uses Contact Queue credentials for signing.
Session 35 found: KEY's entityId must be the REPLY QUEUE rcvId.

KEY secures the queue where the PEER will SEND messages.
Peer sends to Reply Queue -> KEY must be on Reply Queue.

WRONG: KEY entityId = contacts[idx].recipient_id (Contact Queue)
RIGHT: KEY entityId = reply_queue_get(idx)->rcv_id (Reply Queue)

Wrong target = phone stuck on "connecting", cannot send HELLO.

Session 35: PSRAM Slots Empty After Reboot for Contact >0​

After boot, only Slot 0 is loaded from NVS.
ratchet_set_active(1) operates on zeroed PSRAM = crypto failure.

Fix: NVS fallback in set_active:
if (psram_slot[idx] is empty) {
load_from_nvs(idx);
}
Same pattern for handshake_set_active().

Session 34 Day 2: KEY Command Credentials (CRITICAL)​

KEY is a Recipient Command on the Contact Queue (NOT Reply Queue):
EntityId: Contact Queue recipientId
Signing Key: Contact Queue rcv_auth_secret
Body: "KEY " + [0x2C] + [44B SPKI]

Server validates: signature against addressed queue's recipient keys.
Using Reply Queue credentials = ERR AUTH (complete mismatch).

Session 34 Day 2: ERR BLOCK Root Cause​

ERR BLOCK = "incorrect block format, encoding or signature size"
Cause: Any write to TLS socket bypassing smp_write_command_block()
sends malformed transmission (missing txCount, txLen, sigLen).

Server reads signature bytes as txCount = total garbage.
Server recovers automatically, reads next 16384-byte block.

Diagnostic: If ERR BLOCK appears BEFORE first instrumented write,
there is an uninstrumented write path.

Session 34 Day 2: crypto_box_beforenm vs crypto_scalarmult​

crypto_scalarmult(out, private, public)
= raw X25519 DH output (32 bytes)

crypto_box_beforenm(out, public, private)
= crypto_scalarmult() + HSalsa20 key derivation

crypto_box_open_easy_afternm() expects beforenm output.
Using scalarmult directly = decrypt failure (ret=-2).

Session 34: SMP v7 Signing Format (1-Byte Session Prefix)​

SMP command signing concatenates: corrId + entityId + command
Length prefixes in signing buffer MUST be 1-byte (not 2-byte Large):

WRONG: [2B corrLen][corrId][2B entLen][entityId][command]
RIGHT: [1B corrLen][corrId][1B entLen][entityId][command]

2-byte prefix causes signature verification failure on server.
Affected: SUB, KEY, NEW commands simultaneously.

Session 32: Delivery Receipt Wire Format (inner_tag 'V')​

After Double Ratchet body decrypt:
'V' + count(1B Word8) + [AMessageReceipt...]

AMessageReceipt:
msg_id(8B Big Endian) + hash_len(1B) + hash(NB, typically 32B SHA256)

Mapping: seq → msg_id registered after SEND
Receipt: msg_id → seq lookup → UI status update to ""

Session 31: SMP Batch Behavior (ROOT CAUSE!)​

Server batches multiple transmissions in single 16384-byte block:
txCount = 2
TX1: SUB OK response (53 bytes)
TX2: MSG delivery (16178 bytes)

Parser had: if (txCount == 1) → discarded entire batch
Fix: if (txCount >= 1) → one character change

batch = True is hardcoded in Transport.hs since v4.
Third-party clients MUST handle txCount > 1.

Session 31: Re-Delivery After Re-Subscribe​

When re-subscribing to a queue, server re-delivers last unACKed MSG.
Client must detect: msg_ns < ratchet->recv → ACK only, no decrypt.

Session 24: A_MSG Format + ChatMessage JSON​

A_MSG Wire Format:
[1B 'M'][8B sndMsgId Int64][1B prevHash len][0|32B hash]
[1B 'M' A_MSG tag][Tail: ChatMessage JSON]

ChatMessage JSON (required!):
{"v":"1","event":"x.msg.new","params":{"content":{"type":"text","text":"..."}}}

Raw UTF-8 fails: "error parsing chat message: not enough input"

Session 24: ACK Protocol​

SMP Flow Control:
1. Server delivers MSG → blocks until ACK
2. Missing ACK = queue backs up!
3. ACK is Recipient Command (rcv_private_auth_key)
4. ACK response: OK (empty) or MSG (next message)

Session 23: 7-Step Handshake (VERIFIED WORKING!)​

Complete Connection Flow:
1. App creates Invitation (NEW → Q_A)
2. ESP32 sends SKEY + CONF Tag 'D' (Q_B + Profile)
3. App processes Confirmation
4. App accepts Confirmation
5. App sends KEY + SKEY + Tag 'I'
6. ESP32: Reconnect + SUB + KEY + HELLO
7. Both: CON -- CONNECTED!

Session 16: Custom XSalsa20​

SimpleX uses NON-STANDARD XSalsa20:
- Standard: HSalsa20(key, nonce[0:16])
- SimpleX: HSalsa20(key, zeros[16]) ← ZEROS!

Community Recognition​

"Amazing project!" - Evgeny Poberezkin, SimpleX Chat Founder

"what you did is impressive...first third-party SMP implementation" - Evgeny

"concurrency is hard." - Evgeny (Session 31, on the txCount bug)

SimpleGo "demonstrates the energy efficiency of resource-based addressing: the device receives packets without continuous polling." - Evgeny Poberezkin, SimpleX Network Technical Architecture (2026)

SimpleGo is confirmed as the FIRST native SMP protocol implementation outside the official Haskell codebase.


Next Steps (Session 51)​

Phase 1: Rotation Polish​

P0: Late-arrival flow (offline contacts during rotation, second TLS)
P1: Refresh timer stop after DONE
P2: Legacy RQ SUB FAILED after rotation
P3: Rotation error handling (timeouts, retries)

Phase 2: Cleanup​

P4: sdmmc DMA errors during tight SRAM windows
P5: our SMP relay fingerprint update
P6: GoChat reference dump (layer-by-layer)

Phase 3: Alpha Release​

P7: Alpha firmware binary for simplego.dev/installer

Milestone Overview​

#MilestoneDateSession
0AgentConfirmation2026-01-278
1CONNECTED2026-02-0823
2First A_MSG2026-02-1124
3App→ESP32 Decrypt2026-02-1425
4Bidirectional Chat2026-02-1425
5Delivery Receipts2026-02-1425
6Ratchet Persistence2026-02-1426
7Multi-Task Bidirectional2026-02-1831
8Full Messenger UI2026-02-1932
9Multi-Contact Architecture2026-02-2334
10Multi-Contact Bidirectional2026-02-2434b
11** Multi-Contact Chat Filter**2026-02-2435
12** Contact Lifecycle**2026-02-2536
13** Encrypted Chat History**2026-02-2737
14** Backlight + SPI Root Cause**2026-03-0138
15** On-Device WiFi Manager**2026-03-0339
16Sliding Window Chat History2026-03-0440
17** Pre-GitHub Stabilization**2026-03-0441
18** Production Code Quality**2026-03-0542
19** Professional Documentation Site**2026-03-0543
20** Hardware Security Architecture**2026-03-0844
21** Runtime Security + HMAC NVS Vault**2026-03-1045
22** MEGABLAST: Post-Quantum Double Ratchet**2026-03-1246

Current Project Status​

Version: v0.1.18-alpha | Last updated: 2026-03-26 Session 50

Firmware​

  • Post-quantum Double Ratchet (sntrup761, five encryption layers)
  • Queue Rotation: unlimited consecutive with live server switch
  • 21 preset SMP servers, SEC-07 TLS fingerprint at 4 connection points
  • NVS 1 MB (128 PQ contacts), HMAC vault, device-bound HKDF
  • QR 16-stage connection flow, shared statusbar, animated splash
  • Matrix screensaver, configurable lock timer, auto-reconnect
  • Boot: ~9 seconds, 6/6 Security Findings CLOSED

Queue Rotation Status​

  • 4 consecutive rotations verified (send, receive, receipts, PQ crypto)
  • Remaining: late-arrival flow, RQ SUB, timer cleanup, error handling

Open Items​

  • Late-arrival flow for offline contacts during rotation
  • GoChat reference dump (layer-by-layer)
  • Alpha firmware binary for simplego.dev/installer

Index updated: 2026-03-26 Session 50 -- Queue Rotation Multi-Fix: Unlimited Consecutive Rotations