Ethereum: Understand Special Cases While Performing Bitcoin Script
When interacting with bitcoin networks, especially when implementing bitcoin scripts, it is essential to be aware of the “special cases” that are different from the usual procedure. These exceptions require a deeper understanding of both Bitcoin and Ethereum ecosystems and appropriate scripts.
1. P2SH (for payment purposes)
The p2sh
script type is used for payments, where the recipient’s address comes from ScriptPubkey instead of a hard code address. When the “P2SH” transaction is executed, the interpreter carries out extra checks to ensure that the sender receives sufficient funds in their wallets.
In order to understand this process, it is essential to understand how the Bitcoin Script does:
- The script is carried out by the node that controls its validity and integrity.
- It can be justified by the scripts with the entire script hash, including the “P2SH” instruction.
- ScriptPubkey is then subtracted from the resulting hash and used for payment.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address that comes from ScriptPubkey (0x ...
). During enforcement:
- The node justifies the validity of the bitcoin transaction, including the addressee’s address.
- Pull out the
p2sh
instruction and create a hash that contains the entire script (scriptsig +p2sh
).
3
2. P2WSH (assets payment)
The type of p2wsh
script is similar to ap2sh
, but with an additional complicated layer:
- The recipient’s assets come from their wallet balance instead of hard coding.
- When the “P2WSH” transaction is executed, the interpreter carries out extra checks to ensure that the sender receives enough funds in their wallets.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address from the wallet balance (0x ...
). During enforcement:
- The node justifies the validity of the bitcoin transaction, including the addressee’s address.
- Pull out the “P2WSH” instruction and create a hash that contains the entire script (scriptsig +
p2wsh
).
- This hash is then used to calculate Bob’s assets (
0x ...
).
3. P2CO (payment contract)
The type of p2co
script allows you to execute contracts at other nodes:
- The bytes of the contract will be withdrawn from the contract title.
- When the “P2CO” transaction is carried out, the interpreter shall carry out extra checks to ensure that the sender receives sufficient funds in their wallets.
Example:
Suppose you want to make a contract created by Alice Bob (0x ...
) at another node. During enforcement:
- The node justifies the validity of the bitcoin transaction.
- Pulls out the bytes of the contract from the title of the contract (
0x ...
).
3
4. P2PAY (payment address)
The type of p2pay
script allows you to pay a particular address:
- The sender’s address comes from the balance of the wallet.
- When the “P2Pay” transaction is executed, the interpreter shall carry out extra checks to ensure that the recipient has sufficient money in his wallet.
Example:
Suppose Alice wants to send 10 BTC to Bob’s address (0x ...
). During enforcement:
- The node justifies the validity of the bitcoin transaction.
- He pulls out Bob’s balance of wealth from his wallet.
- This balance is then used for the
p2pay
instruction.
5. P2WSHPAY (assets payment and payment address)
The type of p2wshpay
script combines both thep2wsh
and the p2pay
:
- The recipient’s assets come from their wallet balance.
- When the “P2WSHPAY” transaction is executed, the interpreter carries out extra checks to ensure that the sender receives enough funds in their wallets.