Merge rust-bitcoin/rust-bitcoin#7017: key_expression: Add BIP-0032 test vector 4
What changed, and why it matters
This commit only adds a new test case to the project's test suite. It does not change any production code. The new test verifies that the library correctly handles a specific Bitcoin key derivation scenario (BIP-32 test vector 4, involving a private key with a leading zero byte). The test already passes before this commit, so no bug is being fixed here.
No action required. This is a benign test-only addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds vector_4() to key_expression/src/bip32.rs. It exercises BIP-32 hardened child derivation from a seed whose resulting private key has leading zero bytes, using the existing test_path helper. The PR description explicitly states the test passes on master with no code change. No library logic is modified.
Changed components
key_expression/src/bip32.rs (tests only)Inspect captured patch +21 / −0
### key_expression/src/bip32.rs
@@ -2162,6 +2162,27 @@ mod tests {
"xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y");
}
+ #[test]
+ fn vector_4() {
+ // Tests the retention of leading zeros, see btcsuite/btcutil#172.
+ let seed = hex!("3ddd5602285899a946114506157c7997e5444528f3003f6134712147db19b678");
+
+ // m
+ test_path(NetworkKind::Main, &seed, &"m".parse().unwrap(),
+ "xprv9s21ZrQH143K48vGoLGRPxgo2JNkJ3J3fqkirQC2zVdk5Dgd5w14S7fRDyHH4dWNHUgkvsvNDCkvAwcSHNAQwhwgNMgZhLtQC63zxwhQmRv",
+ "xpub661MyMwAqRbcGczjuMoRm6dXaLDEhW1u34gKenbeYqAix21mdUKJyuyu5F1rzYGVxyL6tmgBUAEPrEz92mBXjByMRiJdba9wpnN37RLLAXa");
+
+ // m/0h
+ test_path(NetworkKind::Main, &seed, &"m/0h".parse().unwrap(),
+ "xprv9vB7xEWwNp9kh1wQRfCCQMnZUEG21LpbR9NPCNN1dwhiZkjjeGRnaALmPXCX7SgjFTiCTT6bXes17boXtjq3xLpcDjzEuGLQBM5ohqkao9G",
+ "xpub69AUMk3qDBi3uW1sXgjCmVjJ2G6WQoYSnNHyzkmdCHEhSZ4tBok37xfFEqHd2AddP56Tqp4o56AePAgCjYdvpW2PU2jbUPFKsav5ut6Ch1m");
+
+ // m/0h/1h
+ test_path(NetworkKind::Main, &seed, &"m/0h/1h".parse().unwrap(),
+ "xprv9xJocDuwtYCMNAo3Zw76WENQeAS6WGXQ55RCy7tDJ8oALr4FWkuVoHJeHVAcAqiZLE7Je3vZJHxspZdFHfnBEjHqU5hG1Jaj32dVoS6XLT1",
+ "xpub6BJA1jSqiukeaesWfxe6sNK9CCGaujFFSJLomWHprUL9DePQ4JDkM5d88n49sMGJxrhpjazuXYWdMf17C9T5XnxkopaeS7jGk1GyyVziaMt");
+ }
+
#[test]
fn reject_xpriv_with_non_zero_byte_at_index_45() {
let mut xpriv = base58::decode_check("xprv9wSp6B7kry3Vj9m1zSnLvN3xH8RdsPP1Mh7fAaR7aRLcQMKTR2vidYEeEg2mUCTAwCd6vnxVrcjfy2kRgVsFawNzmjuHc2YmYRmagcEPdU9").unwrap();Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.