0

To test my understanding of the signing and verifying process i tried to verify some random Bitcoin transactions by hand. Sadly i got stuck with a P2WSH transaction, i choose the following transaction with Hash c53b99c9fdba60fd47c6026177d3f6e1ed6d3abde8f433364619aa7d437dad26

With the raw transaction:

010000000001012198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a70100000000ffffffff0220120a000000000017a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea110000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d0400473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101473044022047e4ad9788da6b764e723dd71d9fe07a217e48871129a672ef2788eb0d331a7a02206107b10c23e8720df9f1e5f609c471726066c5b72c56ee774615498f8fe62e8d016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000

I can deserialize this to:


TX version number = 00000001
Inputs count = 01
TX from hash = a7c4fe84bd121e57630c067b455763747ee4fc09b9e220f4fca46008bce59821
TX outpoint Index = 00000001
Input script =
Sequence number = ffffffff
Outputs count = 02
Value(base 10) = 660000
Output script = a91417b9a9afddaae527d25788bce2202563d4ab0d0587
Value(base 10) = 1174148
Output script = 0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d
Witness 0 0 = 00
Witness 0 1 = 473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101
Witness 0 2 = 473044022047e4ad9788da6b764e723dd71d9fe07a217e48871129a672ef2788eb0d331a7a02206107b10c23e8720df9f1e5f609c471726066c5b72c56ee774615498f8fe62e8d01
Witness 0 3 = 6952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae
Lock time = 00000000


Now i try to compute the MessageHash that gets signed:

with:
hashPrevouts = sha256²(2198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a701000000)
hashSequence = sha256²(ffffffff)
hashOutputs = sha256²(20120a0000000000a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea1100000000000020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d)

Version: 01000000
hashPrevouts: 65aa319c96c046e8589c758adf7441d335682d3fc76df649180c4f94a1c4a731
hashSequence: 3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044
outPoint: 2198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a701000000
scriptCode: 6952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae
value: 345c1d0000000000
nSequence: ffffffff
hashOutputs: 58d6a86eb99a911735d2f262a9fc13fcf0f8422d75e25ba04db120f65cf573d6
nLocktime: 00000000
sighash: 01000000


This will give me the MessageHash = 8560e61d0167f784d0cdaf9d45ba0e1be752e94d30a34339d976b01e50f0e366

But if i try to verify this MessageHash with the first Signature(473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101), which has R = 14cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c and S = 1c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b431 against any of the 3 PubKeys in Witness 0 3, i always get the the Signature is not valid.

Can someone tell me where i got wrong ?

0

hashOutputs = sha256²(20120a0000000000a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea1100000000000020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d)

This value is incorrect. The following values are correct.

hashOutputs = sha256²(20120a000000000017a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea110000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d)

hashOutputs: 787ea14bb2276614a291caeadbadb8155b4491f454988aab8919ffbfd6fc83a5

As a result, the message hash is:

989f5760931156cf50fba49c7d9e7b79e785cf340b9775d1a8931bc5e13197f7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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