Skip to content
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

[RPC] Fix addwitnessaddress by replacing ismine with producesignature #10788

Merged
merged 1 commit into from Aug 1, 2017

Conversation

achow101
Copy link
Member

Instead of using ismine to check whether an address can be spent by us, make the witness version of the script or address first and then use ProduceSignature with the DummySignatureCreator to check if we can
solve for the script.

This is to fix cases where we don't have all of the private keys (for something like a multisig address) but have the redeemscript so we can witnessify it.

@achow101 achow101 changed the title Replace ismine with producesignature check in witnessifier [RPC] Fix addwitnessaddress by replacing ismine with producesignature Jul 11, 2017
@sipa
Copy link
Member

sipa commented Jul 11, 2017

Concept ACK, but you'll need to adapt the tests (there is a test in segwit.py which specifically tests for this behaviour).

@achow101
Copy link
Member Author

@sipa I have adapted segwit.py to reflect the new behavior.

@jnewbery
Copy link
Contributor

Travis failed on an unrelated call to encryptwallet() in wallet-dump.py: https://travis-ci.org/bitcoin/bitcoin/jobs/252653271 . I've restarted the job.

(encryptwallet() causes the node to shutdown, so I guess there's a race between the node shutting down and responding to the RPC. That's unrelated to this PR and is something we should think about fixing independently)

Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

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

ACK.

@sipa
Copy link
Member

sipa commented Jul 18, 2017

@sdaftuar Would you mind reviewing this?

@sipa
Copy link
Member

sipa commented Jul 18, 2017

utACK db5cd10bbe1688a5e05e558d1323f8cab923567c, but needs squash before merge.

Copy link
Member

@sdaftuar sdaftuar left a comment

Choose a reason for hiding this comment

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

Seems like this is the right general direction to me (seems vastly simpler than what happens in IsMine()), though I have two concerns that I need to think more about before I can ACK:

  • The protection against accidentally allowing an uncompressed pubkey in a segwit script via addwitnessaddress has now moved from the logic in IsMine() to the VerifyScript() call at the end of ProduceSignature. First, I think that's generally surprising and I could imagine someone not understanding that it's important that we call VerifyScript at the end of ProduceSignature. But second, I think it's unexpected that the script flags passed to VerifyScript in ProduceSignature (which are just our regular policy script flags) are what we're relying on for this wallet behavior. The policy script flags are not something that generally affects our wallet, so I think it'd be unexpected if someone tweaked theirs and got different wallet behavior as a result.

  • Along the lines of the above, it seems like we could use some tests to ensure that IsMine() interacts with ProduceSignature() as expected. In the above example of someone tweaking their policy script flags (eg to turn off SCRIPT_VERIFY_WITNESS_PUBKEYTYPE) then I think you could get into a situation where you could add an address to your wallet that fails IsMine(). This is pretty edge-case, but I want to spend more time thinking about whether other kinds of inconsistencies could exist between IsMine() and this ProduceSignature(...) method.

@@ -459,13 +459,15 @@ def run_test(self):
self.mine_and_test_listunspent(unsolvable_after_importaddress, 1)
self.mine_and_test_listunspent(unseen_anytime, 0)

# addwitnessaddress should refuse to return a witness address if an uncompressed key is used or the address is
# not in the wallet
# addwitnessaddress should refuse to return a witness address if an uncompressed key is used
# note that no witness address should be returned by unsolvable addresses
# the multisig_without_privkey_address will fail because its keys were not added with importpubkey
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 should be updated/removed.

@sipa
Copy link
Member

sipa commented Jul 26, 2017

@sdaftuar Would an explicit VerifyScript call (with consensus + compressed pubkey flags) after ProduceSignature help alleviate your concerns?

Instead of using ismine to check whether an address can be spent by us,
make the witness version of the script or address first and then use
ProduceSignature with the DummySignatureCreator to check if we can
solve for the script.

Also fixes test cases to reflect this change.
@achow101
Copy link
Member Author

I have updated this with @sipa's suggestion and squashed.

@laanwj
Copy link
Member

laanwj commented Aug 1, 2017

utACK e222dc2

@laanwj laanwj merged commit e222dc2 into bitcoin:master Aug 1, 2017
laanwj added a commit that referenced this pull request Aug 1, 2017
…oducesignature

e222dc2 Replace ismine with producesignature check in witnessifier (Andrew Chow)

Pull request description:

  Instead of using ismine to check whether an address can be spent by us, make the witness version of the script or address first and then use ProduceSignature with the DummySignatureCreator to check if we can
  solve for the script.

  This is to fix cases where we don't have all of the private keys (for something like a multisig address) but have the redeemscript so we can witnessify it.

Tree-SHA512: 371777aee839cceb41f099109a13689120d35cf3880cde39216596cc2aac5cc1096af7d9cf07ad9306c3b05c073897f4518a7e97f0b88642f1e3b80b799f481e
@achow101 achow101 deleted the fix-addwitnessaddress branch August 29, 2017 15:28
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants