Ethereum: Understanding Special Cases During Bitcoin Script Execution
When interacting with Bitcoin networks, particularly during the execution of Bitcoin Scripts, it’s essential to be aware of several “special cases” that deviate from the standard procedure. These exceptions require a deeper understanding of both Bitcoin and Ethereum ecosystems, as well as their respective scripts.
۱. p2sh (Pay-to-ScriptHash)
The p2sh
script type is used for payments, where the recipient’s address is derived from the scriptPubKey instead of a hardcoded address. When executing a p2sh
transaction, the interpreter performs extra verification to ensure that the sender has sufficient funds in their wallet.
To understand this process, it’s crucial to grasp how Bitcoin Script executes:
- The script is executed by the node, which verifies its validity and integrity.
- The scriptSig is verified using a hash of the entire script, including the
p2sh
instruction.
- The scriptPubKey is then extracted from the resulting hash and used for payment.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address derived from his scriptPubKey (0x...
). During execution:
- The node verifies the validity of the Bitcoin transaction, including the recipient address.
- It extracts the
p2sh
instruction and creates a hash that includes the entire script (scriptSig +p2sh
).
- This resulting hash is then used to derive Bob’s payment address (
0x...
).
۲. p2wsh (Pay-to-Wealth)
The p2wsh
script type is similar to p2sh
, but with an additional layer of complexity:
- The recipient’s wealth is derived from their wallet balance instead of a hardcoded address.
- When executing a
p2wsh
transaction, the interpreter performs extra verification to ensure that the sender has sufficient funds in their wallet.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address derived from his wallet balance (0x...
). During execution:
- The node verifies the validity of the Bitcoin transaction, including the recipient address.
- It extracts the
p2wsh
instruction and creates a hash that includes the entire script (scriptSig +p2wsh
).
- This resulting hash is then used to derive Bob’s wealth (
0x...
).
۳. p2co (Pay-to-Contract)
The p2co
script type allows for the execution of contracts on other nodes:
- The contract’s bytecode is extracted from a contract address.
- When executing a
p2co
transaction, the interpreter performs extra verification to ensure that the sender has sufficient funds in their wallet.
Example:
Suppose Alice wants to execute a contract created by Bob (0x...
) on another node. During execution:
- The node verifies the validity of the Bitcoin transaction.
- It extracts the contract bytecode from the contract address (
0x...
).
- This resulting bytecode is then used for the
p2co
instruction.
۴. p2pay (Pay-to-Address)
The p2pay
script type allows for the payment of a specific address:
- The sender’s address is derived from their wallet balance.
- When executing a
p2pay
transaction, the interpreter performs extra verification to ensure that the recipient has sufficient funds in their wallet.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address (0x...
). During execution:
- The node verifies the validity of the Bitcoin transaction.
- It extracts Bob’s wealth balance from his wallet.
- This resulting balance is then used for the
p2pay
instruction.
۵. p2wshPay (Pay-to-Wealth and Pay-to-Address)
The p2wshPay
script type combines both p2wsh
and p2pay
:
- The recipient’s wealth is derived from their wallet balance.
- When executing a
p2wshPay
transaction, the interpreter performs extra verification to ensure that the sender has sufficient funds in their wallet.