I'm working my way through "Mastering Bitcoin".

The author made a transaction:



I tried to execute the transaction script (with the Unlock script in vout) in a Bitcoin Script online simulator: https://siminchen.github.io/bitcoinIDE/build/editor.html putting the current ScriptSig:

ScriptSig: PUSHDATA(72)[3045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e381301] PUSHDATA(65)[0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf]

with the output script:

DUP HASH160 PUSHDATA(20)[7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8] EQUALVERIFY CHECKSIG

according the blockchain explorer.

I got "execution unsuccessful" even though i didn't figure out what's the problem. Apparently the op_EQUALVERIFY got failed.

enter image description here


1 Answer 1


The online script check program that you are using to evaluate the script has numerous issues. First, there is a known issue of the software calculating the OP_HASH160 incorrectly. For example, the HASH160 of the public key that you have entered (the one starting with 04...) is 7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8 while the program is calculating it as 6DF13DE1F1D824380834E0D42E49E5E451A647CF. This results in a failed validation when the OP_EQUALVERIFY opcode runs.

The error derives from mishandling the hashing strings as ASCII instead of binary. By this I mean that the program is hashing the public key as a string rather than treating the public key as a hexadecimal number and hashing the bytes. Below is a python code of how the hashing should actually be done.

import hashlib

def hash160(payload_in_hex):
    payload_in_bytes = bytes.fromhex(payload_in_hex) # note this step
    payload_sha256 = hashlib.sha256(payload_in_bytes).digest()
    payload_sha256_ripemd160 = hashlib.new('ripemd160', payload_sha256).hexdigest()
    return payload_sha256_ripemd160

pub_key = '0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf'
>>> '7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8'

Secondly, the signature verification against a public key without knowing what message was signed is simply incorrect. This is resulting in the program accepting any signature for any given public key. For example just try the below script and it will show you that execution was successful.

aecd 0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf OP_CHECKSIG

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.