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

P2PKH scripts paying P2SH redeemScripts are shown in balance. #377

Closed
STRML opened this issue Dec 18, 2015 · 3 comments
Closed

P2PKH scripts paying P2SH redeemScripts are shown in balance. #377

STRML opened this issue Dec 18, 2015 · 3 comments

Comments

@STRML
Copy link
Contributor

STRML commented Dec 18, 2015

For example, there are many spam transactions on the blockchain that use a redeemScript in the P2PKH fashion:

OP_DUP OP_HASH160 <redeemScript> OP_EQUALVERIFY OP_CHECKSIG

This will not be redeemable by a P2SH address, because its script must be:

OP_HASH160 <redeemScript> OP_EQUAL

This is a critical bug IMO as balances on addresses are being reported incorrectly. Any services relying on an Insight service may incorrectly credit an address with a balance it is not actually able to spend.

We should be checking the version type of the address when crediting an output to ensure it is actually spendable.

@STRML
Copy link
Contributor Author

STRML commented Dec 18, 2015

Moved to bitpay/bitcore-lib#33

@STRML STRML closed this as completed Dec 18, 2015
@STRML STRML reopened this Dec 18, 2015
@STRML
Copy link
Contributor Author

STRML commented Dec 18, 2015

Found what seems to be the bug: the DB is indexing redeemScripts and PKHashes identically, so if they collide you will erroneously see a tx you can't spend.

This was part of an optimization effort that assumed that the rest of the script was not necessary (only the PKHash). This is not a safe assumption. Since we are matching script types via templating in bitcore-lib /~https://github.com/bitpay/bitcore-lib/blob/master/lib/script/script.js#L307, it is not necessary to hold onto the entire script, but we must hold onto the type.

/~https://github.com/bitpay/bitcore-node/blob/master/lib/services/address/index.js#L358

STRML referenced this issue Dec 18, 2015
- Adds default to store a large portion of the mempool index in leveldb
- Includes an option to use memdown to have the mempool index in-memory
@STRML
Copy link
Contributor Author

STRML commented Dec 18, 2015

Pushing a fix shortly.

For an example of this bug, note the transaction credited to:

https://test-insight.bitpay.com/address/2MyJ6e284p15EJkFF6LsKSsfiU3jpNPYk5S

which is correct, but how it is also incorrectly credited to

https://test-insight.bitpay.com/address/mmZpwnnaTfgknuPt1gZEEDXqyAqdsxciTo

which is the corresponding P2PKH address.

STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
STRML added a commit to STRML/bitcore-node that referenced this issue Dec 18, 2015
Prevents erroneous crediting of all transactions to both the
p2pkh and the corresponding p2sh address.
kleetus added a commit that referenced this issue Jan 11, 2016
Fix #377; db must contain hash + type, not just hash.
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

1 participant