agents/skills/injectable/l1/state-sync-pruning/SKILL.md
L1 trigger - audits state sync, snapshot integrity, checkpoint trust, pruning race conditions, and state growth attacks.
npx skillsauth add plamentsv/plamen state-sync-pruningInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
L1 trigger:
L1_PATTERN=trueAND (sync/ORsnap_syncORfast_syncORstatesyncORpruningORsnapshot/detected in recon subsystem map) Inject Into:depth-state-traceordepth-edge-caseLanguage: Go and Rust Finding prefix:[SS-N]Status: v0.1 draft, Round 4 exemplars pending
Recon identifies state sync or pruning code. State sync is the mechanism by which a new node catches up without replaying the entire history; pruning is how an existing node garbage-collects old state. Both are subtle: a bug in either can corrupt the node's state silently, leading to later divergence.
Identify the sync mode(s) supported:
| Mode | Description | Trust model | |---|---|---| | Full sync | Replay every block from genesis | Trustless (modulo consensus rules) | | Fast sync | Download headers + recent state trie | Trusts weak subjectivity checkpoint | | Snap sync (Ethereum) | Download flat account snapshots in ranges | Healing phase verifies root | | Warp sync (Parity) | Download a snapshot of state at a past block | Trusts snapshot root | | State sync (Cosmos) | Download state at a trusted height from peers | Trusts a configured height/hash | | Checkpoint sync (Beacon) | Trusts a recent finalized checkpoint root | Weak subjectivity | | Portal Network | Content-addressed historical storage | Trustless per item |
Write the mode(s) into the finding header.
Every non-full sync mode depends on a root or checkpoint. Verify the trust chain:
Tag: [SYNC-TRUST:{source}:{validation}]
Historical exemplar class: unsigned-checkpoint sync in early Cosmos clients; trust-anchor bypass in early beacon chain clients.
For any sync mode that downloads bulk state (snap, warp, state sync):
Tag: [SNAPSHOT:{integrity-class}]
Pruning removes old state to save disk. Bugs here corrupt the active state.
eth_getProof reading historical state while pruner deletes it)A persistence unit is any tuple of writes that must commit or abort together for higher-level state to stay consistent (block body + receipts + state root; header + total-difficulty + canonical-hash mapping; snapshot chunk + chunk manifest). A node crash BETWEEN the writes of a logical unit leaves partially-applied state that the restart path may silently accept.
Methodology — enumerate as a table, one row per logical unit:
| Logical Unit | Writes In Order | Fence (txn commit / fsync / batch) | Restart Recovery | Torn-Write Risk |
For each row:
write + fsync to a file), verify that either the write is
≤ 4 KiB (page-atomic on most filesystems) or the file uses a
write-then-rename pattern with fsync on the parent directory.rename is NOT atomic over an existing file on
pre-Windows-10 / some network filesystems; MoveFileEx with
MOVEFILE_REPLACE_EXISTING is required. Flag any code that assumes
POSIX rename semantics cross-platform.fsync.Tag: [PERSIST-ATOMIC:{unit}:{torn-scenario}]. Severity High by default
(silent state corruption on restart is a safety violation); Critical when
the partial state is accepted as canonical without any reconciliation.
Tag: [PRUNE:{race-or-boundary}]
Attacker crafts transactions that bloat state at low cost, outpacing pruning.
SSTORE of a key) — not a client bug but a client should bound per-tx state growthTag: [STATE-GROW:{mechanism}:{cost}]
| State | Test | Expected | Observed | |---|---|---|---| | Genesis-only sync | no blocks to sync | idempotent | | | Sync from stale checkpoint | checkpoint from N finality periods ago | rejected | | | Peer serves wrong root | chunks that verify against a different root | detected + peer banned | | | Reorg mid-sync | fork-choice changes head during sync | handled cleanly | | | Prune to latest | pruning window = 0 | refuses if below consensus safety | | | Prune across finality | prune past finalized | refused | | | Disk full during sync | out-of-space | graceful error | |
[CONFORMANCE-PASS] (sync correctness test) > [FUZZ-PASS] > [LSP-TRACE]Geth snap-sync state corruption after abnormal termination (Issue #30229, 2024) — in one sync cycle, the storage trie for an account was fully synced and persisted but the account trie was not yet flushed. On restart, restart logic missed topmost trie nodes in 1-2 paths, producing inconsistent state that didn't match the synced state root. The node silently went off-consensus. go-ethereum #30229. Skill catch point: Section 4b — crash-recovery atomicity. For every 2PC-like flush sequence, test with kill -9 at each flush boundary.
Snapping Snap Sync — adversarial sync source attacks (USENIX Security '23, Taverna-Paterson) — snap sync protocol trusts peer-provided state without sufficient on-chain verification. Attacker controlling a sync peer can plant invalid state that survives restart, permanently deviating the victim from consensus. Practical Attacks on Go Ethereum Synchronising Nodes. Skill catch point: Section 3a — every received trie node must be verified against the proof root before writing to disk. No provisional writes. No "trust peer now, verify later."
Geth debug_traceTransaction historical DoS — unbounded custom JS tracer, later restricted. Demonstrates the state-growth / resource-exhaustion pattern in sync-adjacent code.
Ethereum Shanghai EIP-3529 (SSTORE refund reform, 2021) — response to state-growth exploits where attackers abused the gas-refund mechanism to inflate state at negative cost. EIP-3529. Skill catch point: Section 5a — storage cost must cover amortized sync cost, not just write cost.
Insert as new Section 4e (MANDATORY test): Geth issue #30229 shows crash-recovery atomicity is a hot bug class. Test methodology:
kill -9 at the boundary between phasesTag: [SYNC-ATOMIC:{flush-seq}:{kill-point}]
start_sync / sync_loop)consensus-safety-invariants (fork-choice pruning interaction), execution-client-hardening (storage pricing)depth-state-trace, depth-edge-casedocs/l1-mode/severity-matrix.mddevelopment
Prepare Solidity projects for a security audit — test coverage, test quality, NatSpec docs, code hygiene, dependency health, best-practice enforcement, deployment readiness, and project documentation checks. Generates a scored Audit Readiness Report and optionally runs static analysis. Trigger on: "prepare for audit", "audit readiness", "pre-audit check", "audit prep", "NatSpec check", or any request to review a Solidity codebase before a security review.
development
Launch the Plamen deterministic Web3 security audit pipeline
development
Run the Plamen smart-contract audit wizard in Codex
testing
Launch the Plamen deterministic L1 infrastructure audit pipeline