Skip to content

Commit 01552e8

Browse files
committed
test: MiniWallet: always rehash after signing (P2PK mode)
Also explicitly rehash in the cases where we modify a tx after signing in feature_csv_activation.py. Parts of this test relied on the fact that rehashing of transactions is done in the course of calculating a block's merkle root (`calc_merkle_root`), which only works if no hash was calculated before due to a caching mechanism. In the following commit the txid in MiniWallet is calculated via `rehash()`, i.e. this doesn't work anymore and we always have to explicitely have the right hash before we calculate the merkle root.
1 parent 7a4ac71 commit 01552e8

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

test/functional/feature_csv_activation.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,15 @@ def create_bip112special(self, input, txversion):
112112
tx.nVersion = txversion
113113
self.miniwallet.sign_tx(tx)
114114
tx.vin[0].scriptSig = CScript([-1, OP_CHECKSEQUENCEVERIFY, OP_DROP] + list(CScript(tx.vin[0].scriptSig)))
115+
tx.rehash()
115116
return tx
116117

117118
def create_bip112emptystack(self, input, txversion):
118119
tx = self.create_self_transfer_from_utxo(input)
119120
tx.nVersion = txversion
120121
self.miniwallet.sign_tx(tx)
121122
tx.vin[0].scriptSig = CScript([OP_CHECKSEQUENCEVERIFY] + list(CScript(tx.vin[0].scriptSig)))
123+
tx.rehash()
122124
return tx
123125

124126
def send_generic_input_tx(self, coinbases):
@@ -136,7 +138,6 @@ def create_bip68txs(self, bip68inputs, txversion, locktime_delta=0):
136138
tx.nVersion = txversion
137139
tx.vin[0].nSequence = locktime + locktime_delta
138140
self.miniwallet.sign_tx(tx)
139-
tx.rehash()
140141
txs.append({'tx': tx, 'sdf': sdf, 'stf': stf})
141142

142143
return txs
@@ -339,20 +340,16 @@ def run_test(self):
339340
# BIP 113 tests should now fail regardless of version number if nLockTime isn't satisfied by new rules
340341
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
341342
self.miniwallet.sign_tx(bip113tx_v1)
342-
bip113tx_v1.rehash()
343343
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 # = MTP of prior block (not <) but < time put on current block
344344
self.miniwallet.sign_tx(bip113tx_v2)
345-
bip113tx_v2.rehash()
346345
for bip113tx in [bip113tx_v1, bip113tx_v2]:
347346
self.send_blocks([self.create_test_block([bip113tx])], success=False, reject_reason='bad-txns-nonfinal')
348347

349348
# BIP 113 tests should now pass if the locktime is < MTP
350349
bip113tx_v1.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
351350
self.miniwallet.sign_tx(bip113tx_v1)
352-
bip113tx_v1.rehash()
353351
bip113tx_v2.nLockTime = self.last_block_time - 600 * 5 - 1 # < MTP of prior block
354352
self.miniwallet.sign_tx(bip113tx_v2)
355-
bip113tx_v2.rehash()
356353
for bip113tx in [bip113tx_v1, bip113tx_v2]:
357354
self.send_blocks([self.create_test_block([bip113tx])])
358355
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
@@ -477,7 +474,6 @@ def run_test(self):
477474
for tx in [tx['tx'] for tx in bip112txs_vary_OP_CSV_v2 if not tx['sdf'] and tx['stf']]:
478475
tx.vin[0].nSequence = BASE_RELATIVE_LOCKTIME | SEQ_TYPE_FLAG
479476
self.miniwallet.sign_tx(tx)
480-
tx.rehash()
481477
time_txs.append(tx)
482478

483479
self.send_blocks([self.create_test_block(time_txs)])

test/functional/test_framework/wallet.py

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def sign_tx(self, tx, fixed_length=True):
127127
if not fixed_length:
128128
break
129129
tx.vin[0].scriptSig = CScript([der_sig + bytes(bytearray([SIGHASH_ALL]))])
130+
tx.rehash()
130131

131132
def generate(self, num_blocks, **kwargs):
132133
"""Generate blocks with coinbase outputs to the internal address, and append the outputs to the internal list"""

0 commit comments

Comments
 (0)