task: replace unwrap() calls in genesis state decoding (PM-20204)#766
Open
task: replace unwrap() calls in genesis state decoding (PM-20204)#766
Conversation
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>
Contributor
…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>
…into task/PM-20204-node-panic-on-startup
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.








Overview
Replace three
unwrap()calls inrun_nodegenesis state decoding with adecode_genesis_statehelper that returns typed errors viasc_cli::Error::Input. This prevents the node from panicking on startup when the chain spec contains a missing, non-string, or invalid-hexgenesis_stateproperty. Adds a 256 MiB size guard against adversarial chain specs.Addresses Least Authority audit finding Issue M (High severity).
🎫 PM-20204 📐 Engineering
Changes
node/src/command.rs— Extractdecode_genesis_statefunction from inlineunwrap()chain inrun_node. Returnssc_cli::Result<Vec<u8>>with descriptiveError::Inputmessages for each failure mode (missing key, non-string value, invalid hex, oversized payload). Matches the existing error handling pattern used for seed file loading in the same module.changes/changed/fix-genesis-state-decode-panic.md🗹 TODO before merging
📌 Submission Checklist
🧪 Testing Evidence
5 new unit tests for
decode_genesis_stateadded tonode/src/command.rs:Validation:
cargo clippy -p midnight-node -- -D warnings(0 warnings),cargo fmt -- --check(clean).🔱 Fork Strategy
Links