Skip to content

Conversation

furszy
Copy link
Member

@furszy furszy commented Nov 26, 2024

Ensure legacy wallet migration skips the never standard bare multisig with +3 keys
and consensus-invalid multisig scripts. Treating them as valid causes migration to
crash because we are enforcing this rules within the descriptors parsing logic.

Testing Notes:
This can be verified by cherry-picking and running the test commit on master.
It will crash there but pass on this branch.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 26, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31378.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

No conflicts as of last run.

Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruling out consensus-invalid scripts makes sense, but discarding non-standard scripts is a much bigger leap. Also it would be a wack-a-mole: does the migration crash on any non-standard script? How much of that do you want to cover? Is it not possible to make the migration not crash on valid but not standard scripts instead of changing IsMine for those?

@furszy
Copy link
Member Author

furszy commented Nov 27, 2024

Ruling out consensus-invalid scripts makes sense, but discarding non-standard scripts is a much bigger leap. Also it would be a wack-a-mole: does the migration crash on any non-standard script? How much of that do you want to cover?

Ok, I might have made the PR/commit description too broad when the actual changes are very specific.
Migration does not crash on all non-standard scripts, it only crashes on scripts that fail to be parsed by the descriptors' logic. The specific non-standard crash this PR addresses is a bare multisig with +3 keys. And I don't think we want to cover all non-standard rules; we just need to handle the ones also applied by the current descriptors parsing logic.

Ultimately, we’re preserving/freezing the legacy wallet’s existing behavior ahead of its removal. We shouldn’t allow spendability or migration (even though it’s not possible anyway) of scripts that were not functional during the lifetime of the legacy wallet anyway.

Is it not possible to make the migration not crash on valid but not standard scripts instead of changing IsMine for those?

It’s possible, but it would mean duplicating more code. Still, at least for this case, I don't think it matters much. #30328 inlines the IsMine() logic into the migration code, so the entire legacy wallet support can be removed by the next release.
In other words, duplicating code now won’t change the outcome; if #30328 proceeds, the code will end up been consolidated into the same migration function anyway.

I'll update the PR description to reflect the actual scope of this fix. it's not as broad as I initially described.

…scripts as ours

Ensure legacy wallet migration skips the never standard bare multisig with +3 keys
and consensus-invalid multisig scripts. Treating them as valid causes migration to
crash because we are enforcing this rules within the descriptors parsing logic.
@furszy furszy force-pushed the 2024_wallet_migration_multisig_crash branch from d641931 to 74fa29e Compare December 3, 2024 14:39
@achow101
Copy link
Member

achow101 commented Dec 5, 2024

cdaa3a5 "wallet: bugfix, stop treating multisig consensus-invalid/unspendable scripts as ours" modifies legacy IsMine(), ostensibly to mix issues in migration. However, I don't think doing that makes sense that this point as legacy IsMine is going to be removed from migration with #30328, and any changes to it may result in incompatibilities with legacy wallets and migrated wallets.

I think that fixes to migration should be limited to the migration only code. Perhaps it would be easier to cherry pick the tests and migration specific fixes into #30328?

Copy link
Member Author

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cdaa3a5 "wallet: bugfix, stop treating multisig consensus-invalid/unspendable scripts as ours" modifies legacy IsMine(), ostensibly to mix issues in migration. However, I don't think doing that makes sense that this point as legacy IsMine is going to be removed from migration with #30328, and any changes to it may result in incompatibilities with legacy wallets and migrated wallets.

I'm not going too strong over this point but.. it's hard for me to see the incompatibilities when the changes block two consensus-invalid scripts and a +10 year-old non-standard script that is already blocked in other parts of the legacy wallet. Arguably, this could also be labeled as a legacy wallet bugfix.

I think that fixes to migration should be limited to the migration only code. Perhaps it would be easier to cherry pick the tests and migration specific fixes into #30328?

I was aiming to keep #30328 purely as a refactoring without mixing in bug fixes. Reviewing the PR's matching functionality has been challenging in its current state, so I think that it would be good if we don’t expand it more than strictly necessary.

Note: If, after this comment, the general consensus is still to leave IsMine untouched, maybe postponing this PR until after #30328 would be the path that satisfies everyone?

@achow101
Copy link
Member

achow101 commented Dec 6, 2024

Note: If, after this comment, the general consensus is still to leave IsMine untouched, maybe postponing this PR until after #30328 would be the path that satisfies everyone?

Then let's do it afterwards.

@Sjors
Copy link
Member

Sjors commented Dec 19, 2024

Is this now pending #31495 instead of the closed ##30328?

@luke-jr
Copy link
Member

luke-jr commented Jan 8, 2025

we are enforcing this rules within the descriptors parsing logic.

That sounds dumb. Why are we?

@pinheadmz
Copy link
Member

@luke-jr can you rephrase your comment in a friendlier way please

@furszy
Copy link
Member Author

furszy commented Jan 9, 2025

we are enforcing this rules within the descriptors parsing logic.

That sounds dumb. Why are we?

I assume this was simply because there was no need to represent them in the descriptors' language. They've been non-standard for at least the past 10 years now.

However, there's no documentation about it. This restriction has always been present; it was introduced in the first commit that added descriptors in #13697.

We could relax the parsing restriction if a real use case arises. Until then, the descriptor's inference and parsing must allow for round-trips.

That being said, this PR might not end up getting merge. #31495 contains a general round-trip check that does not touch the legacy wallet IsMine code (haven't reviewed it in detail yet). And the fix for the descriptors issue is in #31404.

@maflcko
Copy link
Member

maflcko commented Jan 22, 2025

Could turn into draft while the CI is failing?

@furszy furszy marked this pull request as draft January 22, 2025 14:30
@DrahtBot
Copy link
Contributor

🤔 There hasn't been much activity lately and the CI seems to be failing.

If no one reviewed the current pull request by commit hash, a rebase can be considered. While the CI failure may be a false positive, the CI hasn't been running for some time, so there may be a real issue hiding as well. A rebase triggers the latest CI and makes sure that no silent merge conflicts have snuck in.

1 similar comment
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 6, 2025

🤔 There hasn't been much activity lately and the CI seems to be failing.

If no one reviewed the current pull request by commit hash, a rebase can be considered. While the CI failure may be a false positive, the CI hasn't been running for some time, so there may be a real issue hiding as well. A rebase triggers the latest CI and makes sure that no silent merge conflicts have snuck in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants