miniscript icon indicating copy to clipboard operation
miniscript copied to clipboard

hash160/ripemd160: concrete hash missing in output script

Open benma opened this issue 3 years ago • 2 comments

At https://bitcoin.sipa.be/miniscript/, if I enter this miniscript:

sha256(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)

I receive the expected script structure:

OP_SIZE <20> OP_EQUALVERIFY OP_SHA256
<aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> OP_EQUAL

For hash160/ripemd160 however, the hash is missing in the script. For example:

hash160(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) results in:

OP_SIZE <20> OP_EQUALVERIFY OP_HASH160  OP_EQUAL

(<a....> is missing before OP_EQUAL).

using hash160(H) correctly outputs:

OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <h> OP_EQUAL

benma avatar Jan 05 '23 01:01 benma

I also just noticed this inconsistency:

In the translation table for the hash functions, the Bitcoin Script uses decimal <32>:

SIZE <32> EQUALVERIFY SHA256 <h> EQUAL

While the script structure compilation output prints it in hex <20>:

OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <h> OP_EQUAL

Did a double-take there - would be good to make this consistent and document which format is used for clarity (or maybe use the 0x prefix for hex values).

benma avatar Jan 05 '23 01:01 benma

There's also a subtle ~typo. hash160(H) & ripemd160(H) (using upper case H as a variable) ends up producing ASM with <h> (lower case h). Keeping case sensitive would also be nice. sha256 and hash256 work as expected.

BTW: I'd rather keep the notation <20>, where 20 is in fact 0x20 when enclosed within angle quotation marks.

landabaso avatar Jan 23 '23 19:01 landabaso