-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(scrypt): Fix scrypt JSON parsing for p and r #4611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
sergei-boiko-trustwallet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks legit, thanks for the fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a critical copy-paste bug in the scrypt parameter JSON parsing logic. The bug caused the p and r parameters to always use default values when parsing JSON, even when different values were explicitly provided, because the code was incorrectly checking the n key instead of the respective p and r keys.
Changes:
- Fixed conditional checks for
pparameter to useCodingKeys::SP::pinstead ofCodingKeys::SP::n - Fixed conditional checks for
rparameter to useCodingKeys::SP::rinstead ofCodingKeys::SP::n
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (json.count(CodingKeys::SP::p) != 0) | ||
| p = json[CodingKeys::SP::p]; | ||
| if (json.count(CodingKeys::SP::n) != 0) | ||
| if (json.count(CodingKeys::SP::r) != 0) | ||
| r = json[CodingKeys::SP::r]; |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix correctly addresses the copy-paste bug where p and r parameters were checking the wrong JSON key (n instead of their respective keys). However, there is no test coverage that specifically validates the conditional parsing behavior when p or r keys are missing from JSON. Consider adding a unit test that verifies the default values are used when these keys are absent, and that custom values are correctly parsed when present.
|
@MatusKysel, from the first glance, the fix is correct, but the implementation in general looks wrong because we shouldn't use default |
Thanks for the catch. The fix here only corrects the key checks for p/r; the “default if missing” behavior was already present via the struct defaults (same pattern as PBKDF2 iterations). So the patch doesn’t introduce that behavior. If we want to treat missing n/p/r as invalid, I agree that’s a separate behavior change. We’d probably want to enforce required fields (and likely do the same for PBKDF2) to avoid silently falling back and to surface malformed keystores explicitly. Happy to follow up with a separate PR if that’s the direction |
Description
Fixed the JSON parsing copy-paste bug so p and r are only read when their own keys are present, preventing defaults from being silently used. Updated logic in
src/Keystore/ScryptParameters.cppto checkCodingKeys::SP::pandCodingKeys::SP::rinstead ofCodingKeys::SP::n.