当我阅读本书 Mastering Bitcoin chapter 6
时我尝试按照本书中提到的步骤进行操作,但我发现结果不正确,我错在哪里?
交易为here:
输入脚本:
ScriptSig:
PUSHDATA(72)[3045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e381301]
PUSHDATA(65)[0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf]
然后我跟踪此交易中包含的output。其中输出脚本如下:
DUP HASH160 PUSHDATA(20)[7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8] EQUALVERIFY CHECKSIG
然后我使用website calculator
计算RIPMED160(SHA256(Pubk)) = "6df13de1f1d824380834e0d42e49e5e451a647cf"
但结果不等于输出脚本中的7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8。
答案 0 :(得分:1)
你有正确的想法,但我认为你正在散列十六进制字符串,而不是二进制数据。如果我使用Python的hashlib库计算ripemd160(sha256(pubk)),我会得到正确的结果:
$ python
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii, hashlib
>>> sha256 = hashlib.new('sha256')
>>> ripemd160 = hashlib.new('ripemd160')
>>> sha256.update(binascii.unhexlify('0484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adf'))
>>> ripemd160.update(sha256.digest())
>>> ripemd160.hexdigest()
'7f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a8'