Skip to content

Conversation

@rodentrabies
Copy link
Contributor

This implements a proposal in #12805.

I follow the suggestion by @ryanofsky and compare a genesis block hash, extracted from wallet's best block locator, to an chainActive's genesis block hash. If they don't match, the error is reported.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 21, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #15443 (qa: Add getdescriptorinfo functional test by promag)
  • #13756 (wallet: "avoid_reuse" wallet flag for improved privacy by kallewoof)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@gmaxwell
Copy link
Contributor

Genesis block isn't sufficient, a lot of altcoins share genesis blocks. :( Also there should be a way to override, since moving wallet files between forks is a common way of collecting fork coins-- obviously not something you'd want to happen accidentally but fine as an unsupported "you get to keep both pieces" option.

@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch 2 times, most recently from b019568 to da99bd1 Compare October 21, 2018 10:58
@rodentrabies
Copy link
Contributor Author

@gmaxwell, thanks for the suggestion. Just added an override option -allowreusewallets (maybe should be renamed to something clearer). Still working on sufficiency issue. First of all, since CChain::GetLocator builds a vHave sequence deterministically, maybe the whole vectors can be compared, but a lot of forked altcoins share those blocks as well, so I'm looking for an alternative.

@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch from da99bd1 to 81f1124 Compare October 27, 2018 22:19
@rodentrabies
Copy link
Contributor Author

Implemented the new check via FindForkInGlobalIndex. This solution looks at all blocks known to the wallet and not only at a genesis. It may misbehave in case of temporary forks (reorgs), but there seems to be no simple way around that.

This can be tested with the following function test (here two disconnected nodes in regtest mode generate two different chains with the same genesis, so can be used to model fork coins with shared genesis):

        # ...
        self.log.info("Generating initial distinct blockchains")
        self.nodes[0].generate(5)
        self.nodes[1].generate(5)

        self.log.info("Creating wallets")
        w0_path = os.path.join(self.nodes[0].datadir, 'w0')
        w1_path = os.path.join(self.nodes[1].datadir, 'w1')
        self.nodes[0].createwallet(w0_path)
        self.nodes[1].createwallet(w1_path)

        self.log.info("Restarting nodes")  # to close wallets
        self.stop_node(0)
        self.stop_node(1)
        self.start_node(0)
        self.start_node(1)

        self.log.info("Loading wallet")
        print(self.nodes[0].loadwallet(w1_path))  # this should fail with wallet reuse error

Not sure if this needs a separate test though, so any suggestions on which one should have it appended?

@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch from 81f1124 to ddeb3df Compare October 28, 2018 09:44
@meshcollider
Copy link
Contributor

meshcollider commented Nov 10, 2018

It doesn't seem like a good idea to prevent a wallet from opening in the case of even a 1 block reorg IMO. Maybe checking 6 blocks back in the chain or something would be better?

Concept ACK though, I think this is still a nice check to have

A new test file here would be fine too I think, but you also need to fix up the existing tests to work with this change too, travis is failing on some of them

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe walletInstance->WalletLogPrintf the hashes or something too

@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch 2 times, most recently from d22a8a4 to 884781a Compare November 10, 2018 13:57
@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch from 884781a to 9ffb1c6 Compare November 10, 2018 14:06
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this should really be an option?

Copy link
Member

Choose a reason for hiding this comment

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

If there is an option, the name -walletcrosschain might be better.

Copy link
Member

Choose a reason for hiding this comment

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

This comment's described behaviour is definitely wrong: the best known block could be a stale block!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, but this is going away after the @meshcollider's comments are addressed. I didn't have much time lately, will do it sometime the next two weeks.

@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch from 9ffb1c6 to 11f3568 Compare June 8, 2019 20:49
@rodentrabies rodentrabies changed the title wallet: ensure wallet files are not reused across chains [WIP] wallet: ensure wallet files are not reused across chains Jun 8, 2019
@rodentrabies rodentrabies force-pushed the wallet-file-reuse-prevention branch from 11f3568 to dc48765 Compare June 11, 2019 21:10
@DrahtBot
Copy link
Contributor

Needs rebase

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase, so I am closing this for now. Please let me know when you want to continue working on this, so the pull request can be re-opened.

@ryanofsky
Copy link
Contributor

ryanofsky commented Sep 30, 2019

Not sure, but it may be more important to add this check with the new "Open Wallet -> Other..." GUI feature in #15204 to prevent mistakenly loading incompatible wallets.

@rodentrabies
Copy link
Contributor Author

Looks like I completely forgot about this one. Updated and tested the old branch yesterday - https://github.com/mrwhythat/bitcoin/tree/wallet-file-reuse-prevention. Can it be reopened or should I just open another PR?

@fanquake
Copy link
Member

fanquake commented Apr 7, 2020

I'm unable to re-open this PR, so creating a new one should be ok.

@ghost ghost mentioned this pull request Sep 3, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants