Ethereum: What are the scriptPubKey, scriptSig, redeem script and witness for the various output types?

Understanding Ethereum Script Output: A Guide to ScriptPubKey, ScriptSig, RedeemScript, and Witness Scripts

The Ethereum script system is a powerful tool that allows developers to create custom transactions and contracts. The heart of this system is the different script outputs used in those transactions. In this article, we’ll dive into the different types of script outputs and their corresponding scripts.

ScriptPubKey: A Universal Address Format

The ScriptPubKey (SPK) is a unique address format used to identify Ethereum addresses. It’s a combination of a private key, a public key, and a version number. Here’s how it works:

  • Public Key: The first two bytes of the SPK represent the public key.
  • Version Number: The next byte specifies the version of the Ethereum standard (currently 1).
  • Private Key: The last 4 bytes are the private key.

ScriptSig: Signatures and verification

A ScriptSig is a signature that verifies the authenticity of a transaction. It is defined by the following parameters:

  • Public key: The public key used to sign the transaction.
  • SigHash: A hash of the transaction data, encrypted with the private key.

The ScriptSig format looks like this:

0x00000f3d... (Signature)

RedeemScript: Payment verification

A RedeemScript is a script that verifies the validity of a payment. It is used to check whether the transaction was successfully processed and paid correctly. The RedeemScript format looks like this:

0x00000f3d... (Signature)

1x... (Transaction data digest)

2x... (Sender's public key)

3x... (Sender's private key)

4x... (Block number and timestamp)

5x... (Difficulty level)

6x... (Amount paid)

7x... (Sender's address)

8x... (Recipient's address)

9x... (Gas limit)

10x... (Gas price)

Witness script: signing transactions

A witness script is a type of script that signs transactions on behalf of the sender. It is used to verify the authenticity and integrity of a transaction, even after it has been mined. The Witness script format looks like this:

0x00000f3d... (Signature)

1x... (Transaction data digest)

2x... (Sender's public key)

3x... (Sender's private key)

4x... (Block number and timestamp)

5x... (Difficulty level)

6x... (Amount paid)

7x... (Sender's address)

8x... (Recipient's address)

9x... (Gas limit)

10x... (Gas price)

Witness Program: Signatures and verification

A Witness program is a type of script that signs transactions on behalf of the sender. It is used to verify the authenticity and integrity of a transaction, even after it has been mined. The Witness program format looks like this:

0x00000f3d... (Signature)

1x... (Transaction data digest)

2x... (Sender's public key)

3x... (Sender's private key)

4x... (Block number and timestamp)

5x... (Difficulty level)

6x... (Amount paid)

7x... (Sender's address)

8x... (Recipient's address)

9x... (Gas limit)

10x... (Gas price)

To sum up, ScriptPubKey is used to identify Ethereum addresses, while ScriptSig verifies the authenticity of transactions. RedeemScript is used to verify the integrity of payments, and Witness scripts sign transactions on behalf of senders.

Output Types

Ethereum supports several output types, including:

  • P2PKH: A private key-based address format.
  • P2SH: A script hash-based address format (used in SegWit).
  • BIP39: A base58 checker (used to output seeds).
  • BIP44:

    Ethereum: What are the scriptPubKey, scriptSig, redeem script and witness for the various output types?

    A 32-byte seed output format (used to store private keys).

Each output type has its own set of scripts, including ScriptPubKey, ScriptSig, RedeemScript, and Witness. Understanding these different script outputs is essential to building secure and efficient Ethereum-based applications.