Skip to content

Conversation

jimpo
Copy link
Contributor

@jimpo jimpo commented Aug 23, 2017

Simply adding unit test coverage.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Remove periods from commit messages.

@@ -46,6 +46,8 @@ isminetype IsMine(const CKeyStore &keystore, const CTxDestination& dest, bool& i

isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool& isInvalid, SigVersion sigversion)
{
isInvalid = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please explain why? Since isValid is a return parameter, I think it should get set to false from an initial value of true if the script is not invalid.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, got it.

keystore.AddKey(keys[0]);

CScript witnessScript;
witnessScript << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable is unused.

@jimpo jimpo force-pushed the script-standard-tests branch 3 times, most recently from b84d27c to e6eed35 Compare August 23, 2017 17:13
@gmaxwell
Copy link
Contributor

gmaxwell commented Aug 26, 2017

Without a6564cc, P2WPKH scripts where the pubkey is uncompressed are incorrectly

sounds correct to change; but how would a P2WPKH redeem script for such a key end up in the wallet in the first place? (trying to gauge severity; if it's only accessible inside the code it's good to fix but not e.g. something we need to worry about end users hitting.)

@jimpo
Copy link
Contributor Author

jimpo commented Aug 26, 2017

@gmaxwell I haven't looked through the wallet code enough to know. I assume it would not happen, and it's just a bug in some internals that wouldn't be exercised, but I'm not 100% sure. I came across it through unit tests, not end-to-end testing of the wallet.

@gmaxwell
Copy link
Contributor

Great okay! just making sure you weren't aware of any.

@sipa
Copy link
Member

sipa commented Aug 27, 2017

@jimpo If a6564cc has any effect, I think it's a sign there is a more severe issue, namely that the CKeyID and the CKey in the CBasicKeyStore's map are not in sync with each other (as the CKey stores the compressedness too). I'd rather investigate that discrepancy first.

EDIT: it seems it's just the test code that's wrong. You're calling AddKeyPubKey with a CKey and CPubKey that don't correspond (different compressedness).

BOOST_CHECK(!isInvalid);

// Keystore has key
keystore.AddKeyPubKey(keys[0], uncompressedPubkey0);
Copy link
Member

Choose a reason for hiding this comment

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

You're adding a compressed CKey (keys[0]) with an uncompressed CPubKey, which is incorrect use of the function. You should first change the CKey's compressedness.

Perhaps this warrants a comment on AddKeyPubKey or even an assert. It should alleviate the need for a6564cca7d443789671778f769a24bbb5a4a0652 though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will change.

@jimpo jimpo force-pushed the script-standard-tests branch from e6eed35 to 323dd0e Compare August 28, 2017 16:39
@jimpo
Copy link
Contributor Author

jimpo commented Aug 28, 2017

Thanks for the review @sipa. I had forgotten that CKey tracks the compressedness. Updated the test and removed the change to CBasicKeyStore.

@gmaxwell
Copy link
Contributor

gmaxwell commented Sep 8, 2017

utACK

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

utACK 323dd0e

BOOST_CHECK(solutions[4] == std::vector<unsigned char>({3}));

// TX_NULL_DATA
solutions.clear();
Copy link
Member

Choose a reason for hiding this comment

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

why? It is the task of the solver to set the size of the vector to 0. Otherwise you could as well remove the BOOST_CHECK_EQUAL(solutions.size(), 0);, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point.

@jimpo jimpo force-pushed the script-standard-tests branch from 323dd0e to 184a07d Compare September 20, 2017 18:09
Copy link
Contributor

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

utACK 184a07d5b6131c13238397db1b1e9a0a1c58c54f

}

CScript expected, result;
CTxDestination dest;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is practically unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, removed.

@jimpo jimpo force-pushed the script-standard-tests branch from 184a07d to 7a1e873 Compare September 21, 2017 19:24
@laanwj laanwj merged commit 7a1e873 into bitcoin:master Sep 21, 2017
laanwj added a commit that referenced this pull request Sep 21, 2017
…tions.

7a1e873 [script] Unit tests for IsMine (Jim Posen)
d7afe2d [script] Unit tests for script/standard functions (Jim Posen)

Pull request description:

  Simply adding unit test coverage.

Tree-SHA512: aaf16b1b07b6d43c884a67f4fd5f83c31bf2c560f78798036d7aa37a3efe71a7ca3c82c4b3ba1f3119bcbe3b78013e64bb0020fe57ebc69aea1cb54943881959
@jimpo jimpo deleted the script-standard-tests branch September 21, 2017 20:47

// TX_WITNESS_V0_SCRIPTHASH
s.clear();
s << OP_0 << ToByteVector(CScriptID(redeemScript));
Copy link
Member

Choose a reason for hiding this comment

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

Posthumous review (and fixed in #11167): this does not construct a valid TX_WITNESS_V0_SCRIPTHASH but a TX_WITNESS_V0_KEYHASH (as the pushed size is 20, not 32)

maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Oct 3, 2017
Does not test watch-only addresses.

Github-Pull: bitcoin#11116
Rebased-From: 7a1e873
codablock pushed a commit to codablock/dash that referenced this pull request Sep 24, 2019
…ne functions.

7a1e873 [script] Unit tests for IsMine (Jim Posen)
d7afe2d [script] Unit tests for script/standard functions (Jim Posen)

Pull request description:

  Simply adding unit test coverage.

Tree-SHA512: aaf16b1b07b6d43c884a67f4fd5f83c31bf2c560f78798036d7aa37a3efe71a7ca3c82c4b3ba1f3119bcbe3b78013e64bb0020fe57ebc69aea1cb54943881959
zkbot added a commit to zcash/zcash that referenced this pull request Dec 19, 2019
Bitcoin wallet PRs 3

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7687
- bitcoin/bitcoin#11116
  - Excludes SegWit tests
  - Excludes `isInvalid` code (which is part of the SegWit support structure)
- bitcoin/bitcoin#13002
  - Excludes changes to `importwallet` (missing bitcoin/bitcoin#11667)
  - Excludes changes to `ProcessImport` (missing bitcoin/bitcoin#7551)
  - Third commit was rewritten to add an internal SigVersion argument (which we didn't have because it was added to support SegWit logic).
barrystyle pushed a commit to PACGlobalOfficial/PAC that referenced this pull request Jan 22, 2020
…ne functions.

7a1e873 [script] Unit tests for IsMine (Jim Posen)
d7afe2d [script] Unit tests for script/standard functions (Jim Posen)

Pull request description:

  Simply adding unit test coverage.

Tree-SHA512: aaf16b1b07b6d43c884a67f4fd5f83c31bf2c560f78798036d7aa37a3efe71a7ca3c82c4b3ba1f3119bcbe3b78013e64bb0020fe57ebc69aea1cb54943881959
@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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants