programmingbitcoin icon indicating copy to clipboard operation
programmingbitcoin copied to clipboard

Length of P2SH redeem script is incorrectly prepended prior to parsing via Script.parse

Open salmonberry7 opened this issue 10 months ago • 0 comments

In Tx.verify_input in Chap. 13, the length of the redeem script is computed using int_to_little_endian(len(cmd), 1). As stated in the code comment 'prepend the length of the RedeemScript using encode_varint' in Chap. 8 it should be computed using encode_varint(len(cmd)), to be compatible with Script.parse.

According to BIP16 '520-byte limitation on serialized script size' a P2SH redeem script can have a serialized script length of up to 520 bytes. Thus the present code will cause failure for a redeem script length >= 253. For example a CHECKMULTISIG redeem script with 8 or more compressed public keys (=> length >= 3 + 8*34 = 275 bytes) will raise an OverflowError exception as int_to_little_endian fails.

salmonberry7 avatar Jan 13 '25 18:01 salmonberry7