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

Potentially misleading/buggy implementation in checking P2WPK and P2WSH nested in P2SH #176

Closed
wanwenli opened this issue May 18, 2018 · 1 comment

Comments

@wanwenli
Copy link
Contributor

wanwenli commented May 18, 2018

In class CScript of core.script, the comments and the method names of
is_witness_v0_nested_keyhash and is_witness_v0_nested_scripthash are misleading and one implementation is susceptibly buggy.

Firstly, P2WPK and P2WSH cannot be distinguished in outputs, according to examples given in BIP-0141. In other words, just by looking at their outputs they are merely P2SH. Therefore I would like to propose changing both the names and comments of these two methods. The nested type cannot be told by checking "key hash" or "script hash" as their names suggest. Anyway from tracing the call hierarchy in this test case I have found that is_witness_v0_nested_keyhash is used to check redeemScript, rather than what its name and comment suggest. However is_witness_v0_nested_scripthash is not found to be used anywhere in the code base.

Most importantly, the implementation of is_witness_v0_nested_scripthash is wrong. Its logic is essentially the same as is_p2sh.

Here is an example:

The last output of transaction 44323efd5714949d516f9970899da3c0207ed1308b0deb160efe099d047f641e is of P2SH type and I use its script hex to test against your API's in IPython.

In [4]: script = CScript(bytearray.fromhex("a9148a8ceee90f9da5402de69e72055933d830fbf6b987"))

In [5]: script.is_p2sh()
Out[5]: True

In [6]: script.is_witness_v0_nested_scripthash()
Out[6]: True

This output has been spent in transaction 7927a96ff5e3915b95bdbfef648cd342bd5bd8b13be35602d4ac0e30dab95e9e as the sole input and it is found to be a generic P2SH-MULTISIG payment, not a P2WSH type.

If you agree with me, please allow me to submit a PR. Otherwise please give your suggestions. Many thanks.

@petertodd
Copy link
Owner

Yup, I think you're right here. Removing those two functions is fine by me; that pull-req is welcome!

petertodd added a commit that referenced this issue Aug 21, 2019
96dd697 fix checking on p2sh-p2wsh (Wan Wenli)

Pull request description:

  After discussing in [this issue](#176), I think it is better to keep the methods signatures, but change the comments and fix a potential bug.

Top commit has no ACKs.

Tree-SHA512: 4f09f111903280d68a33394f64e02943bf9bdf287ec4bac470c5efabb334baddd3202b5e0fbad1ab4c9ccaca9325580d38881c60285a1adbc827281273ac1dc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants