fix: replace H160::from_slice().unwrap() with proper error handling#666
Open
eval-exec wants to merge 3 commits into
Open
fix: replace H160::from_slice().unwrap() with proper error handling#666eval-exec wants to merge 3 commits into
eval-exec wants to merge 3 commits into
Conversation
Replace all 32 instances of H160::from_slice(...).unwrap() across the codebase with proper error handling: - For functions returning Result: use .map_err(|e| format!(...))? - For closures inside .map() on Result: convert to .and_then() - For closures inside .map() on Option: convert to .and_then().ok() - For format!() calls: extract H160 to a variable first - For guarded/safe sites in signer.rs: use .expect() with clear message - For [0..20] slicing: add bounds check via .get(0..20) before H160 Fixes the highest-frequency panic pattern in the codebase (~30 sites that could crash from malformed address data from RPC/user input).
59f2145 to
b3f0930
Compare
Member
|
Consider adding a helper function. |
Extract the repeated pattern of H160::from_slice(x).map_err(...) into two helper functions in src/utils/other.rs: - h160_from_slice(data, context) -> Result<H160, String> - h160_from_slice_prefix(data, context) -> Result<H160, String> (takes first 20 bytes, with bounds check) Replace all inline H160::from_slice error handling across 8 files with calls to these helpers. Net reduction of 7 lines while making error messages consistent and code more readable.
doitian
approved these changes
Jun 18, 2026
chenyukang
approved these changes
Jun 18, 2026
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.
Summary
Replace all 32 instances of H160::from_slice(...).unwrap() across the codebase with proper error handling.
Problem
H160::from_slice() returns Result<H160, String>, but the codebase had 32 sites where .unwrap() was called on this result. These would panic/crash the CLI if:
This was the highest-frequency panic pattern identified in the codebase audit.
Changes
Files Changed
Verification