-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: identity derivation path changes #48
Conversation
WalkthroughThe pull request introduces several modifications across multiple files, primarily focusing on the Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (5)
dash/src/blockdata/transaction/special_transaction/coinbase.rs (2)
98-100
: Consider adding validation for decoded values.While the decoding logic is correct, consider adding validation for the decoded values:
- Validate
best_cl_height
is not greater than the current height- Ensure
asset_locked_amount
is within reasonable boundsHere's a suggested improvement:
- let best_cl_height = if version >= 3 { Some(read_compact_size(r)?) } else { None }; - let best_cl_signature = - if version >= 3 { Some(BLSSignature::consensus_decode(r)?) } else { None }; - let asset_locked_amount = if version >= 3 { Some(u64::consensus_decode(r)?) } else { None }; + let best_cl_height = if version >= 3 { + let height = read_compact_size(r)?; + if height > u32::MAX as u64 { + return Err(encode::Error::ParseFailed("best_cl_height exceeds maximum value")); + } + Some(height) + } else { None }; + let best_cl_signature = if version >= 3 { + Some(BLSSignature::consensus_decode(r)?) + } else { None }; + let asset_locked_amount = if version >= 3 { + let amount = u64::consensus_decode(r)?; + if amount > consensus::MAX_MONEY { + return Err(encode::Error::ParseFailed("asset_locked_amount exceeds maximum value")); + } + Some(amount) + } else { None };
Line range hint
124-142
: Consider expanding test coverage.The current test only verifies size calculations. Consider adding tests for:
- Decoding invalid data (error cases)
- Edge cases for optional fields
- Version compatibility checks
- Boundary values for
best_cl_height
andasset_locked_amount
Would you like me to help generate additional test cases?
dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs (1)
95-96
: Consider adding documentation for version-specific behavior.The code conditionally decodes
quorum_index
only for versions 2 and 4. Consider adding a comment explaining why these specific versions include a quorum index, as this appears to be protocol-critical behavior.dash/src/consensus/encode.rs (1)
968-970
: Consider using constants for magic numbersWhile the simplified conditional structure is good, consider defining constants for the magic numbers 253 and 65536 to improve code maintainability and readability.
+const COMPACT_SIZE_THRESHOLD_1: u32 = 253; +const COMPACT_SIZE_THRESHOLD_2: u32 = 65536; pub fn compact_size_len(value: u32) -> usize { let mut size: usize = 0; - if value < 253 { + if value < COMPACT_SIZE_THRESHOLD_1 { size += 1; - } else if value < 65536 { + } else if value < COMPACT_SIZE_THRESHOLD_2 { size += 3; } else { size += 5; } size }dash/src/bip32.rs (1)
Line range hint
401-411
: Preserve backward compatibility with clear deprecation notice.The old method has been renamed but should include a deprecation notice to guide users to the new implementation.
Add a deprecation attribute:
+#[deprecated(since = "0.1.0", note = "Use identity_registration_path instead which uses hardened child numbers")] pub fn identity_registration_path_child_non_hardened(network: Network, index: u32) -> Self {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
dash/src/bip32.rs
(4 hunks)dash/src/blockdata/block.rs
(0 hunks)dash/src/blockdata/transaction/special_transaction/coinbase.rs
(3 hunks)dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs
(4 hunks)dash/src/consensus/encode.rs
(5 hunks)
💤 Files with no reviewable changes (1)
- dash/src/blockdata/block.rs
🔇 Additional comments (12)
dash/src/blockdata/transaction/special_transaction/coinbase.rs (2)
21-22
: LGTM! Import organization looks good.
The imports are properly organized and all imported items are used in the code.
117-117
: Formatting looks good.
dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs (3)
21-26
: LGTM! Import organization improves readability.
The grouping of related consensus::encode
imports enhances code organization and makes dependencies clearer.
80-81
: LGTM! Line split improves readability.
The multi-line formatting of the write_fixed_bitset
call improves code readability while maintaining the same functionality.
165-167
: LGTM! Test imports organization improves readability.
The multi-line formatting of local imports in the test module enhances code organization and maintainability.
dash/src/consensus/encode.rs (4)
36-36
: LGTM: Import section formatting
The added blank line after imports improves code readability by clearly separating imports from the rest of the code.
939-939
: LGTM: Improved error message clarity
The error message is now more concise and direct, making it easier to understand the failure condition.
1003-1007
: LGTM: Improved function signature formatting
The updated function signature formatting improves readability while maintaining proper parameter alignment according to Rust style guidelines.
1455-1456
: LGTM: Improved test vector formatting
The test vector initialization is now more readable with proper line breaks and indentation.
dash/src/bip32.rs (3)
412-420
: LGTM: New identity registration path uses hardened indices.
The implementation correctly uses hardened child numbers which provides better security by preventing public key derivation.
422-432
: LGTM: Improved path structure with separate indices.
The implementation correctly:
- Uses hardened index for identity (improved security)
- Uses non-hardened index for top-up (allows public derivation)
- Separates concerns between identity and top-up indices
1837-1843
: LGTM: Comprehensive test coverage for path changes.
The tests thoroughly verify:
- Identity registration with hardened indices
- Identity top-up with separated indices
- Path structure correctness for both networks
Run the following script to verify test coverage:
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests