Bitcoin-Core

手動驗證 P2WSH

  • January 13, 2021

為了測試我對簽名和驗證過程的理解,我嘗試手動驗證一些隨機比特幣交易。可悲的是,我遇到了 P2WSH 交易,我選擇了以下帶有雜湊c53b99c9fdba60fd47c6026177d3f6e1ed6d3abde8f433364619aa7d437dad26的交易

使用原始交易:

010000000001012198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a70100000000ffffffff0220120a000000000017a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea110000000000220020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d0400473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101473044022047e4ad9788da6b764e723dd71d9fe07a217e48871129a672ef2788eb0d331a7a02206107b10c23e8720df9f1e5f609c471726066c5b72c56ee774615498f8fe62e8d016952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae00000000

我可以將其反序列化為:


TX版本號= 00000001

輸入計數= 01

從散列TX = a7c4fe84bd121e57630c067b455763747ee4fc09b9e220f4fca46008bce59821

TX外點指數= 00000001

輸入腳本=

序號= FFFFFFFF

輸出計數= 02

值(基體10)= 660000

輸出腳本= a91417b9a9afddaae527d25788bce2202563d4ab0d0587

值(基體10)= 1174148

輸出腳本= 0020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d

證人0 0 = 00

證人0 1 = 473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101

證人0 2 = 473044022047e4ad9788da6b764e723dd71d9fe07a217e48871129a672ef2788eb0d331a7a02206107b10c23e8720df9f1e5f609c471726066c5b72c56ee774615498f8fe62e8d01

證人0 3 = 6952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae

鎖定時間= 00000000


現在我嘗試計算得到簽名的 MessageHash:

用:

hashPrevouts =sha256²(2198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a701000000)

hashSequence =sha256²(FFFFFFFF)

hashOutputs =sha256²(20120a0000000000a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea1100000000000020701a8d401c84fb13e6baf169d59684e17abd9fa216c8cc5b9fc63d622ff8c58d)

版本:01000000

hashPrevouts:65aa319c96c046e8589c758adf7441d335682d3fc76df649180c4f94a1c4a731

hashSequence:3bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044

出點:2198e5bc0860a4fcf420e2b909fce47e746357457b060c63571e12bd84fec4a701000000

腳本程式碼:6952210375e00eb72e29da82b89367947f29ef34afb75e8654f6ea368e0acdfd92976b7c2103a1b26313f430c4b15bb1fdce663207659d8cac749a0e53d70eff01874496feff2103c96d495bfdd5ba4145e3e046fee45e84a8a48ad05bd8dbb395c011a32cf9f88053ae

值:345c1d0000000000

nSequence:FFFFFFFF

hashOutputs:58d6a86eb99a911735d2f262a9fc13fcf0f8422d75e25ba04db120f65cf573d6

nLocktime:00000000

sighash:01000000


這會給我 MessageHash = 8560e61d0167f784d0cdaf9d45ba0e1be752e94d30a34339d976b01e50f0e366

但如果我嘗試來驗證這個MessageHash與第一簽名(473044022014cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c02201c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b43101),其中有R = 14cd600863ad3c9f6802383fe814a693a77144117cf7694f63b558b8c02d801c和S = 1c3ad9901f659742668caf770f3d7f89a3633f9ccd2bfdd6a7c6f7529fe7b431反對任何證人0 3 3 PubKeys的,我總是得到的簽名是無效的。

有人能告訴我哪裡錯了嗎?

hashOutputs = sha256²(20120a0000000000a91417b9a9afddaae527d25788bce2202563d4ab0d058784ea1100000000000000000000020701a8d401c84fb13e6baf169d59682ff48e17abd96dfdb68c)

此值不正確。以下值是正確的。

HashOutputs =SHA256²(20120A00000000000017A91417B9A9AFDDAAE527D25788BCE2202563D4AB0D058784AE11002019384ABD9FB13CA8D401C84FB13E633D4ABD9FB13E6BAF169D59684E17ABD9FA216C8CC5B9FC63D622FF8C58D)

雜湊輸出:787ea14bb2276614a291caeadbadb8155b4491f454988aab8919ffbfd6fc83a5

結果,消息雜湊為:

989f5760931156cf50fba49c7d9e7b79e785cf340b9775d1a8931bc5e13197f7

引用自:https://bitcoin.stackexchange.com/questions/101414