Components of ScriptSig
Components of ScriptSig
A standard ScriptSig for a P2PKH (Pay-to-Public-Key-Hash) transaction contains two specific cryptographic items.
1. The Digital Signature
The largest component of ScriptSig is the Digital Signature.
-
Algorithm: Usually ECDSA (Elliptic Curve Digital Signature Algorithm).
-
Encoding: DER (Distinguished Encoding Rules).
-
Purpose: To prove that the person creating the transaction knows the private key associated with the coins.
-
SIGHASH Flag: The signature also includes a 1-byte suffix (usually
0x01for SIGHASH_ALL) which defines which parts of the transaction are protected by the signature.
2. The Public Key
The second component is the Public Key.
-
Format: Usually Compressed (33 bytes) or Uncompressed (65 bytes).
-
Purpose: The node needs the public key to verify the signature. It also hashes this public key to ensure it matches the address (Public Key Hash) specified in the lock.
3. Raw Data Structure
In the raw hex of a transaction, these components are prefixed by their length.
[Sig Length][Signature Bytes][Pubkey Length][Pubkey Bytes]
4. Multi-Sig ScriptSig
In more complex transactions, like Multi-Sig, the ScriptSig might contain:
-
An
OP_0(due to a legacy bug in the Bitcoin source code). -
Multiple signatures from different owners.
| Component | Standard Size | Purpose |
|---|---|---|
| Signature | ~71-73 Bytes | Proof of Intent/Authorization |
| Public Key | 33 Bytes | Proof of Identity |
| SIGHASH | 1 Byte | Defined signing scope |
The signature in ScriptSig is created by signing the entire transaction (excluding the ScriptSigs themselves), preventing anyone from changing the amounts or recipients after you sign.
In the next section, we will explore the Stack Execution Model in detail.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: