Using your favorite programming language solves the following
Goal: Understand basic Bitcoin Script by constructing and validating a Pay-to-Public-Key-Hash (P2PKH) transaction output.
Steps:
-
Generate a private key and derive its public key and hash:
- Generate a private key.
- Derive the public key from the private key.
- Compute the public key hash (e.g., RIPEMD-160(SHA-256(pubkey))).
-
Construct a P2PKH locking script:
OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
-
Simulate an unlocking script with a dummy signature and public key.
-
Write a function to “execute” the script:
- Push unlocking script items onto a stack.
- Apply locking script opcodes (duplicate, hash, compare, check signature).
- Return
True
if valid,False
otherwise.
Goal: Explore multi-signature setups by creating and spending a multisig output.
Steps:
-
Generate 3 keypairs (private/public keys).
-
Build a 2-of-3 multisig locking script:
OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3 OP_CHECKMULTISIG
-
Simulate spending with 2 signatures from any 2 keys.
-
Write a function to validate the multisig script execution.