-
Notifications
You must be signed in to change notification settings - Fork 329
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
fix(chain): sanitize derivation index before apply changeset #1792
base: master
Are you sure you want to change the base?
fix(chain): sanitize derivation index before apply changeset #1792
Conversation
@notmandatory I am also working on this PR but is not been assigned to me yet. |
If this helps, it appears that #[test]
fn insert_descriptor_should_reject_hardened_steps() {
use bdk_chain::keychain_txout::KeychainTxOutIndex;
// This descriptor has hardened child steps
let s = "wpkh([e273fe42/84h/1h/0h/0h]tpubDEBY7DLZ5kK6pMC2qdtVvKpe6CiAmVDx1SiLtLS3V4GAGyRvsuVbCYReJ9oQz1rfMapghJyUAYLqkqJ3Xadp3GSTCtdAFcKPgzAXC1hzz8a/*h)";
let (desc, _) =
<Descriptor<DescriptorPublicKey>>::parse_descriptor(&Secp256k1::new(), s).unwrap();
// FIXME: This will panic by attempting to derive a script pubkey from a hardened step
let mut indexer = KeychainTxOutIndex::<&str>::new(10);
let _ = indexer.insert_descriptor("keychain", desc);
} |
yes thanks @ValuedMammal I did a similar test 😅 It panics because of So I am going to add the sanitize part in the |
I think it makes sense to handle the error in |
I tried to create such a test but it takes a lot of time to complete #[test]
fn insert_descriptor_maliciously() {
use bdk_chain::keychain_txout::KeychainTxOutIndex;
let s = "wpkh([e273fe42/84h/1h/0h/0h]tpubDEBY7DLZ5kK6pMC2qdtVvKpe6CiAmVDx1SiLtLS3V4GAGyRvsuVbCYReJ9oQz1rfMapghJyUAYLqkqJ3Xadp3GSTCtdAFcKPgzAXC1hzz8a/*)";
let (desc, _) =
<Descriptor<DescriptorPublicKey>>::parse_descriptor(&Secp256k1::new(), s).unwrap();
let changeset: ChangeSet = ChangeSet {
last_revealed: [(desc.descriptor_id(), bdk_chain::BIP32_MAX_INDEX + 1)].into(),
};
let mut indexer_a = KeychainTxOutIndex::<TestKeychain>::new(10);
indexer_a
.insert_descriptor(TestKeychain::External, desc.clone())
.expect("must insert keychain");
indexer_a
.apply_changeset(changeset.clone())
.expect("must apply changeset");
} |
@ValuedMammal just to be sure, the sanitize check has to be only made in |
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.
Approach NACK
The thing with changesets is that they are designed to be loaded from persistence and ideally be fully monotone in nature. Erroring when applying the changeset is against this design principle.
I think the correct solution would be to modify the ChangeSet::last_revealed
values in KeychainTxOutIndex::apply_changeset
to be maxed at 2^31-1.
Whether the descriptor has any hardened steps in the derivation path should be checked in insert_descriptor
(which already returns an error).
fix: #1688
Description
Notes to the reviewers
Changelog notice
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committing