Bitcoin bases its logic of payment (locking) and spending (unlocking) funds on a scripting language
and a stack
. Each byte within raw sigScript has its own meaning. Bytes can be divided into two major types. Bytes that indicate which operation should be performed on the stack and bytes that indicate data. The first type represents opcodes. For example, the byte 0xae
has a special meaning and indicates the OP_CHECKMULTISIG opcode. You can find a list of all opcodes here.
Looking at the example you provided, the raw scriptSig looks like this (opcodes are in bold, the rest is data):
0047304402201c45383cc6e43202ed069e36184a97bf5dd489c6bea1372629540dea154c424902200a950b3557bba9ae9531237d46e6eb1afffd01eba989c3e53adaac443e5e2a2e01473044022032a681fb77589ce1a29a84494a6f9cb19630fcd65480ff646f30d8b826980390022006dc71baba1142abb275bbf3613b2a13b347bac4d09d41ccd9b69b02c270d8c2014c69522103745aaaf364030720b2d14de50a3310eef521c91e36353dca20813713535c005a2102db8911b3989b43c43d8dd6e50459bd85c38faf3b2862eb78ef297002775a10bd210351e3f71b7cf9a5f5f86c1908fee02ebf5a1ed77b6748f7486505d155833645f253ae
Therefore, the first byte (0x00
) represents one of the opcodes and indicates the operation OP_0
, i.e. that it is necessary to push an empty array onto the stack. The next byte (0x47
) also has a special meaning (opcode) which means that the next 71 bytes represent the data to be pushed onto the stack. After the data (the previous 71 bytes), the byte 0x47
(opcode) follows again, indicating the pushing of the next 71 bytes. This data is followed by the byte 0x4c
. The given byte indicates the opcode OP_PUSHDATA1
. According to that opcode, the next byte indicates the length of the data (in this case 0x69
; 105 decimal), followed by the data of the given length that should be pushed onto the stack.
Based on everything previously written, scriptSig in human readable form looks like this:
OP_0
OP_PUSHBYTES_71
304402201c45383cc6e43202ed069e36184a97bf5dd489c6bea1372629540dea154c424902200a950b3557bba9ae9531237d46e6eb1afffd01eba989c3e53adaac443e5e2a2e01
OP_PUSHBYTES_71
3044022032a681fb77589ce1a29a84494a6f9cb19630fcd65480ff646f30d8b826980390022006dc71baba1142abb275bbf3613b2a13b347bac4d09d41ccd9b69b02c270d8c201
OP_PUSHDATA1
69
522103745aaaf364030720b2d14de50a3310eef521c91e36353dca20813713535c005a2102db8911b3989b43c43d8dd6e50459bd85c38faf3b2862eb78ef297002775a10bd210351e3f71b7cf9a5f5f86c1908fee02ebf5a1ed77b6748f7486505d155833645f253ae
Finally, it should be noted that since the P2SH output is consumed, the last push in scriptSig represents the redeem script
. Therefore, the content of that last push (redeem script
) is not only treated as data pushed onto the stack, but the content is also treated as a script with its opcodes and data.
Precisely because of this, the following content (the last push in scriptSig - redeem script)
522103745aaaf364030720b2d14de50a3310eef521c91e36353dca20813713535c005a2102db8911b3989b43c43d8dd6e50459bd85c38faf3b2862eb78ef297002775a10bd210351e3f71b7cf9a5f5f86c1908fee02ebf5a1ed77b6748f7486505d155833645f253ae
does not only indicate data, but is itself a script with opcodes and data. The way this was decoded, that is, presented in human readable format is as follows (taken from the site mempool.space):
OP_PUSHNUM_2
OP_PUSHBYTES_33
03745aaaf364030720b2d14de50a3310eef521c91e36353dca20813713535c005a
OP_PUSHBYTES_33
02db8911b3989b43c43d8dd6e50459bd85c38faf3b2862eb78ef297002775a10bd
OP_PUSHBYTES_33
0351e3f71b7cf9a5f5f86c1908fee02ebf5a1ed77b6748f7486505d155833645f2
OP_PUSHNUM_3
OP_CHECKMULTISIG
Everything previously written represents the way in which the raw scriptSig is decoded into a human readable format, and the way in which bitcoin nodes know how to properly execute the script.