Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Mar 31, 2020

ParsePrevouts uses GetScriptForWitness on the given witnessScript to find the corresponding redeemScript. This is incorrect when the witnessScript is either a P2PK or P2PKH script as it returns the corresponding P2WPK script instead of turning the witnessScript into a P2WSH script. Instead this should make the script a WitnessV0ScriptHash destination and get the script for that.

Test cases are also added. These will fail on master with a redeemScript does not correspond to witnessScript

Reported on Bitcointalk

@sipa
Copy link
Member

sipa commented Mar 31, 2020

utACK c0f9a61793ffccb6af97ffb6b4a156780e1a4597

After this it seems that GetScriptForWitness is only used in bitcoin-tx (all in places were more explicit constructions of scripts would be preferable) and in tests. Maybe it's time (in a different PR) to get rid of it entirely.

@maflcko maflcko changed the title Correctly compute redeemScript from witnessScript for signrawtransaction rpc: Correctly compute redeemScript from witnessScript for signrawtransaction Mar 31, 2020
@achow101 achow101 force-pushed the signrawtx-p2pkh-p2wsh branch from c0f9a61 to d0deb17 Compare March 31, 2020 19:04
ParsePrevouts uses GetScriptForWitness on the given witnessScript
to find the corresponding redeemScript. This is incorrect when the
witnessScript is either a P2PK or P2PKH script as it returns the
corresponding P2WPK script instead of turning the witnessScript
into a P2WSH script. Instead this should make the script a
WitnessV0ScriptHash destination and get the script for that.

Test cases are also added.
@achow101 achow101 force-pushed the signrawtx-p2pkh-p2wsh branch from d0deb17 to cd3b156 Compare March 31, 2020 22:42
@maflcko maflcko added this to the 0.20.0 milestone Apr 3, 2020
@maflcko
Copy link
Member

maflcko commented Apr 3, 2020

weak ACK cd3b156, only checked that the test fails without the code change 🚰

Show signature and timestamp

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

weak ACK cd3b1569d9, only checked that the test fails without the code change 🚰
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUjCbwwAsp2heFGb1866a8x98h5pUos0kinxV/wI5wCnXhsD698tiLJMjYSr0q6U
Y5GZwCHJLQTgAwI+SB7j4c/YZONMro+sspVT6RzeBNEmZ+sGRTfpDSDJ8ia95zuZ
lKbSab1ClG7IgmuLpxOag2twuwtY48RT8HOcC1xcMaipDylBdM2uRrFHKJE7CW6H
UDaFGunaLDJDqjWjYG7Y62G1u2IF4nNQu/8FqoyMOx0gXTDQo5pv/M6HYDD0JYZV
fNC2clH/wcaqY2dP0khpBTrBoOh8V/1VPswc9VgW7/TEI36c8Vk0KZ2u8DbKY9e9
3PSwN6gE6U6VgDfTLclF52lC+OR0snp8meIgziPey9IhPXZITNRFVaE963EtjVed
uOI4T20GU8f7tIOw4om7Y7dVRMY+z08VfksdhppwgdMwSwW2CIeRl+KByBRmUbGw
aRGLVysoFFI26MgI37KyLGIptLGC/zPPgJHxvS+l6X6Ofhp0RxyyTyrDycc6yiQi
HH6jdJlB
=HXml
-----END PGP SIGNATURE-----

Timestamp of file with hash 881a6eae6982f18b4068be3f58ea3caa8e81d392053eea501c317ee5ae66cb93 -

@maflcko
Copy link
Member

maflcko commented Apr 3, 2020

@maflcko maflcko closed this Apr 3, 2020
@maflcko maflcko reopened this Apr 3, 2020
@instagibbs
Copy link
Member

utACK cd3b156

@maflcko maflcko merged commit c0b389b into bitcoin:master Apr 6, 2020
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK cd3b156

It looks like we are close to being able to remove GetScriptForWitness as per:

src/script/standard.h:202: * TODO: replace calls to GetScriptForWitness with GetScriptForDestination using the various witness-specific CTxDestination subtypes.

self.nodes[0].generate(1)
# Now create and sign a transaction spending that output on node[0], which doesn't know the scripts or keys
spending_tx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], {self.nodes[1].getnewaddress(): Decimal("9.999")})
spending_tx_signed = self.nodes[0].signrawtransactionwithkey(spending_tx, [embedded_privkey], [{'txid': txid, 'vout': vout, 'scriptPubKey': script_pub_key, 'redeemScript': redeem_script, 'witnessScript': witness_script, 'amount': 10}])
Copy link
Member

Choose a reason for hiding this comment

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

verified that reverting the change in rawtransaction_util.cpp::219 causes the test to fail here with redeemScript does not correspond to witnessScript (-8)

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Apr 8, 2020
…Script for signrawtransaction

cd3b156 Correctly compute redeemScript from witnessScript for signrawtransaction (Andrew Chow)

Pull request description:

  `ParsePrevouts` uses `GetScriptForWitness` on the given witnessScript to find the corresponding redeemScript. This is incorrect when the witnessScript is either a P2PK or P2PKH script as it returns the corresponding P2WPK script instead of turning the witnessScript into a P2WSH script. Instead this should make the script a `WitnessV0ScriptHash` destination and get the script for that.

  Test cases are also added. These will fail on master with a `redeemScript does not correspond to witnessScript`

  Reported on [Bitcointalk](https://bitcointalk.org/index.php?topic=5236818.0)

ACKs for top commit:
  MarcoFalke:
    weak ACK cd3b156, only checked that the test fails without the code change 🚰
  instagibbs:
    utACK bitcoin@cd3b156

Tree-SHA512: afac671dbb52ce88bfb4a9ca3dd6065427ad52c9778d0549ad40e9286778f308adad24fb3b3c3089545d7f88c57c53d41224fd7a4bb207550eff2fe06600118f
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Apr 13, 2020
…gging

9cdddae test: add rpc_signrawtransaction logging (Jon Atack)
4d6cde3 test: refactor rpc_signrawtransaction witness script tests (Jon Atack)

Pull request description:

  As a follow-up to bitcoin#18484, the new tests are good but bury the one non-duplicate line in each test that sets the witness script, and there is no logging in the testfile. This PR makes it easy to see what is unique to each of the new tests and adds logging.

ACKs for top commit:
  theStack:
    ACK bitcoin@9cdddae 🥚 🐰

Tree-SHA512: 7b1ca303326658afb90b7635abc9fe8bb65f0be004124d4dcf38702bb6f38bc06ce33c0642be4ad5d511453d003cdefeea691e66e3b963a4feb66f6237a3c241
Copy link

@Iceymann18777 Iceymann18777 left a comment

Choose a reason for hiding this comment

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

.

@bitcoin bitcoin locked and limited conversation to collaborators Sep 24, 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.

6 participants