Script Challenges

Test your Bitcoin Script knowledge. Each challenge shows you a locking script — your job is to figure out the unlocking script that makes it pass.

0 / 17 solved

beginner

#1. The Number

beginner

The lock expects a specific number. Can you push the right one?

Locking Script
OP_5 OP_EQUAL

#2. Quick Math

beginner

Push two numbers that add up to 9.

Locking Script
OP_ADD OP_9 OP_EQUAL

#3. Double Up

beginner

Push one number. The lock duplicates it and adds both copies. Result must be 10.

Locking Script
OP_DUP OP_ADD OP_10 OP_EQUAL

intermediate

#4. Choose Wisely

intermediate

A nested IF/ELSE: two booleans select one of four outcomes (2, 3, 4, or 5). The lock checks for 4. Which two booleans open the path that pushes 4?

Locking Script
OP_IF OP_IF OP_2 OP_ELSE OP_3 OP_ENDIF OP_ELSE OP_IF OP_4 OP_ELSE OP_5 OP_ENDIF OP_ENDIF OP_4 OP_EQUAL

#5. Reverse Order

intermediate

Push two numbers A and B. The lock swaps them, subtracts (B − A), verifies the result is positive, then checks it equals 3.

Locking Script
OP_SWAP OP_SUB OP_DUP OP_0 OP_GREATERTHAN OP_VERIFY OP_3 OP_EQUAL

#6. Twin Values

intermediate

Push two identical numbers. The lock duplicates the top, copies the second (OP_OVER), verifies they match, then adds the two originals. Sum must be 8.

Locking Script
OP_DUP OP_OVER OP_EQUALVERIFY OP_ADD OP_8 OP_EQUAL

#7. Secret Word (HASH160)

intermediate

Find the preimage. The lock hashes your input with HASH160 (RIPEMD160(SHA256(x))) and checks the digest — the same hash used in Bitcoin addresses.

Locking Script
OP_HASH160 b6a9c8c230722b7c748331a8b450f05566dc7d0f OP_EQUAL

#11. Range Gate

intermediate

Push one number. The lock checks it is in the range [3, 10) (≥ 3 and < 10), then multiplies it by 2. The result must equal 10.

Locking Script
OP_DUP OP_3 OP_10 OP_WITHIN OP_VERIFY OP_2 OP_MUL OP_10 OP_EQUAL

#12. Two Paths

intermediate

The lock has two paths: IF checks SHA256(preimage), ELSE checks HASH160(preimage). We want the ELSE path. Push the preimage and the boolean that selects ELSE.

Locking Script
OP_IF OP_SHA256 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 OP_EQUAL OP_ELSE OP_HASH160 b6a9c8c230722b7c748331a8b450f05566dc7d0f OP_EQUAL OP_ENDIF

advanced

#8. String Builder

advanced

Push two byte strings that concatenate to "helloworld" (hex: 68656c6c6f776f726c64). OP_CAT is restored on BSV.

Locking Script
OP_CAT 68656c6c6f776f726c64 OP_EQUAL

#9. Alt Stack Trick

advanced

Push two numbers. One goes to the alt stack, the other is doubled, then the alt value is added. Result must be 11.

Locking Script
OP_TOALTSTACK OP_2 OP_MUL OP_FROMALTSTACK OP_ADD OP_11 OP_EQUAL

#10. Rabin Check

advanced

Verify a Rabin signature: the lock computes s² mod n and checks it equals 4. Public key n = 77 (0x4d). Find a valid signature s.

Locking Script
OP_DUP OP_MUL 4d OP_MOD OP_4 OP_EQUAL

#13. Dual Secret

advanced

The lock requires two different SHA256 preimages. The first (top of stack) must hash to one digest, the second to another. Push both in order.

Locking Script
OP_SHA256 2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90 OP_EQUALVERIFY OP_SHA256 81b637d8fcd2c6da6359e6963113a1170de795e4b725b84d1e0b4cfd9ec58ce9 OP_EQUAL

#14. Byte Split

advanced

Push one 10-byte value. The lock splits it at position 5 (OP_5 OP_SPLIT), then verifies the left half is "hello" and the right half is "world".

Locking Script
OP_5 OP_SPLIT 776f726c64 OP_EQUALVERIFY 68656c6c6f OP_EQUAL

#15. Stack Depth

advanced

Push exactly three numbers. The lock verifies stack depth is 3 (OP_DEPTH), then adds all three. The sum must equal 12.

Locking Script
OP_DEPTH OP_3 OP_EQUALVERIFY OP_ADD OP_ADD OP_12 OP_EQUAL

#16. Message Auth

advanced

The lock concatenates two fields (sender and message) with OP_CAT, hashes with SHA256, and checks the digest. Find a valid [sender, message] pair that matches the locked hash.

Locking Script
OP_CAT OP_SHA256 b5f2cf84fd46833a53045e8952af76ec501feb9254ab4fa0a000126a424bac6b OP_EQUAL

#17. Conditional Dual Hash

advanced

Same lock as Two Paths: IF = SHA256(preimage), ELSE = HASH160(preimage). This time we want the IF path. Push the preimage and the boolean that selects IF.

Locking Script
OP_IF OP_SHA256 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 OP_EQUAL OP_ELSE OP_HASH160 b6a9c8c230722b7c748331a8b450f05566dc7d0f OP_EQUAL OP_ENDIF

Want to experiment with custom scripts?

Open Script Lab