1

What really is "Witness"? I saw this data in blockchain and can not identify what it really is.
Here is the dump of transaction for example.

TX hash = EDA80AD83A974ECE1A09E9252D33C7E3BC4CFEAB24C5BC3B395D3502374AAFB9  
Transaction version number = 00000002  
Witness activated >>  
Inputs count = 03  
TX from hash = 1BFDB87E8CBACFFDA389124870F0BC297786D505D4D52880FC714750B0E935CD  
N output = 0000003B  
Input script = 1600145F0027223B0D4CC9BB989C362925A2FC26A96E1A  
Sequence number = FDFFFFFF  
TX from hash = 61FE2A66C6DF705F509B56F6DC881BEB75D6B9C410EB95499554B017040774D8  
N output = 00000001  
Input script = 160014F3588696F6E42AC1C399D05807A612DE740F8377  
Sequence number = FDFFFFFF  
TX from hash = 22DEBD06DAEC109B2BFBFE14EAA5ADE515976FF0829E7690A780ADA241565411  
N output = 00000000  
Input script = 1600148E7DBA421FC81C5BFF2FF17AEF429C6175CF72EE  
Sequence number = FDFFFFFF  
Outputs count = 1  
Value = 0000000000180E1E  
Output script = 00149A72FC82F598FDE0960331476C3E437E924C2D96  
Witness 0 0 71 010F0EC3631C1100B7C9646F5537BFE4E71244298800B25BC7ED01C0CDF2B1C87B2002C1AF1677EA1F6375D85D865AF096D083E05F85F45148A3FE02F986E91B10EF0620024430  
Witness 0 1 33 A0AA4C55C7A3F7ABAB5C96F98906A3025BA57D3CFA7620CC2331B140FC75058D02  
Witness 1 0 71 01EB07758EA895C9268E841DAD2AAB51F3FCB8899915444512E9540B235F60580D2002FD0657F406E2D62F55BCC22B2CA68D5712F8B77BAD3B2E58D0E6BAFA6B057B0720024430  
Witness 1 1 33 0C1E14723ECCFE891EF132AAA06A0B729570D36D9DC3F6793768BF070BC5BBF503  
Witness 2 0 71 018293044A1493BEA7CA2E63DD9C782ABD978EB024E115F396210E030C247B920F2002323DB7E6952F6C4C32B95FFB20FBF4E980BBAF1D9B601F49E681AA4E96873F4E20024430  
Witness 2 1 33 E5D76A65261A1AAC4FD6B28E119C89A4F53049EC874B34B2D618049DCEF5713402  
Lock time = 000A2701  

So what is the "Witness" data in this transaction dump?

1 Answer 1

2

This is a transaction with three P2WPKH (native segwit v0 single-sig) inputs and a single P2WPKH output. For P2WPKH, the scriptPubKey (the locking script encoded in an output) contains a witness program that commits to the hash of a public key. The witness in the input therefore reveals the corresponding pre-image of the hash in the form of the public key (33 bytes) and provides the appropriate signature of 71 or 72 bytes. As each input must have a witness (if there is at least one segwit input), there are three witnesses with those two items each. For example the witness for the first input (labeled as position 0) is shown in the following two lines of your data:

Witness 0 0 71 010F0EC3631C1100B7C9646F5537BFE4E71244298800B25BC7ED01C0CDF2B1C87B2002C1AF1677EA1F6375D85D865AF096D083E05F85F45148A3FE02F986E91B10EF0620024430  
Witness 0 1 33 A0AA4C55C7A3F7ABAB5C96F98906A3025BA57D3CFA7620CC2331B140FC75058D02  

This reads as zeroth witness, zeroth witness item, 71-byte length, signature, zeroth witness, first item, 33-byte length, pubkey. The data dump is a bit weird here, in that the witness appears to be presented in little-endian and it enumerates the witness positions and witness item positions which does not appear in the raw transaction in that form.

Let's take a step back and approach from the raw transaction. (I've added '||' before the witness block, between the witnesses, and after the witness block. I've also marked the zeroth witness as bold).

02000000000103cd35e9b0504771fc8028d5d405d5867729bcf070481289a3fdcfba8c7eb8fd1b3b000000171600145f0027223b0d4cc9bb989c362925a2fc26a96e1afdffffffd874070417b054954995eb10c4b9d675eb1b88dcf6569b505f70dfc6662afe610100000017160014f3588696f6e42ac1c399d05807a612de740f8377fdffffff11545641a2ad80a790769e82f06f9715e5ada5ea14fefb2b9b10ecda06bdde2200000000171600148e7dba421fc81c5bff2ff17aef429c6175cf72eefdffffff011e0e1800000000001600149a72fc82f598fde0960331476c3e437e924c2d96||02473044022006ef101be986f902fea34851f4855fe083d096f05a865dd875631fea7716afc102207bc8b1f2cdc001edc75bb20088294412e7e4bf37556f64c9b700111c63c30e0f0121028d0575fc40b13123cc2076fa3c7da55b02a30689f9965cababf7a3c7554caaa0||024730440220077b056bfabae6d0582e3bad7bb7f812578da62c2bc2bc552fd6e206f45706fd02200d58605f230b54e9124544159989b8fcf351ab2aad1d848e26c995a88e7507eb012103f5bbc50b07bf683779f6c39d6dd37095720b6aa0aa32f11e89fecc3e72141e0c||0247304402204e3f87964eaa81e6491f609b1dafbb80e9f4fb20fb5fb9324c6c2f95e6b73d3202200f927b240c030e2196f315e124b08e97bd2a789cdd632ecaa7be93144a0493820121023471f5ce9d0418d6b2344b87ec4930f5a4899c118eb2d64fac1a1a26656ad7e5||01270a00

Picking the zeroth witness apart we have the following items:

02 ⇐ item count (0x02: witness has two items)
47 ⇐ length of first item  (0x47: signature is 71 bytes)
3044022006ef101be986f902fea34851f4855fe083d096f05a865dd875631fea7716afc102207bc8b1f2cdc001edc75bb20088294412e7e4bf37556f64c9b700111c63c30e0f01 ⇐ signature
21 ⇐ length of second item (0x21: pubkey is 33 bytes)
028d0575fc40b13123cc2076fa3c7da55b02a30689f9965cababf7a3c7554caaa0 ⇐ pubkey

When investigating transaction details, you may find it helpful to use the expanded view on a blockexplorer to help you identify where what part of the transaction starts.

screenshot of details of first transaction input labeling the various parts of the input data
via blockstream.info

You can find more details about P2WPKH inputs in What is the size and weight of a P2WPKH input?.

2
  • So in Pay to Witness Public Key Hash (P2WPKH), the witness items include a public-key, not a hash of a public key. What does the H (Hash) in the name refer to? Aug 18, 2021 at 14:59
  • 1
    It refers to the fact that that witness program (= the scriptPubKey for native segwit outputs, or the redeemscript for P2SH-embedded segwit outputs) contains a hash of the public key. Aug 18, 2021 at 15:44

Your Answer

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

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