diff --git a/test/functional/test_framework/blocktools.py b/test/functional/test_framework/blocktools.py index 38600bc005a..8e616285572 100644 --- a/test/functional/test_framework/blocktools.py +++ b/test/functional/test_framework/blocktools.py @@ -28,7 +28,6 @@ from .messages import ( ser_uint256, tx_from_hex, uint256_from_compact, - uint256_from_str, WITNESS_SCALE_FACTOR, ) from .script import ( @@ -111,8 +110,8 @@ def create_block(hashprev=None, coinbase=None, ntime=None, *, version=None, tmpl return block def get_witness_script(witness_root, witness_nonce): - witness_commitment = uint256_from_str(hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce))) - output_data = WITNESS_COMMITMENT_HEADER + ser_uint256(witness_commitment) + witness_commitment = hash256(ser_uint256(witness_root) + ser_uint256(witness_nonce)) + output_data = WITNESS_COMMITMENT_HEADER + witness_commitment return CScript([OP_RETURN, output_data]) def add_witness_commitment(block, nonce=0): diff --git a/test/functional/test_framework/script.py b/test/functional/test_framework/script.py index d510cf9b1ca..12bfee7c776 100644 --- a/test/functional/test_framework/script.py +++ b/test/functional/test_framework/script.py @@ -17,9 +17,7 @@ from .messages import ( CTxOut, hash256, ser_string, - ser_uint256, sha256, - uint256_from_str, ) from .crypto.ripemd160 import ripemd160 @@ -711,41 +709,42 @@ def sign_input_segwitv0(tx, input_index, input_scriptpubkey, input_amount, privk # Note that this corresponds to sigversion == 1 in EvalScript, which is used # for version 0 witnesses. def SegwitV0SignatureMsg(script, txTo, inIdx, hashtype, amount): + ZERO_HASH = bytes([0]*32) - hashPrevouts = 0 - hashSequence = 0 - hashOutputs = 0 + hashPrevouts = ZERO_HASH + hashSequence = ZERO_HASH + hashOutputs = ZERO_HASH if not (hashtype & SIGHASH_ANYONECANPAY): serialize_prevouts = bytes() for i in txTo.vin: serialize_prevouts += i.prevout.serialize() - hashPrevouts = uint256_from_str(hash256(serialize_prevouts)) + hashPrevouts = hash256(serialize_prevouts) if (not (hashtype & SIGHASH_ANYONECANPAY) and (hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE): serialize_sequence = bytes() for i in txTo.vin: serialize_sequence += i.nSequence.to_bytes(4, "little") - hashSequence = uint256_from_str(hash256(serialize_sequence)) + hashSequence = hash256(serialize_sequence) if ((hashtype & 0x1f) != SIGHASH_SINGLE and (hashtype & 0x1f) != SIGHASH_NONE): serialize_outputs = bytes() for o in txTo.vout: serialize_outputs += o.serialize() - hashOutputs = uint256_from_str(hash256(serialize_outputs)) + hashOutputs = hash256(serialize_outputs) elif ((hashtype & 0x1f) == SIGHASH_SINGLE and inIdx < len(txTo.vout)): serialize_outputs = txTo.vout[inIdx].serialize() - hashOutputs = uint256_from_str(hash256(serialize_outputs)) + hashOutputs = hash256(serialize_outputs) ss = bytes() ss += txTo.version.to_bytes(4, "little") - ss += ser_uint256(hashPrevouts) - ss += ser_uint256(hashSequence) + ss += hashPrevouts + ss += hashSequence ss += txTo.vin[inIdx].prevout.serialize() ss += ser_string(script) ss += amount.to_bytes(8, "little", signed=True) ss += txTo.vin[inIdx].nSequence.to_bytes(4, "little") - ss += ser_uint256(hashOutputs) + ss += hashOutputs ss += txTo.nLockTime.to_bytes(4, "little") ss += hashtype.to_bytes(4, "little") return ss