Skip to content

Commit 029c65e

Browse files
committed
Merge #17141: Test: Rename SegwitVersion1SignatureHash()
eebcdfa [test] rename SegwitVersion1SignatureHash() (John Newbery) Pull request description: The function implementing segwit v0 signature hash was originally named SegwitVersion1SignatureHash() (presumably before segwit v0 was named segwit v0). Rename it to SegwitV0SignatureHash(). Also rename SignatureHash() to LegacySignatureHash() for disambiguation. ACKs for top commit: laanwj: ACK eebcdfa elichai: ACK eebcdfa (Checked to see you didn't miss any renaming) theStack: ACK bitcoin/bitcoin@eebcdfa Tree-SHA512: ae504ac33dc4fca38079a113beb5ebcaf509162aef121edec5368a460a24c2ac040ef84f0be1dfc6186c32d94d68f8129db049907f1d6449f92eea9d39a40dbd
2 parents c787556 + eebcdfa commit 029c65e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

test/functional/feature_block.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
OP_RETURN,
4747
OP_TRUE,
4848
SIGHASH_ALL,
49-
SignatureHash,
49+
LegacySignatureHash,
5050
hash160,
5151
)
5252
from test_framework.test_framework import BitcoinTestFramework
@@ -532,7 +532,7 @@ def run_test(self):
532532
# second input is corresponding P2SH output from b39
533533
tx.vin.append(CTxIn(COutPoint(b39.vtx[i].sha256, 0), b''))
534534
# Note: must pass the redeem_script (not p2sh_script) to the signature hash function
535-
(sighash, err) = SignatureHash(redeem_script, tx, 1, SIGHASH_ALL)
535+
(sighash, err) = LegacySignatureHash(redeem_script, tx, 1, SIGHASH_ALL)
536536
sig = self.coinbase_key.sign_ecdsa(sighash) + bytes(bytearray([SIGHASH_ALL]))
537537
scriptSig = CScript([sig, redeem_script])
538538

@@ -1312,7 +1312,7 @@ def sign_tx(self, tx, spend_tx):
13121312
if (scriptPubKey[0] == OP_TRUE): # an anyone-can-spend
13131313
tx.vin[0].scriptSig = CScript()
13141314
return
1315-
(sighash, err) = SignatureHash(spend_tx.vout[0].scriptPubKey, tx, 0, SIGHASH_ALL)
1315+
(sighash, err) = LegacySignatureHash(spend_tx.vout[0].scriptPubKey, tx, 0, SIGHASH_ALL)
13161316
tx.vin[0].scriptSig = CScript([self.coinbase_key.sign_ecdsa(sighash) + bytes(bytearray([SIGHASH_ALL]))])
13171317

13181318
def create_and_sign_transaction(self, spend_tx, value, script=CScript([OP_TRUE])):

test/functional/p2p_segwit.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
SIGHASH_ANYONECANPAY,
6868
SIGHASH_NONE,
6969
SIGHASH_SINGLE,
70-
SegwitVersion1SignatureHash,
71-
SignatureHash,
70+
SegwitV0SignatureHash,
71+
LegacySignatureHash,
7272
hash160,
7373
)
7474
from test_framework.test_framework import BitcoinTestFramework
@@ -103,7 +103,7 @@ def get_p2pkh_script(pubkeyhash):
103103

104104
def sign_p2pk_witness_input(script, tx_to, in_idx, hashtype, value, key):
105105
"""Add signature for a P2PK witness program."""
106-
tx_hash = SegwitVersion1SignatureHash(script, tx_to, in_idx, hashtype, value)
106+
tx_hash = SegwitV0SignatureHash(script, tx_to, in_idx, hashtype, value)
107107
signature = key.sign_ecdsa(tx_hash) + chr(hashtype).encode('latin-1')
108108
tx_to.wit.vtxinwit[in_idx].scriptWitness.stack = [signature, script]
109109
tx_to.rehash()
@@ -1489,7 +1489,7 @@ def test_uncompressed_pubkey(self):
14891489
tx2.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
14901490
tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_wsh))
14911491
script = get_p2pkh_script(pubkeyhash)
1492-
sig_hash = SegwitVersion1SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue)
1492+
sig_hash = SegwitV0SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue)
14931493
signature = key.sign_ecdsa(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL
14941494
tx2.wit.vtxinwit.append(CTxInWitness())
14951495
tx2.wit.vtxinwit[0].scriptWitness.stack = [signature, pubkey]
@@ -1543,7 +1543,7 @@ def test_uncompressed_pubkey(self):
15431543
tx5 = CTransaction()
15441544
tx5.vin.append(CTxIn(COutPoint(tx4.sha256, 0), b""))
15451545
tx5.vout.append(CTxOut(tx4.vout[0].nValue - 1000, CScript([OP_TRUE])))
1546-
(sig_hash, err) = SignatureHash(script_pubkey, tx5, 0, SIGHASH_ALL)
1546+
(sig_hash, err) = LegacySignatureHash(script_pubkey, tx5, 0, SIGHASH_ALL)
15471547
signature = key.sign_ecdsa(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL
15481548
tx5.vin[0].scriptSig = CScript([signature, pubkey])
15491549
tx5.rehash()
@@ -1693,7 +1693,7 @@ def test_signature_version_1(self):
16931693
tx2.vout.append(CTxOut(tx.vout[0].nValue, CScript([OP_TRUE])))
16941694

16951695
script = get_p2pkh_script(pubkeyhash)
1696-
sig_hash = SegwitVersion1SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue)
1696+
sig_hash = SegwitV0SignatureHash(script, tx2, 0, SIGHASH_ALL, tx.vout[0].nValue)
16971697
signature = key.sign_ecdsa(sig_hash) + b'\x01' # 0x1 is SIGHASH_ALL
16981698

16991699
# Check that we can't have a scriptSig

test/functional/test_framework/script.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (c) 2015-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Functionality to build scripts, as well as SignatureHash().
5+
"""Functionality to build scripts, as well as signature hash functions.
66
77
This file is modified from python-bitcoinlib.
88
"""
@@ -608,7 +608,7 @@ def FindAndDelete(script, sig):
608608
return CScript(r)
609609

610610

611-
def SignatureHash(script, txTo, inIdx, hashtype):
611+
def LegacySignatureHash(script, txTo, inIdx, hashtype):
612612
"""Consensus-correct SignatureHash
613613
614614
Returns (hash, err) to precisely match the consensus-critical behavior of
@@ -662,7 +662,7 @@ def SignatureHash(script, txTo, inIdx, hashtype):
662662
# Performance optimization probably not necessary for python tests, however.
663663
# Note that this corresponds to sigversion == 1 in EvalScript, which is used
664664
# for version 0 witnesses.
665-
def SegwitVersion1SignatureHash(script, txTo, inIdx, hashtype, amount):
665+
def SegwitV0SignatureHash(script, txTo, inIdx, hashtype, amount):
666666

667667
hashPrevouts = 0
668668
hashSequence = 0

0 commit comments

Comments
 (0)