Skip to content

task: replace unwrap() calls in genesis state decoding (PM-20204)#766

Merged
gilescope merged 6 commits into
mainfrom
task/PM-20204-node-panic-on-startup
Feb 27, 2026
Merged

task: replace unwrap() calls in genesis state decoding (PM-20204)#766
gilescope merged 6 commits into
mainfrom
task/PM-20204-node-panic-on-startup

Conversation

@m2ux

@m2ux m2ux commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace three unwrap() calls in genesis state decoding with proper error propagation, preventing node panics on malformed chain specifications. Addresses Least Authority audit finding Issue M (High severity).

🎫 PM-20204 📐 Engineering


Motivation

The node panics on startup when the chain specification contains a missing, non-string, or invalid-hex genesis_state property. Three unwrap() calls in run_node (node/src/command.rs) abort the process instead of returning actionable error messages. This prevents operators from diagnosing configuration problems and is classified as a High severity finding in the Q4 2025 Least Authority security audit (Issue M, parent epic PM-19974).


Changes

  • decode_genesis_state function — Extracted from inline run_node code. Returns sc_cli::Result<Vec<u8>> with descriptive sc_cli::Error::Input errors for: missing key, non-string value, invalid hex encoding
  • Size guard — 256 MiB upper bound (MAX_GENESIS_STATE_BYTES) prevents unbounded allocation from adversarial chain specs
  • Unit tests — 5 tests covering: valid hex, empty hex, missing key, non-string value, invalid hex
  • Change filechanges/changed/fix-genesis-state-decode-panic.md for release notes

📌 Submission Checklist

  • Changes are backward-compatible (or flagged if breaking)
  • Pull request description explains why the change is needed
  • Self-reviewed the diff
  • I have included a change file, or skipped for this reason: N/A
  • If the changes introduce a new feature, I have bumped the node minor version
  • Update documentation (if relevant)
  • No new todos introduced

🔱 Fork Strategy

  • Node Runtime Update
  • Node Client Update
  • Other
  • N/A

🗹 TODO before merging

  • Ready for review
  • Squash-merge with edited commit message (remove Co-authored-by trailers)

Audit finding Issue M: Node can panic on startup due to unwrap()
calls in genesis state decoding (node/src/command.rs).

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.16

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 96
LOW LOW 12
INFO INFO 83
TRACE TRACE 0
TOTAL TOTAL 191
Metric Values
Files scanned placeholder 31
Files parsed placeholder 31
Files failed to scan placeholder 0
Total executed queries placeholder 73
Queries failed to execute placeholder 0
Execution time placeholder 9

m2ux and others added 4 commits February 24, 2026 16:15
…pagation

Extract `decode_genesis_state` function from `run_node` to replace three
chained unwrap() calls that panic when chain spec properties contain
missing, non-string, or malformed hex genesis_state values.

- Return typed sc_cli::Error::Input with descriptive messages
- Add 256 MiB upper bound validation on decoded genesis state size
- Add 7 unit tests covering all error paths and boundary conditions

Resolves: PM-20204 (Least Authority audit Issue M)
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Drop decode_genesis_state_oversized and decode_genesis_state_at_size_limit
tests that each allocated ~512 MiB to verify a trivial integer comparison.
The size guard remains in the implementation; the five remaining tests cover
all three error paths, the happy path, and the empty-input edge case.

Co-authored-by: Cursor <cursoragent@cursor.com>
@m2ux m2ux marked this pull request as ready for review February 24, 2026 17:59
@m2ux m2ux requested a review from a team as a code owner February 24, 2026 17:59
@gilescope gilescope assigned gilescope and unassigned gilescope and m2ux Feb 25, 2026
@gilescope gilescope added this pull request to the merge queue Feb 27, 2026
Merged via the queue into main with commit 4e38bbd Feb 27, 2026
36 of 38 checks passed
@gilescope gilescope deleted the task/PM-20204-node-panic-on-startup branch February 27, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants