Skip to content

Conversation

@sstone
Copy link
Contributor

@sstone sstone commented Nov 29, 2021

Check that descriptors returned by external signers have been parsed properly when creating a new wallet.
See #23627 for context.

The problem is that parsing an invalid descriptor will return null which is not checked for in CWallet::SetupDescriptorScriptPubKeyMans().

I'm not completely sure what the best fix is since there several strategies for dealing with errors in the current codebase but the proposed fix is very simple and consistent with other validation checks in CWallet::SetupDescriptorScriptPubKeyMans().

@laanwj laanwj added the Wallet label Nov 29, 2021
@sstone sstone force-pushed the external-signer-catch-invalid-scriptors branch from c098529 to f9574a4 Compare November 29, 2021 16:46
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 29, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22838 (descriptors: Be able to specify change and receiving in a single descriptor string by achow101)

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.

@sstone sstone force-pushed the external-signer-catch-invalid-scriptors branch 2 times, most recently from be42c78 to 0221b2c Compare November 29, 2021 19:59
@fanquake fanquake requested a review from Sjors December 2, 2021 05:03

def mock_signer_path(self):
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'signer.py')
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mocks', 'invalid_signer.py' if self.options.invalid else 'signer.py')
Copy link
Member

Choose a reason for hiding this comment

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

Adding a new invalid_signer.py is fine with me, though an alternative approach would be to keep one mock, and then use the device fingerprint to decide the behavior.

In that case you would expand the enumerate mock to add a signer with e.g. "fingerprint": "00000003", and then getdescriptors would return an invalid descriptor for 00000003.

Copy link
Contributor Author

@sstone sstone Dec 8, 2021

Choose a reason for hiding this comment

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

I could not get that to work, it seems that it is not supported yet ? (see https://github.com/bitcoin/bitcoin/blob/master/src/wallet/external_signer_scriptpubkeyman.cpp#L47) so instead I re-start the node and change signer path to point to the invalid signer mock.

Copy link
Member

Choose a reason for hiding this comment

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

createwallet doesn't let you specify a fingerprint, so this workaround is probably fine for now.

Comment on lines +57 to +59
buffer = sys.stdin.read()
if buffer and buffer.rstrip() != "":
sys.argv.extend(buffer.rstrip().split(" "))
Copy link

Choose a reason for hiding this comment

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

python3 -c "import sys; print(type(sys.stdin))" reports that this is a TextIOWrapper (even when I pipe something in such that stdin isn't a tty), so that BufferedIOBase.read will be used, which cannot return None. Why not buffer = sys.stdin.read().rstrip(), then? Then it wouldn't be necessary to strip it twice. And if buffer and buffer.rstrip() != "" could be simply if buffer or maybe if buffer != "" if you prefer to be verbose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sstone sstone force-pushed the external-signer-catch-invalid-scriptors branch from 0221b2c to a5f53c3 Compare December 8, 2021 09:23
@sstone sstone force-pushed the external-signer-catch-invalid-scriptors branch from a5f53c3 to 96846ef Compare December 8, 2021 21:16
@achow101
Copy link
Member

achow101 commented Dec 8, 2021

ACK 96846ef7817257326d51c4f05047ca46c3f7f3c7

@fanquake fanquake requested a review from Sjors December 9, 2021 02:31
Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

tACK 96846ef7817257326d51c4f05047ca46c3f7f3c7

Check that descriptors returned by external signers have been parsed properly when creating a new wallet.
@sstone sstone force-pushed the external-signer-catch-invalid-scriptors branch from 96846ef to 5493e92 Compare December 9, 2021 10:17
@jamesob
Copy link
Contributor

jamesob commented Dec 9, 2021

Code review ACK 5493e92

Nice first contribution! Fix is straightforward and well-covered by tests. I did not test this locally.

@achow101
Copy link
Member

achow101 commented Dec 9, 2021

ACK 5493e92

@fanquake fanquake merged commit 09ad512 into bitcoin:master Dec 10, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 10, 2021
5493e92 Check descriptors returned by external signers (sstone)

Pull request description:

  Check that descriptors returned by external signers have been parsed properly when creating a new wallet.
  See bitcoin#23627 for context.

  The problem is that parsing an invalid descriptor will return `null` which is not checked for in `CWallet::SetupDescriptorScriptPubKeyMans()`.

  I'm not completely sure what the best fix is since there several strategies for dealing with errors in the current codebase but the proposed fix is very simple and consistent with other validation checks in `CWallet::SetupDescriptorScriptPubKeyMans()`.

ACKs for top commit:
  jamesob:
    Code review ACK bitcoin@5493e92
  achow101:
    ACK 5493e92

Tree-SHA512: 63259f4aa519405a86c554b6813efdb741314bdaa18bf005b70ea8bb92a27abc6e2b65f7c584641dc257fc78a6499f42b51b5310c243e611c4663430dccf3d04
RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
…igners

c904665 Check descriptors returned by external signers (sstone)

Pull request description:

  Check that descriptors returned by external signers have been parsed properly when creating a new wallet.
  See bitcoin/bitcoin#23627 for context.

  The problem is that parsing an invalid descriptor will return `null` which is not checked for in `CWallet::SetupDescriptorScriptPubKeyMans()`.

  I'm not completely sure what the best fix is since there several strategies for dealing with errors in the current codebase but the proposed fix is very simple and consistent with other validation checks in `CWallet::SetupDescriptorScriptPubKeyMans()`.

ACKs for top commit:
  jamesob:
    Code review ACK bitcoin/bitcoin@c904665
  achow101:
    ACK c904665

Tree-SHA512: 63259f4aa519405a86c554b6813efdb741314bdaa18bf005b70ea8bb92a27abc6e2b65f7c584641dc257fc78a6499f42b51b5310c243e611c4663430dccf3d04
@bitcoin bitcoin locked and limited conversation to collaborators Dec 10, 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.

8 participants