fix(scrypt): Fix scrypt JSON parsing for p and r#4611
fix(scrypt): Fix scrypt JSON parsing for p and r#4611MatusKysel wants to merge 1 commit intotrustwallet:masterfrom
Conversation
sergei-boiko-trustwallet
left a comment
There was a problem hiding this comment.
Looks legit, thanks for the fix!
There was a problem hiding this comment.
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.
|
@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 |
|
Closed due to #4680 |
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.